# rithvikronaldo/acta architecture

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

- Interactive diagram: https://gitdiagram.com/rithvikronaldo/acta
- Repository: https://github.com/rithvikronaldo/acta

## Overview

1. **Overall shape**
   - `acta` is a two-part system: a Go backend that owns the ledger and a Next.js frontend that renders the live dashboard.
   - The backend is the source of truth; the frontend is a consumer of API and SSE events, not a separate business-logic layer.

2. **Go backend entrypoints**
   - `cmd/api/main.go` starts the HTTP API server.
   - `cmd/snapshot/main.go` runs the offline snapshot job used for point-in-time balance queries.
   - This split matters architecturally: online transactional reads/writes stay in the API, while snapshot computation is a separate maintenance workflow.

3. **HTTP API boundary**
   - `internal/api` contains route handlers for health, transactions, balances, authorizations, tenants, agents, events, and stress/demo endpoints.
   - `internal/api/router.go` wires the surface area together, while `middleware_auth.go` enforces API-key and tenant context on protected endpoints.
   - The API is the narrow boundary between external clients and the ledger domain.

4. **Ledger domain core**
   - `internal/ledger` contains the business rules for double-entry accounting, balances, FX lookup, authorization lifecycle, tenant scoping, snapshots, and transaction listing.
   - This is where invariants live: balanced entries, point-in-time semantics, authorization hold semantics, and tenant isolation.
   - The tests in this package are substantial, which suggests the core rules are validated mostly at the domain layer rather than in handlers.

5. **Database and schema**
   - `internal/db` is the database plumbing, backed by Postgres migrations in `migrations/`.
   - The schema evolves in layers: base ledger tables, invariant triggers, account snapshots, authorizations, agents, tenants, and tenant-scoping/uniqueness constraints.
   - The database is not just persistence; it also enforces critical invariants through SQL and trigger logic.

6. **Transaction posting flow**
   - A client posts balanced entries over HTTP, usually with an `Idempotency-Key`.
   - The API validates input, passes it into the ledger domain, and the write path persists the transaction and its entries in Postgres.
   - Idempotency is part of the service contract: retries can return the original response, while mismatched replays or concurrent duplicates are rejected.

7. **Balances and point-in-time queries**
   - Current balance queries combine realized ledger state with pending authorization holds to produce `balance`, `available`, and `on_hold`.
   - Historical queries use `account_snapshots` plus replay of later entries, so the system avoids scanning the full ledger every time.
   - FX conversion is also historical: rate lookup uses the latest observation at or before the requested timestamp.

8. **Authorization lifecycle**
   - The authorization subsystem models reserve/capture/void flows separately from normal transactions.
   - Holds reduce availability without immediately realizing the balance movement; capture moves value, and void releases it.
   - This is a distinct accounting boundary, not just a transaction type alias.

9. **Eventing and realtime UI**
   - `internal/events/broadcaster.go` provides an in-process event fanout that backs the `/events/stream` Server-Sent Events endpoint.
   - Events are emitted when ledger activity occurs, and the dashboard subscribes to them to update in real time.
   - This is a one-way stream from backend to frontend; the frontend does not write to the event system.

10. **Multi-tenancy and auth**
    - Tenant support is first-class in both schema and API: `tenants` tables, tenant-scoped unique constraints, signup flows, and API-key authentication.
    - `internal/ledger/tenant.go`, `auth.go`, and `agent.go` indicate the domain assigns accounts and agents to tenants and enforces isolation across reads and writes.
    - The public demo tenant is a special case for anonymous viewing, but the normal model is tenant-bound access.

11. **Demo and stress simulation**
    - `internal/api/demo_bootstrap.go`, `demo_simulator.go`, and `stress.go` support the live sandbox experience.
    - The demo tenant emits steady authorize/capture/void traffic so the dashboard has visible movement without user setup.
    - This creates a production-like observability layer for the product’s showcase mode.

12. **Frontend architecture**
    - `web/` is a separate Next.js app using React, Tailwind, Zustand, and Motion.
    - Its main job is presentation and interaction: live transaction stream, agent cards, treasury view, scrubber/replay controls, and onboarding dialogs.
    - It consumes backend APIs plus SSE, and maintains local UI state for replay, simulation, and dashboard interactions.

13. **Offline/demo assets and docs**
    - `prototypes/dashboard.html` is a standalone vanilla-JS prototype, useful as a lightweight rendering reference and for screenshots.
    - `blog/`, `DESIGN.md`, and the docs page under `web/app/docs` show that the repository includes product/engineering narrative alongside code.
    - This suggests the repo is both an application and a public-facing technical artifact.

14. **Infrastructure and deployment shape**
    - The repo includes Docker, `docker-compose.yml`, Fly.io config, and Render config, indicating containerized deployment with Postgres as the backing service.
    - The architecture is therefore “Go API + Postgres + separate web frontend,” with the snapshot job as an auxiliary worker-style command.
    - Local development mirrors production closely: database in Docker, migrations applied separately, then API and frontend run independently.

Main entry points: [`internal/ledger`](https://github.com/rithvikronaldo/acta/tree/main/internal/ledger) (Ledger core), [`web/app`](https://github.com/rithvikronaldo/acta/tree/main/web/app) (Next.js app), [`internal/api/router.go`](https://github.com/rithvikronaldo/acta/blob/main/internal/api/router.go) (HTTP API), [`cmd/api/main.go`](https://github.com/rithvikronaldo/acta/blob/main/cmd/api/main.go) (API server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Go backend"]
  node_api_main(("API server<br/>go cmd<br/>[main.go]"))
  node_snapshot_main(("Snapshot job<br/>go cmd<br/>[main.go]"))
  node_api_router["HTTP API<br/>handler layer<br/>[router.go]"]
  node_api_auth["Auth middleware<br/>api middleware<br/>[middleware_auth.go]"]
  node_api_demo["Demo traffic<br/>demo/stress<br/>[demo_bootstrap.go]"]
  node_api_events["SSE stream<br/>event endpoint<br/>[events.go]"]
  node_ledger_core["Ledger core<br/>domain rules"]
  node_ledger_balance["Balances<br/>domain service<br/>[balance.go]"]
  node_ledger_auth["Authorizations<br/>domain service<br/>[auth.go]"]
  node_ledger_tenant["Tenancy<br/>domain service<br/>[tenant.go]"]
  node_ledger_snapshot["Snapshots<br/>domain service<br/>[snapshot.go]"]
  node_ledger_fx["FX lookup<br/>domain service<br/>[fx.go]"]
  node_db[("Postgres DB<br/>db plumbing<br/>[db.go]")]
  node_events_bus["Event bus<br/>fanout<br/>[broadcaster.go]"]
end

subgraph group_frontend["Web app"]
  node_web_app["Next.js app<br/>frontend app"]
  node_web_stream["Live stream<br/>ui component"]
  node_web_treasury["Treasury view<br/>ui component"]
  node_web_replay["Replay controls<br/>ui state<br/>[replay-queue.ts]"]
end

subgraph group_infra["Infra & schema"]
  node_schema["Migrations<br/>sql schema"]
  node_deploy["Deployment<br/>container/config<br/>[docker-compose.yml]"]
end

subgraph group_docs["Docs & demos"]
  node_demo_proto["Dashboard prototype<br/>[dashboard.html]"]
  node_repo_docs["Docs<br/>[DESIGN.md]"]
end

node_api_main -->|"starts"| node_api_router
node_api_main -->|"uses"| node_db
node_snapshot_main -->|"runs"| node_ledger_snapshot
node_api_router -->|"protects"| node_api_auth
node_api_router -->|"delegates"| node_ledger_core
node_api_router -->|"serves"| node_api_events
node_api_router -->|"exposes"| node_api_demo
node_api_demo -->|"publishes"| node_events_bus
node_ledger_core -->|"persists"| node_db
node_ledger_core -->|"includes"| node_ledger_balance
node_ledger_core -->|"includes"| node_ledger_auth
node_ledger_core -->|"includes"| node_ledger_tenant
node_ledger_core -->|"includes"| node_ledger_snapshot
node_ledger_core -->|"includes"| node_ledger_fx
node_ledger_core -->|"depends on"| node_schema
node_events_bus -->|"streams to"| node_api_events
node_web_app -->|"consumes"| node_api_router
node_web_app -->|"subscribes"| node_api_events
node_web_app -->|"composes"| node_web_stream
node_web_app -->|"composes"| node_web_treasury
node_web_app -->|"manages"| node_web_replay
node_schema -->|"shapes"| node_db
node_deploy -->|"runs"| node_api_main
node_deploy -->|"runs"| node_web_app
node_demo_proto -.->|"references"| node_web_app
node_repo_docs -.->|"documents"| node_ledger_core
node_repo_docs -.->|"documents"| node_web_app

click node_api_main "https://github.com/rithvikronaldo/acta/blob/main/cmd/api/main.go"
click node_snapshot_main "https://github.com/rithvikronaldo/acta/blob/main/cmd/snapshot/main.go"
click node_api_router "https://github.com/rithvikronaldo/acta/blob/main/internal/api/router.go"
click node_api_auth "https://github.com/rithvikronaldo/acta/blob/main/internal/api/middleware_auth.go"
click node_api_demo "https://github.com/rithvikronaldo/acta/blob/main/internal/api/demo_bootstrap.go"
click node_api_events "https://github.com/rithvikronaldo/acta/blob/main/internal/api/events.go"
click node_ledger_core "https://github.com/rithvikronaldo/acta/tree/main/internal/ledger"
click node_ledger_balance "https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/balance.go"
click node_ledger_auth "https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/auth.go"
click node_ledger_tenant "https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/tenant.go"
click node_ledger_snapshot "https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/snapshot.go"
click node_ledger_fx "https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/fx.go"
click node_db "https://github.com/rithvikronaldo/acta/blob/main/internal/db/db.go"
click node_events_bus "https://github.com/rithvikronaldo/acta/blob/main/internal/events/broadcaster.go"
click node_web_app "https://github.com/rithvikronaldo/acta/tree/main/web/app"
click node_web_stream "https://github.com/rithvikronaldo/acta/blob/main/web/components/transaction-stream.tsx"
click node_web_treasury "https://github.com/rithvikronaldo/acta/blob/main/web/components/treasury-center.tsx"
click node_web_replay "https://github.com/rithvikronaldo/acta/blob/main/web/lib/replay-queue.ts"
click node_schema "https://github.com/rithvikronaldo/acta/tree/main/migrations"
click node_deploy "https://github.com/rithvikronaldo/acta/blob/main/docker-compose.yml"
click node_demo_proto "https://github.com/rithvikronaldo/acta/blob/main/prototypes/dashboard.html"
click node_repo_docs "https://github.com/rithvikronaldo/acta/blob/main/DESIGN.md"

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_api_main,node_snapshot_main,node_api_router,node_api_auth,node_api_demo,node_api_events,node_ledger_core,node_ledger_balance,node_ledger_auth,node_ledger_tenant,node_ledger_snapshot,node_ledger_fx,node_db,node_events_bus toneBlue
class node_web_app,node_web_stream,node_web_treasury,node_web_replay toneAmber
class node_schema,node_deploy toneMint
class node_demo_proto,node_repo_docs toneRose
```

## Components

### Go backend

HTTP API, ledger domain, database, eventing, and worker commands.

- [API server](https://github.com/rithvikronaldo/acta/blob/main/cmd/api/main.go): go cmd · Starts the HTTP API process. · `cmd/api/main.go`
- [Snapshot job](https://github.com/rithvikronaldo/acta/blob/main/cmd/snapshot/main.go): go cmd · Runs offline snapshot computation for point-in-time balance queries. · `cmd/snapshot/main.go`
- [HTTP API](https://github.com/rithvikronaldo/acta/blob/main/internal/api/router.go): handler layer · Routes health, transactions, balances, authorizations, tenants, agents, events, stress, and demo endpoints. · `internal/api/router.go`
- [Auth middleware](https://github.com/rithvikronaldo/acta/blob/main/internal/api/middleware_auth.go): api middleware · Enforces API key and tenant context on protected endpoints. · `internal/api/middleware_auth.go`
- [Demo traffic](https://github.com/rithvikronaldo/acta/blob/main/internal/api/demo_bootstrap.go): demo/stress · Bootstraps and simulates the public demo tenant and synthetic activity. · `internal/api/demo_bootstrap.go`
- [SSE stream](https://github.com/rithvikronaldo/acta/blob/main/internal/api/events.go): event endpoint · Exposes the live event feed to the dashboard. · `internal/api/events.go`
- [Ledger core](https://github.com/rithvikronaldo/acta/tree/main/internal/ledger): domain rules · Double-entry accounting, balances, authorization lifecycle, tenant scope, snapshots, FX, and transaction listing. · `internal/ledger`
- [Balances](https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/balance.go): domain service · Computes current and historical balance state, including holds and point-in-time queries. · `internal/ledger/balance.go`
- [Authorizations](https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/auth.go): domain service · Models reserve, capture, and void flows as a distinct accounting boundary. · `internal/ledger/auth.go`
- [Tenancy](https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/tenant.go): domain service · Assigns and scopes accounts, agents, and reads/writes by tenant. · `internal/ledger/tenant.go`
- [Snapshots](https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/snapshot.go): domain service · Maintains historical balance snapshots and replay semantics. · `internal/ledger/snapshot.go`
- [FX lookup](https://github.com/rithvikronaldo/acta/blob/main/internal/ledger/fx.go): domain service · Resolves historical exchange rates at or before a requested timestamp. · `internal/ledger/fx.go`
- [Postgres DB](https://github.com/rithvikronaldo/acta/blob/main/internal/db/db.go): db plumbing · Database access layer used by the API and ledger domain. · `internal/db/db.go`
- [Event bus](https://github.com/rithvikronaldo/acta/blob/main/internal/events/broadcaster.go): fanout · In-process broadcaster that feeds the SSE endpoint. · `internal/events/broadcaster.go`

### Web app

Next.js dashboard and its client-side state and presentation layers.

- [Next.js app](https://github.com/rithvikronaldo/acta/tree/main/web/app): frontend app · Standalone dashboard UI that consumes APIs and SSE, and owns local interaction state. · `web/app`
- [Live stream](https://github.com/rithvikronaldo/acta/blob/main/web/components/transaction-stream.tsx): ui component · Renders incoming transactions and realtime updates. · `web/components/transaction-stream.tsx`
- [Treasury view](https://github.com/rithvikronaldo/acta/blob/main/web/components/treasury-center.tsx): ui component · Shows balances, availability, and account-level financial state. · `web/components/treasury-center.tsx`
- [Replay controls](https://github.com/rithvikronaldo/acta/blob/main/web/lib/replay-queue.ts): ui state · Manages scrubber, replay, capture, and time-skip interaction state. · `web/lib/replay-queue.ts`

### Infra & schema

Deployment and migration assets that shape runtime and storage.

- [Migrations](https://github.com/rithvikronaldo/acta/tree/main/migrations): sql schema · Defines tables, triggers, snapshots, authorizations, agents, tenants, and tenant-scoping constraints. · `migrations`
- [Deployment](https://github.com/rithvikronaldo/acta/blob/main/docker-compose.yml): container/config · Docker, compose, Fly.io, and Render setup for running the API, web app, and Postgres. · `docker-compose.yml`

### Docs & demos

Narrative, prototype, and product-facing reference material.

- [Dashboard prototype](https://github.com/rithvikronaldo/acta/blob/main/prototypes/dashboard.html): prototype · Standalone HTML prototype for layout and rendering reference. · `prototypes/dashboard.html`
- [Docs](https://github.com/rithvikronaldo/acta/blob/main/DESIGN.md): docs · Design notes, README, and blog content that document the system and product story. · `DESIGN.md`

## Connections

- API server → HTTP API: starts · API binary hosts the HTTP surface.
- API server → Postgres DB: uses · API connects to Postgres through the DB layer.
- Snapshot job → Snapshots: runs · Snapshot command executes offline snapshot computation.
- HTTP API → Auth middleware: protects · Router applies auth middleware to protected routes.
- HTTP API → Ledger core: delegates · Handlers hand business operations to the ledger domain.
- HTTP API → SSE stream: serves · Routes the SSE stream endpoint.
- HTTP API → Demo traffic: exposes · Includes demo and stress endpoints.
- Demo traffic → Event bus: publishes · Demo activity feeds the live event stream.
- Ledger core → Postgres DB: persists · Domain writes and reads ledger state from Postgres.
- Ledger core → Balances: includes · Balance computation is a central domain capability.
- Ledger core → Authorizations: includes · Authorization lifecycle is part of the domain boundary.
- Ledger core → Tenancy: includes · Tenant scoping and isolation are enforced in-domain.
- Ledger core → Snapshots: includes · Historical balance semantics rely on snapshots and replay.
- Ledger core → FX lookup: includes · Historical FX conversion is part of balance semantics.
- Ledger core → Migrations: depends on · Domain invariants are reinforced by schema and trigger logic.
- Event bus → SSE stream: streams to · Broadcaster feeds the SSE endpoint.
- Next.js app → HTTP API: consumes · Frontend calls API endpoints for data and actions.
- Next.js app → SSE stream: subscribes · Frontend receives live updates via SSE.
- Next.js app → Live stream: composes · The dashboard includes a live transaction stream.
- Next.js app → Treasury view: composes · The dashboard includes treasury and balance views.
- Next.js app → Replay controls: manages · Local UI state controls replay and scrubber interaction.
- Migrations → Postgres DB: shapes · Migrations define the database structure used by the DB layer.
- Deployment → API server: runs · Deployment config includes the API service.
- Deployment → Next.js app: runs · Deployment config includes the frontend app.
- Dashboard prototype → Next.js app: references · Prototype informs the dashboard presentation.
- Docs → Ledger core: documents · Docs explain accounting rules and system behavior.
- Docs → Next.js app: documents · Docs also cover the frontend product experience.
