# prabhavalabs/opentreasury architecture

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

- Interactive diagram: https://gitdiagram.com/prabhavalabs/opentreasury
- Repository: https://github.com/prabhavalabs/opentreasury

## Overview

OpenTreasury is a public-finance transparency and treasury-management platform. Government finance exports are mapped by connectors and submitted to the Core API, which validates treasury lifecycle rules and persists operational data in PostgreSQL; the ledger gateway anchors public-safe proofs to a traceability backend. Web and mobile applications, public APIs, independent verification, and MCP tools expose the resulting information. The graph includes README-documented capabilities whose implementation was not sampled; those broader links are marked dashed where source-level wiring was not shown.

Main entry points: [`services/core-api/internal/httpapi/router.go`](https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/httpapi/router.go) (Core API), [`services/ledger-gateway/internal/anchor/anchor.go`](https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/internal/anchor/anchor.go) (Ledger gateway), [`services/ledger-gateway/cmd/verify/main.go`](https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/cmd/verify/main.go) (Independent verifier), [`services/connectors/generic-file/internal/connector/deliver.go`](https://github.com/prabhavalabs/opentreasury/blob/main/services/connectors/generic-file/internal/connector/deliver.go) (File connector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Ingestion and treasury"]
  node_connector["File connector<br/>[deliver.go]"]
  node_treasury["Treasury rules"]
  node_journal["Journal and accounts"]
  node_commitments["Commitments<br/>[commitment.go]"]
  node_reconciliation["Reconciliation"]
  node_insights["Insights<br/>[insights.go]"]
end

subgraph group_backend["API and persistence"]
  node_core["Core API<br/>[router.go]"]
  node_auth["Identity and policy<br/>[authz.go]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_traceability["Public traceability"]
  node_ledger["Ledger gateway<br/>[anchor.go]"]
  node_merkle["Merkle proofs<br/>[merkle.go]"]
  node_chaincode["Fabric chaincode<br/>[anchor_contract.go]"]
  node_verify["Independent verifier<br/>[main.go]"]
end

subgraph group_clients["User applications"]
  node_web["Web dashboard<br/>[index.tsx]"]
  node_mobile["Mobile app<br/>[explorer.tsx]"]
  node_mcp["MCP server<br/>[main.go]"]
end

subgraph group_integrations["External integrations"]
  node_fabric[("Hyperledger Fabric")]
  node_oidc["OIDC identity provider"]
end

node_gov(("Government systems"))
node_auditors(("Auditors and public"))

node_gov -->|"provides exports"| node_connector
node_connector -->|"submits staging data"| node_core
node_core -->|"checks access"| node_auth
node_core -->|"validates lifecycle"| node_treasury
node_core -->|"persists records"| node_postgres
node_core -->|"serves journal data"| node_journal
node_core -.->|"serves commitments"| node_commitments
node_core -.->|"serves reconciliation"| node_reconciliation
node_core -->|"serves insights"| node_insights
node_ledger -->|"builds proofs"| node_merkle
node_ledger -->|"reads and records anchors"| node_postgres
node_ledger -->|"commits roots"| node_chaincode
node_chaincode -->|"records anchors"| node_fabric
node_web -.->|"uses APIs"| node_core
node_mobile -.->|"uses APIs"| node_core
node_verify -->|"fetches proofs"| node_core
node_verify -->|"checks inclusion"| node_merkle
node_mcp -->|"reads public tier"| node_core
node_oidc -.->|"provides identity"| node_auth
node_auditors -.->|"reviews dashboards"| node_web
node_auditors -.->|"checks entries"| node_mobile
node_auditors -.->|"independently verifies"| node_verify
node_auditors -.->|"queries public data"| node_mcp

click node_connector "https://github.com/prabhavalabs/opentreasury/blob/main/services/connectors/generic-file/internal/connector/deliver.go"
click node_core "https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/httpapi/router.go"
click node_auth "https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/authz/authz.go"
click node_treasury "https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury"
click node_journal "https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury"
click node_commitments "https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/treasury/commitment.go"
click node_reconciliation "https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury"
click node_insights "https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/treasury/insights.go"
click node_ledger "https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/internal/anchor/anchor.go"
click node_merkle "https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/internal/merkle/merkle.go"
click node_chaincode "https://github.com/prabhavalabs/opentreasury/blob/main/chaincode/treasury/internal/contract/anchor_contract.go"
click node_web "https://github.com/prabhavalabs/opentreasury/blob/main/apps/web/src/routes/index.tsx"
click node_mobile "https://github.com/prabhavalabs/opentreasury/blob/main/apps/mobile/src/app/(tabs)/explorer.tsx"
click node_verify "https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/cmd/verify/main.go"
click node_mcp "https://github.com/prabhavalabs/opentreasury/blob/main/services/mcp-server/cmd/mcp-server/main.go"

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_connector,node_treasury,node_journal,node_commitments,node_reconciliation,node_insights toneBlue
class node_core,node_auth,node_postgres toneAmber
class node_ledger,node_merkle,node_chaincode,node_verify toneMint
class node_web,node_mobile,node_mcp toneRose
class node_fabric,node_oidc,node_gov,node_auditors toneIndigo
```

## Components

### Ingestion and treasury

- [File connector](https://github.com/prabhavalabs/opentreasury/blob/main/services/connectors/generic-file/internal/connector/deliver.go): `services/connectors/generic-file/internal/connector/deliver.go`
- [Treasury rules](https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury): `services/core-api/internal/treasury`
- [Journal and accounts](https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury): `services/core-api/internal/treasury`
- [Commitments](https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/treasury/commitment.go): `services/core-api/internal/treasury/commitment.go`
- [Reconciliation](https://github.com/prabhavalabs/opentreasury/tree/main/services/core-api/internal/treasury): `services/core-api/internal/treasury`
- [Insights](https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/treasury/insights.go): `services/core-api/internal/treasury/insights.go`

### API and persistence

- [Core API](https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/httpapi/router.go): `services/core-api/internal/httpapi/router.go`
- [Identity and policy](https://github.com/prabhavalabs/opentreasury/blob/main/services/core-api/internal/authz/authz.go): `services/core-api/internal/authz/authz.go`
- **PostgreSQL**

### Public traceability

- [Ledger gateway](https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/internal/anchor/anchor.go): `services/ledger-gateway/internal/anchor/anchor.go`
- [Merkle proofs](https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/internal/merkle/merkle.go): `services/ledger-gateway/internal/merkle/merkle.go`
- [Fabric chaincode](https://github.com/prabhavalabs/opentreasury/blob/main/chaincode/treasury/internal/contract/anchor_contract.go): `chaincode/treasury/internal/contract/anchor_contract.go`
- [Independent verifier](https://github.com/prabhavalabs/opentreasury/blob/main/services/ledger-gateway/cmd/verify/main.go): `services/ledger-gateway/cmd/verify/main.go`

### User applications

- [Web dashboard](https://github.com/prabhavalabs/opentreasury/blob/main/apps/web/src/routes/index.tsx): `apps/web/src/routes/index.tsx`
- [Mobile app](https://github.com/prabhavalabs/opentreasury/blob/main/apps/mobile/src/app/(tabs)/explorer.tsx): `apps/mobile/src/app/(tabs)/explorer.tsx`
- [MCP server](https://github.com/prabhavalabs/opentreasury/blob/main/services/mcp-server/cmd/mcp-server/main.go): `services/mcp-server/cmd/mcp-server/main.go`

### External integrations

- **Hyperledger Fabric**
- **OIDC identity provider**

### Other components

- **Government systems**
- **Auditors and public**

## Connections

- Government systems → File connector: provides exports (evidence: `README.md`)
- File connector → Core API: submits staging data
- Core API → Identity and policy: checks access
- Core API → Treasury rules: validates lifecycle (evidence: `README.md`)
- Core API → PostgreSQL: persists records
- Core API → Journal and accounts: serves journal data (evidence: `services/core-api/internal/httpapi/router.go`)
- Core API → Commitments: serves commitments (evidence: `README.md`)
- Core API → Reconciliation: serves reconciliation (evidence: `README.md`)
- Core API → Insights: serves insights (evidence: `services/core-api/internal/httpapi/router.go`)
- Ledger gateway → Merkle proofs: builds proofs (evidence: `services/ledger-gateway/internal/anchor/anchor.go`)
- Ledger gateway → PostgreSQL: reads and records anchors (evidence: `README.md`)
- Ledger gateway → Fabric chaincode: commits roots
- Fabric chaincode → Hyperledger Fabric: records anchors (evidence: `README.md`)
- Web dashboard → Core API: uses APIs (evidence: `README.md`)
- Mobile app → Core API: uses APIs (evidence: `README.md`)
- Independent verifier → Core API: fetches proofs (evidence: `services/ledger-gateway/cmd/verify/main.go`)
- Independent verifier → Merkle proofs: checks inclusion (evidence: `services/ledger-gateway/cmd/verify/main.go`)
- MCP server → Core API: reads public tier (evidence: `services/mcp-server/cmd/mcp-server/main.go`)
- OIDC identity provider → Identity and policy: provides identity (evidence: `README.md`)
- Auditors and public → Web dashboard: reviews dashboards (evidence: `README.md`)
- Auditors and public → Mobile app: checks entries (evidence: `README.md`)
- Auditors and public → Independent verifier: independently verifies (evidence: `README.md`)
- Auditors and public → MCP server: queries public data (evidence: `README.md`)
