# dami904/bursar architecture

> Architecture diagram of the GitHub repository dami904/bursar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dami904/bursar
- Repository: https://github.com/dami904/bursar

## Overview

Bursar gives AI agents scoped keys to spend from a shared, job-level USDC budget. Owners configure jobs and review approvals in the web console; agents initiate purchases through MCP or HTTP. The API checks policy and reserves funds, while the worker executes and reconciles payments, and JobVault on Arc enforces release limits. The README establishes this separation; several subsystem implementations are unsampled, so their internal links are shown only where documented or visible in the source index.

Main entry points: [`apps/api/src/app.ts`](https://github.com/dami904/bursar/blob/main/apps/api/src/app.ts) (HTTP API), [`apps/worker/src/executor.ts`](https://github.com/dami904/bursar/blob/main/apps/worker/src/executor.ts) (Payment executor), [`apps/worker/src/worker.ts`](https://github.com/dami904/bursar/blob/main/apps/worker/src/worker.ts) (Worker scheduler), [`apps/api/src/services/spend.ts`](https://github.com/dami904/bursar/blob/main/apps/api/src/services/spend.ts) (Spend and reservation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["User surfaces"]
  node_web["Web console<br/>[main.tsx]"]
  node_mcp["MCP tools<br/>[server.ts]"]
  node_mcpclient["Agent API client<br/>[client.ts]"]
  node_operator["AI operator<br/>[operator.ts]"]
  node_model["Model providers<br/>[model.ts]"]
end

subgraph group_control["API and controls"]
  node_api["HTTP API<br/>[app.ts]"]
  node_auth["Key and sign-in auth<br/>[auth.ts]"]
  node_console["Owner console services<br/>[console.ts]"]
  node_spend["Spend and reservation<br/>[spend.ts]"]
  node_approvals["Payment approvals<br/>[approvals.ts]"]
  node_policy["Spend policy<br/>[policy.ts]"]
end

subgraph group_execution["Payment execution"]
  node_payments["Payment integrations<br/>[x402.ts]"]
  node_gateway["Gateway payments<br/>[gateway.ts]"]
  node_sellerapp["Seller storefront<br/>[app.ts]"]
end

subgraph group_operations["Worker operations"]
  node_worker["Worker scheduler<br/>[worker.ts]"]
  node_executor["Payment executor<br/>[executor.ts]"]
  node_reconciler["Payment reconciliation<br/>[reconciler.ts]"]
  node_audit["Audit anchoring<br/>[anchor.ts]"]
end

subgraph group_state["Persistence and chain"]
  node_db[("Postgres state<br/>[schema.ts]")]
  node_vault{{"JobVault on Arc"}}
end

node_owner(("Job owner"))
node_agent(("AI agent"))
node_seller(("x402 seller"))
node_circle["Circle wallets"]

node_owner -->|"configures jobs"| node_web
node_agent -->|"uses tools"| node_mcp
node_mcp -->|"calls"| node_mcpclient
node_mcpclient -->|"requests spend"| node_api
node_web -->|"manages jobs"| node_api
node_owner -->|"signs approvals"| node_api
node_api -->|"authenticates"| node_auth
node_api -->|"serves console"| node_console
node_api -->|"requests spend"| node_spend
node_api -->|"routes decisions"| node_approvals
node_spend -->|"checks rules"| node_policy
node_spend -->|"reserves funds"| node_db
node_spend -->|"requests payment"| node_payments
node_agent -->|"provides job brief"| node_operator
node_operator -->|"queries model"| node_model
node_operator -->|"uses Bursar API"| node_mcpclient
node_payments -.->|"requests paid resource"| node_sellerapp
node_sellerapp -->|"serves products"| node_seller
node_worker -->|"runs execution"| node_executor
node_executor -->|"uses integrations"| node_payments
node_executor -->|"checks rules"| node_policy
node_executor -->|"reads and writes"| node_db
node_worker -->|"runs reconciliation"| node_reconciler
node_reconciler -.->|"checks chain outcome"| node_vault
node_worker -.->|"anchors evidence"| node_audit
node_audit -->|"anchors on Arc"| node_vault
node_executor -.->|"funds payments"| node_circle
node_vault -.->|"releases payment"| node_seller
node_approvals -.->|"verifies signature"| node_vault
node_worker -->|"runs autopilot"| node_operator

click node_web "https://github.com/dami904/bursar/blob/main/apps/web/src/main.tsx"
click node_mcp "https://github.com/dami904/bursar/blob/main/apps/mcp/src/server.ts"
click node_mcpclient "https://github.com/dami904/bursar/blob/main/apps/mcp/src/client.ts"
click node_operator "https://github.com/dami904/bursar/blob/main/apps/operator/src/operator.ts"
click node_model "https://github.com/dami904/bursar/blob/main/apps/operator/src/model.ts"
click node_api "https://github.com/dami904/bursar/blob/main/apps/api/src/app.ts"
click node_auth "https://github.com/dami904/bursar/blob/main/apps/api/src/services/auth.ts"
click node_console "https://github.com/dami904/bursar/blob/main/apps/api/src/services/console.ts"
click node_spend "https://github.com/dami904/bursar/blob/main/apps/api/src/services/spend.ts"
click node_approvals "https://github.com/dami904/bursar/blob/main/apps/api/src/services/approvals.ts"
click node_policy "https://github.com/dami904/bursar/blob/main/packages/policy/src/policy.ts"
click node_payments "https://github.com/dami904/bursar/blob/main/packages/payments/src/x402.ts"
click node_gateway "https://github.com/dami904/bursar/blob/main/packages/payments/src/gateway.ts"
click node_sellerapp "https://github.com/dami904/bursar/blob/main/apps/seller/src/app.ts"
click node_worker "https://github.com/dami904/bursar/blob/main/apps/worker/src/worker.ts"
click node_executor "https://github.com/dami904/bursar/blob/main/apps/worker/src/executor.ts"
click node_reconciler "https://github.com/dami904/bursar/blob/main/apps/worker/src/reconciler.ts"
click node_audit "https://github.com/dami904/bursar/blob/main/apps/worker/src/anchor.ts"
click node_db "https://github.com/dami904/bursar/blob/main/packages/db/src/schema.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_mcp,node_mcpclient,node_operator,node_model toneBlue
class node_api,node_auth,node_console,node_spend,node_approvals,node_policy toneAmber
class node_payments,node_gateway,node_sellerapp toneMint
class node_worker,node_executor,node_reconciler,node_audit toneRose
class node_db,node_vault,node_owner,node_agent,node_seller,node_circle toneIndigo
```

## Components

### User surfaces

- [Web console](https://github.com/dami904/bursar/blob/main/apps/web/src/main.tsx): `apps/web/src/main.tsx`
- [MCP tools](https://github.com/dami904/bursar/blob/main/apps/mcp/src/server.ts): `apps/mcp/src/server.ts`
- [Agent API client](https://github.com/dami904/bursar/blob/main/apps/mcp/src/client.ts): `apps/mcp/src/client.ts`
- [AI operator](https://github.com/dami904/bursar/blob/main/apps/operator/src/operator.ts): `apps/operator/src/operator.ts`
- [Model providers](https://github.com/dami904/bursar/blob/main/apps/operator/src/model.ts): `apps/operator/src/model.ts`

### API and controls

- [HTTP API](https://github.com/dami904/bursar/blob/main/apps/api/src/app.ts): `apps/api/src/app.ts`
- [Key and sign-in auth](https://github.com/dami904/bursar/blob/main/apps/api/src/services/auth.ts): `apps/api/src/services/auth.ts`
- [Owner console services](https://github.com/dami904/bursar/blob/main/apps/api/src/services/console.ts): `apps/api/src/services/console.ts`
- [Spend and reservation](https://github.com/dami904/bursar/blob/main/apps/api/src/services/spend.ts): `apps/api/src/services/spend.ts`
- [Payment approvals](https://github.com/dami904/bursar/blob/main/apps/api/src/services/approvals.ts): `apps/api/src/services/approvals.ts`
- [Spend policy](https://github.com/dami904/bursar/blob/main/packages/policy/src/policy.ts): `packages/policy/src/policy.ts`

### Payment execution

- [Payment integrations](https://github.com/dami904/bursar/blob/main/packages/payments/src/x402.ts): `packages/payments/src/x402.ts`
- [Gateway payments](https://github.com/dami904/bursar/blob/main/packages/payments/src/gateway.ts): `packages/payments/src/gateway.ts`
- [Seller storefront](https://github.com/dami904/bursar/blob/main/apps/seller/src/app.ts): `apps/seller/src/app.ts`

### Worker operations

- [Worker scheduler](https://github.com/dami904/bursar/blob/main/apps/worker/src/worker.ts): `apps/worker/src/worker.ts`
- [Payment executor](https://github.com/dami904/bursar/blob/main/apps/worker/src/executor.ts): `apps/worker/src/executor.ts`
- [Payment reconciliation](https://github.com/dami904/bursar/blob/main/apps/worker/src/reconciler.ts): `apps/worker/src/reconciler.ts`
- [Audit anchoring](https://github.com/dami904/bursar/blob/main/apps/worker/src/anchor.ts): `apps/worker/src/anchor.ts`

### Persistence and chain

- [Postgres state](https://github.com/dami904/bursar/blob/main/packages/db/src/schema.ts): `packages/db/src/schema.ts`
- **JobVault on Arc**

### Other components

- **Job owner**
- **AI agent**
- **x402 seller**
- **Circle wallets**

## Connections

- Job owner → Web console: configures jobs (evidence: `README.md`)
- AI agent → MCP tools: uses tools (evidence: `README.md`)
- MCP tools → Agent API client: calls (evidence: `apps/mcp/src/server.ts`)
- Agent API client → HTTP API: requests spend (evidence: `apps/mcp/src/client.ts`)
- Web console → HTTP API: manages jobs
- Job owner → HTTP API: signs approvals (evidence: `README.md`)
- HTTP API → Key and sign-in auth: authenticates (evidence: `apps/api/src/services/auth.ts`)
- HTTP API → Owner console services: serves console (evidence: `apps/api/src/app.ts`)
- HTTP API → Spend and reservation: requests spend (evidence: `apps/api/src/app.ts`)
- HTTP API → Payment approvals: routes decisions (evidence: `apps/api/src/app.ts`)
- Spend and reservation → Spend policy: checks rules (evidence: `README.md`)
- Spend and reservation → Postgres state: reserves funds (evidence: `README.md`)
- Spend and reservation → Payment integrations: requests payment (evidence: `README.md`)
- AI agent → AI operator: provides job brief
- AI operator → Model providers: queries model (evidence: `apps/operator/src/operator.ts`)
- AI operator → Agent API client: uses Bursar API
- Payment integrations → Seller storefront: requests paid resource (evidence: `README.md`)
- Seller storefront → x402 seller: serves products (evidence: `apps/seller/src/app.ts`)
- Worker scheduler → Payment executor: runs execution (evidence: `apps/worker/src/worker.ts`)
- Payment executor → Payment integrations: uses integrations (evidence: `apps/worker/src/executor.ts`)
- Payment executor → Spend policy: checks rules (evidence: `apps/worker/src/executor.ts`)
- Payment executor → Postgres state: reads and writes (evidence: `apps/worker/src/executor.ts`)
- Worker scheduler → Payment reconciliation: runs reconciliation (evidence: `apps/worker/src/worker.ts`)
- Payment reconciliation → JobVault on Arc: checks chain outcome (evidence: `README.md`)
- Worker scheduler → Audit anchoring: anchors evidence (evidence: `README.md`)
- Audit anchoring → JobVault on Arc: anchors on Arc (evidence: `README.md`)
- Payment executor → Circle wallets: funds payments (evidence: `README.md`)
- JobVault on Arc → x402 seller: releases payment (evidence: `README.md`)
- Payment approvals → JobVault on Arc: verifies signature (evidence: `README.md`)
- Worker scheduler → AI operator: runs autopilot (evidence: `apps/worker/src/worker.ts`)
