How rithvikronaldo/acta works
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: ledger Ledger core · app Next.js app · router.go HTTP API · main.go API server
Components 22
Go backend
HTTP API, ledger domain, database, eventing, and worker commands.
- API server · Starts the HTTP API process.
cmd/api/main.go - Snapshot job · Runs offline snapshot computation for point-in-time balance queries.
cmd/snapshot/main.go - HTTP API · Routes health, transactions, balances, authorizations, tenants, agents, events, stress, and demo endpoints.
internal/api/router.go - Auth middleware · Enforces API key and tenant context on protected endpoints.
internal/api/middleware_auth.go - Demo traffic · Bootstraps and simulates the public demo tenant and synthetic activity.
internal/api/demo_bootstrap.go - SSE stream · Exposes the live event feed to the dashboard.
internal/api/events.go - Ledger core · Double-entry accounting, balances, authorization lifecycle, tenant scope, snapshots, FX, and transaction listing.
internal/ledger - Balances · Computes current and historical balance state, including holds and point-in-time queries.
internal/ledger/balance.go - Authorizations · Models reserve, capture, and void flows as a distinct accounting boundary.
internal/ledger/auth.go - Tenancy · Assigns and scopes accounts, agents, and reads/writes by tenant.
internal/ledger/tenant.go - Snapshots · Maintains historical balance snapshots and replay semantics.
internal/ledger/snapshot.go - FX lookup · Resolves historical exchange rates at or before a requested timestamp.
internal/ledger/fx.go - Postgres DB · Database access layer used by the API and ledger domain.
internal/db/db.go - Event bus · 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 · Standalone dashboard UI that consumes APIs and SSE, and owns local interaction state.
web/app - Live stream · Renders incoming transactions and realtime updates.
web/components/transaction-stream.tsx - Treasury view · Shows balances, availability, and account-level financial state.
web/components/treasury-center.tsx - Replay controls · 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 · Defines tables, triggers, snapshots, authorizations, agents, tenants, and tenant-scoping constraints.
migrations - Deployment · 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 · Standalone HTML prototype for layout and rendering reference.
prototypes/dashboard.html - Docs · Design notes, README, and blog content that document the system and product story.
DESIGN.md
Connections 27
- 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.