# mhiah/bursar- architecture

> Architecture diagram of the GitHub repository mhiah/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/mhiah/bursar-
- Repository: https://github.com/mhiah/bursar-

## Overview

Bursar combines a small-business finance dashboard with an autonomous USDC agent whose onchain vault limits what it can execute. Owners create a business and vault, manage customers, invoices, suppliers and bills, then the agent periodically reviews balances and books, handles collections and payment decisions, requests owner approval when needed, and records decisions. Customers pay invoices directly into vaults; reserve and savings are separate money-management capabilities. The README documents the main capabilities and external integrations; unsampled modules are represented at exact enclosing paths, and edges are limited to documented or excerpted relationships.

Main entry points: [`app/src/agent/run.ts`](https://github.com/mhiah/bursar-/blob/main/app/src/agent/run.ts) (Agent run coordinator), [`app/src/lib/db.ts`](https://github.com/mhiah/bursar-/blob/main/app/src/lib/db.ts) (Business database), [`app/src/agent/tools.ts`](https://github.com/mhiah/bursar-/blob/main/app/src/agent/tools.ts) (Agent action tools), [`app/src/lib/abi/BursarVault.ts`](https://github.com/mhiah/bursar-/blob/main/app/src/lib/abi/BursarVault.ts) (Bursar vault)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_business["Business workspace"]
  node_workspace["Business dashboard<br/>[page.tsx]"]
  node_business_setup["Business setup<br/>[route.ts]"]
  node_customer_records["Customer records<br/>[route.ts]"]
  node_invoice_requests["Invoices and pay links<br/>[route.ts]"]
  node_payment_page["Customer payment<br/>[page.tsx]"]
  node_supplier_records["Supplier records<br/>[route.ts]"]
  node_bill_records["Bill management<br/>[route.ts]"]
  node_approvals["Owner approvals<br/>[page.tsx]"]
  node_savings_ui["Savings pots<br/>[page.tsx]"]
  node_decision_log["Decision history<br/>[route.ts]"]
end

subgraph group_agent["Autonomous agent"]
  node_agent_runner["Agent run coordinator<br/>[run.ts]"]
  node_agent_tools["Agent action tools<br/>[tools.ts]"]
  node_agent_reasoning["AI decision making<br/>[ai.ts]"]
  node_payment_matching["Payment matching<br/>[incoming.ts]"]
  node_collections["Customer collections<br/>[recheck.ts]"]
  node_reserve_savings["Reserve and savings logic<br/>[savings.ts]"]
end

subgraph group_chain["Onchain money controls"]
  node_vault[("Bursar vault<br/>[BursarVault.ts]")]
  node_savings_contract[("Savings contract<br/>[BursarSavings.ts]")]
end

subgraph group_platform["Platform services"]
  node_wallet_checks["Wallet screening<br/>[screening.ts]"]
  node_database[("Business database<br/>[db.ts]")]
  node_chain_access["Arc chain access<br/>[chain.ts]"]
  node_rpc_proxy["RPC relay<br/>[route.ts]"]
  node_agent_wallet["Circle agent wallet<br/>[wallet.ts]"]
end

node_owner(("Business owner"))
node_customer(("Customer"))
node_timer["Agent timer<br/>[agent-timer.ts]"]
node_email["Customer email"]
node_marketplace["Circle Agent Marketplace"]

node_owner -->|"creates business"| node_business_setup
node_owner -->|"creates and configures"| node_vault
node_business_setup -->|"stores business"| node_database
node_owner -->|"adds customers"| node_customer_records
node_customer_records -->|"screens wallet"| node_wallet_checks
node_customer_records -->|"stores records"| node_database
node_owner -->|"creates invoices"| node_invoice_requests
node_invoice_requests -->|"stores requests"| node_database
node_customer -->|"opens pay link"| node_payment_page
node_payment_page -->|"pays into"| node_vault
node_owner -->|"adds suppliers"| node_supplier_records
node_supplier_records -->|"screens wallet"| node_wallet_checks
node_supplier_records -->|"stores suppliers"| node_database
node_owner -->|"records bills"| node_bill_records
node_bill_records -->|"stores and flags"| node_database
node_owner -->|"reviews requests"| node_approvals
node_owner -->|"manages savings"| node_savings_ui
node_savings_ui -->|"reads savings pots"| node_savings_contract
node_owner -->|"views overview"| node_workspace
node_workspace -->|"reports activity"| node_database
node_timer -->|"starts runs"| node_agent_runner
node_agent_runner -.->|"requests decisions"| node_agent_reasoning
node_agent_runner -.->|"dispatches actions"| node_agent_tools
node_agent_runner -.->|"reviews incoming payments"| node_payment_matching
node_agent_runner -.->|"reviews invoices"| node_collections
node_agent_runner -.->|"manages spare cash"| node_reserve_savings
node_agent_runner -.->|"reads business books"| node_database
node_agent_runner -->|"reads vault state"| node_vault
node_agent_runner -->|"signs actions"| node_agent_wallet
node_agent_runner -->|"pays AI calls"| node_marketplace
node_agent_tools -->|"submits guarded payments"| node_vault
node_vault -->|"rejects rule violations"| node_agent_wallet
node_agent_tools -->|"checks wallets"| node_wallet_checks
node_agent_tools -->|"sends reminders and receipts"| node_email
node_agent_tools -->|"requests owner review"| node_approvals
node_agent_tools -->|"records decisions"| node_decision_log
node_decision_log -->|"reads decision history"| node_database
node_agent_runner -->|"deposits savings"| node_savings_contract
node_workspace -->|"relays signed chain calls"| node_rpc_proxy
node_rpc_proxy -->|"forwards RPC"| node_chain_access
node_chain_access -->|"reads vault"| node_vault

click node_timer "https://github.com/mhiah/bursar-/blob/main/app/src/agent-timer.ts"
click node_workspace "https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/dashboard/page.tsx"
click node_business_setup "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/business/route.ts"
click node_customer_records "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/customers/route.ts"
click node_invoice_requests "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/requests/route.ts"
click node_payment_page "https://github.com/mhiah/bursar-/blob/main/app/src/app/pay/%5Bid%5D/page.tsx"
click node_supplier_records "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/suppliers/route.ts"
click node_bill_records "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/bills/route.ts"
click node_approvals "https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/approvals/page.tsx"
click node_savings_ui "https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/savings/page.tsx"
click node_decision_log "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/decisions/route.ts"
click node_agent_runner "https://github.com/mhiah/bursar-/blob/main/app/src/agent/run.ts"
click node_agent_tools "https://github.com/mhiah/bursar-/blob/main/app/src/agent/tools.ts"
click node_agent_reasoning "https://github.com/mhiah/bursar-/blob/main/app/src/agent/ai.ts"
click node_payment_matching "https://github.com/mhiah/bursar-/blob/main/app/src/agent/incoming.ts"
click node_collections "https://github.com/mhiah/bursar-/blob/main/app/src/agent/recheck.ts"
click node_reserve_savings "https://github.com/mhiah/bursar-/blob/main/app/src/agent/savings.ts"
click node_wallet_checks "https://github.com/mhiah/bursar-/blob/main/app/src/lib/screening.ts"
click node_database "https://github.com/mhiah/bursar-/blob/main/app/src/lib/db.ts"
click node_chain_access "https://github.com/mhiah/bursar-/blob/main/app/src/lib/chain.ts"
click node_rpc_proxy "https://github.com/mhiah/bursar-/blob/main/app/src/app/api/rpc/route.ts"
click node_vault "https://github.com/mhiah/bursar-/blob/main/app/src/lib/abi/BursarVault.ts"
click node_savings_contract "https://github.com/mhiah/bursar-/blob/main/app/src/lib/abi/BursarSavings.ts"
click node_agent_wallet "https://github.com/mhiah/bursar-/blob/main/app/src/agent/wallet.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_workspace,node_business_setup,node_customer_records,node_invoice_requests,node_payment_page,node_supplier_records,node_bill_records,node_approvals,node_savings_ui,node_decision_log toneBlue
class node_agent_runner,node_agent_tools,node_agent_reasoning,node_payment_matching,node_collections,node_reserve_savings toneAmber
class node_vault,node_savings_contract toneMint
class node_wallet_checks,node_database,node_chain_access,node_rpc_proxy,node_agent_wallet toneRose
class node_owner,node_customer,node_email,node_marketplace toneIndigo
class node_timer toneTeal
```

## Components

### Business workspace

- [Business dashboard](https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/dashboard/page.tsx): `app/src/app/(app)/dashboard/page.tsx`
- [Business setup](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/business/route.ts): `app/src/app/api/business/route.ts`
- [Customer records](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/customers/route.ts): `app/src/app/api/customers/route.ts`
- [Invoices and pay links](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/requests/route.ts): `app/src/app/api/requests/route.ts`
- [Customer payment](https://github.com/mhiah/bursar-/blob/main/app/src/app/pay/%5Bid%5D/page.tsx): `app/src/app/pay/[id]/page.tsx`
- [Supplier records](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/suppliers/route.ts): `app/src/app/api/suppliers/route.ts`
- [Bill management](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/bills/route.ts): `app/src/app/api/bills/route.ts`
- [Owner approvals](https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/approvals/page.tsx): `app/src/app/(app)/approvals/page.tsx`
- [Savings pots](https://github.com/mhiah/bursar-/blob/main/app/src/app/(app)/savings/page.tsx): `app/src/app/(app)/savings/page.tsx`
- [Decision history](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/decisions/route.ts): `app/src/app/api/decisions/route.ts`

### Autonomous agent

- [Agent run coordinator](https://github.com/mhiah/bursar-/blob/main/app/src/agent/run.ts): `app/src/agent/run.ts`
- [Agent action tools](https://github.com/mhiah/bursar-/blob/main/app/src/agent/tools.ts): `app/src/agent/tools.ts`
- [AI decision making](https://github.com/mhiah/bursar-/blob/main/app/src/agent/ai.ts): `app/src/agent/ai.ts`
- [Payment matching](https://github.com/mhiah/bursar-/blob/main/app/src/agent/incoming.ts): `app/src/agent/incoming.ts`
- [Customer collections](https://github.com/mhiah/bursar-/blob/main/app/src/agent/recheck.ts): `app/src/agent/recheck.ts`
- [Reserve and savings logic](https://github.com/mhiah/bursar-/blob/main/app/src/agent/savings.ts): `app/src/agent/savings.ts`

### Onchain money controls

- [Bursar vault](https://github.com/mhiah/bursar-/blob/main/app/src/lib/abi/BursarVault.ts): `app/src/lib/abi/BursarVault.ts`
- [Savings contract](https://github.com/mhiah/bursar-/blob/main/app/src/lib/abi/BursarSavings.ts): `app/src/lib/abi/BursarSavings.ts`

### Platform services

- [Wallet screening](https://github.com/mhiah/bursar-/blob/main/app/src/lib/screening.ts): `app/src/lib/screening.ts`
- [Business database](https://github.com/mhiah/bursar-/blob/main/app/src/lib/db.ts): `app/src/lib/db.ts`
- [Arc chain access](https://github.com/mhiah/bursar-/blob/main/app/src/lib/chain.ts): `app/src/lib/chain.ts`
- [RPC relay](https://github.com/mhiah/bursar-/blob/main/app/src/app/api/rpc/route.ts): `app/src/app/api/rpc/route.ts`
- [Circle agent wallet](https://github.com/mhiah/bursar-/blob/main/app/src/agent/wallet.ts): `app/src/agent/wallet.ts`

### Other components

- **Business owner**
- **Customer**
- [Agent timer](https://github.com/mhiah/bursar-/blob/main/app/src/agent-timer.ts): `app/src/agent-timer.ts`
- **Customer email**
- **Circle Agent Marketplace**

## Connections

- Business owner → Business setup: creates business (evidence: `app/src/app/api/business/route.ts`)
- Business owner → Bursar vault: creates and configures
- Business setup → Business database: stores business (evidence: `app/src/app/api/business/route.ts`)
- Business owner → Customer records: adds customers
- Customer records → Wallet screening: screens wallet (evidence: `app/src/app/api/customers/route.ts`)
- Customer records → Business database: stores records (evidence: `app/src/app/api/customers/route.ts`)
- Business owner → Invoices and pay links: creates invoices
- Invoices and pay links → Business database: stores requests (evidence: `app/src/app/api/requests/route.ts`)
- Customer → Customer payment: opens pay link
- Customer payment → Bursar vault: pays into
- Business owner → Supplier records: adds suppliers
- Supplier records → Wallet screening: screens wallet (evidence: `app/src/app/api/suppliers/route.ts`)
- Supplier records → Business database: stores suppliers (evidence: `app/src/app/api/suppliers/route.ts`)
- Business owner → Bill management: records bills
- Bill management → Business database: stores and flags (evidence: `app/src/app/api/bills/route.ts`)
- Business owner → Owner approvals: reviews requests
- Business owner → Savings pots: manages savings
- Savings pots → Savings contract: reads savings pots
- Business owner → Business dashboard: views overview
- Business dashboard → Business database: reports activity
- Agent timer → Agent run coordinator: starts runs
- Agent run coordinator → AI decision making: requests decisions
- Agent run coordinator → Agent action tools: dispatches actions
- Agent run coordinator → Payment matching: reviews incoming payments
- Agent run coordinator → Customer collections: reviews invoices
- Agent run coordinator → Reserve and savings logic: manages spare cash
- Agent run coordinator → Business database: reads business books
- Agent run coordinator → Bursar vault: reads vault state
- Agent run coordinator → Circle agent wallet: signs actions
- Agent run coordinator → Circle Agent Marketplace: pays AI calls
- Agent action tools → Bursar vault: submits guarded payments
- Bursar vault → Circle agent wallet: rejects rule violations
- Agent action tools → Wallet screening: checks wallets
- Agent action tools → Customer email: sends reminders and receipts
- Agent action tools → Owner approvals: requests owner review
- Agent action tools → Decision history: records decisions
- Decision history → Business database: reads decision history (evidence: `app/src/app/api/decisions/route.ts`)
- Agent run coordinator → Savings contract: deposits savings
- Business dashboard → RPC relay: relays signed chain calls (evidence: `app/src/app/api/rpc/route.ts`)
- RPC relay → Arc chain access: forwards RPC (evidence: `app/src/app/api/rpc/route.ts`)
- Arc chain access → Bursar vault: reads vault
