How chrinoreesambu/ledger works
Formance Ledger is a programmable financial core: clients submit atomic postings or Numscript transactions, then query ledger state and balances. The API delegates ledger operations to controllers, which apply transaction rules and persist ledger records. The README identifies PostgreSQL as the transactional store and describes shipping ledger logs to replica stores; sampled pipeline code confirms ordered log fetching and exporter delivery. The v2 pipeline endpoints delegate lifecycle operations to the system controller. The tree documents additional query, schema, bucket, and log-import/export capabilities; their internal wiring is not inferred here.
Main entry points: controller_default.go Ledger controller · routes.go v2 controllers · controller.go System controller · driver.go Exporter drivers
Components 21
API surface
- HTTP API
internal/api/router.go - v2 controllers
internal/api/v2/routes.go - Pipeline endpoints
internal/api/v2/controllers_pipeline_create.go
Ledger domain
- System controller
internal/controller/system/controller.go - Ledger controller
internal/controller/ledger/controller_default.go - Numscript runtime
internal/controller/ledger/numscript_runtime.go - Transaction machine
internal/machine/vm/run.go - Accounts and balances
internal/api/v2/controllers_accounts_list.go - Transactions
internal/api/v2/controllers_transactions_create.go - Schemas and queries
internal/api/v2/controllers_schema_insert.go
Persistence
- Ledger storage
internal/storage/ledger/store.go - System storage
internal/storage/system/store.go
Log replication
- Pipeline state
internal/pipeline.go - Log pipeline
internal/replication/pipeline.go - Exporter drivers
internal/replication/drivers/driver.go - ClickHouse exporter
internal/replication/drivers/clickhouse/driver.go - Elasticsearch exporter
internal/replication/drivers/elasticsearch/driver.go - HTTP exporter
internal/replication/drivers/http/driver.go
Other components
- Ledger client
pkg/client/v2.go - PostgreSQL
- Replica data store
Connections 26
- Ledger client → HTTP API: sends requests
- HTTP API → v2 controllers: routes requests
- v2 controllers → Transactions: dispatches
- v2 controllers → Accounts and balances: dispatches
- v2 controllers → Schemas and queries: dispatches
- v2 controllers → Pipeline endpoints: dispatches
- Transactions → Ledger controller: invokes
- Accounts and balances → Ledger controller: invokes
- Schemas and queries → Ledger controller: invokes
- Pipeline endpoints → System controller: invokes
- System controller → Ledger controller: obtains controller
- Ledger controller → Numscript runtime: parses scripts
- Ledger controller → Transaction machine: executes transactions
- Ledger controller → Ledger storage: reads and writes
- Ledger storage → PostgreSQL: persists records
- System controller → System storage: manages state
- System storage → PostgreSQL: persists state
- System controller → Pipeline state: manages pipelines
- Log pipeline → Ledger storage: fetches logs
- Log pipeline → Exporter drivers: delivers logs
- Exporter drivers → ClickHouse exporter: selects exporter
- Exporter drivers → Elasticsearch exporter: selects exporter
- Exporter drivers → HTTP exporter: selects exporter
- ClickHouse exporter → Replica data store: writes replica data
- Elasticsearch exporter → Replica data store: writes replica data
- HTTP exporter → Replica data store: sends replica data