# mikashboks/formance-stack architecture

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

- Interactive diagram: https://gitdiagram.com/mikashboks/formance-stack
- Repository: https://github.com/mikashboks/formance-stack

## Overview

#### Purpose and Entry Points
This repository assembles the Formance Stack: a modular financial-services platform centered on an immutable double-entry ledger, payments data/APIs, and orchestration. Service implementations are versioned external components; this repo supplies stack composition, shared event contracts, release assembly, and validation assets.

Local entry point: `docker-compose.yml`, exposing the gateway API at `/api`. Developer-local variants use `.local/docker-compose.yml` and `.local/process-compose.yaml`. Build orchestration is rooted at `Earthfile`.

#### Stack Composition and Gateway
Docker Compose defines the runnable service topology and its dependencies; the local Caddy gateway configuration is at `.local/gateway/Caddyfile`. Production deployment is intended to package independently deployable service binaries/images, typically to Kubernetes via external Helm charts.

The HTTP gateway is a boundary between clients and module APIs. PostgreSQL is the primary persistent backend; Kafka or NATS provide asynchronous inter-service communication, per the stack’s documented infrastructure model.

Paths: `docker-compose.yml`, `.local/docker-compose.yml`, `.local/gateway/Caddyfile`.

#### Versioned Event Contract Library
`libs/events` is the shared cross-service event schema package. YAML files are canonical service/version/event definitions; generation produces JSON schemas and aggregate metadata for consumers. This is the principal compatibility boundary among Ledger, Payments, and Orchestration modules.

Supported domains include:
- Ledger transaction commits, reversals, metadata lifecycle.
- Payments connector, account, balance, payment, pool, and initiation lifecycle.
- Orchestration trigger, workflow, and workflow-stage outcomes.

Paths: `libs/events/events.go`, `libs/events/services/payments/v3.0.0/SAVED_PAYMENT_INITIATION.yaml`, `libs/events/generated/all.json`.

#### Ledger Domain
Ledger is the system of record for programmable, immutable, double-entry transactions. Its externally observable event interface evolves independently, with ledger v1 and v2 event schemas for committed transactions, reversals, and metadata changes. Numscript is the monetary-computation and transaction-modeling DSL/VM used by the broader platform, though its implementation is not present in this tree.

Paths: `libs/events/services/ledger/v2.0.0/COMMITTED_TRANSACTIONS.yaml`, `libs/events/services/ledger/v2.0.0/REVERTED_TRANSACTION.yaml`.

#### Payments and Orchestration Domains
Payments provides a unified payment-processing data layer, emitting versioned state-change events for connector synchronization and payment entities. Orchestration models asynchronous trigger/workflow execution and publishes started, succeeded, and failed transitions. These domains communicate at the event boundary rather than through this repository’s direct implementation code.

Paths: `libs/events/services/payments/v3.0.0/CONNECTOR_RESET.yaml`, `libs/events/services/payments/v3.0.0/SAVED_PAYMENT.yaml`, `libs/events/services/orchestration/v2.0.0/FAILED_WORKFLOW.yaml`.

#### Release and Integration Boundary
Release assets consolidate API specifications through merge and overlay configuration. Integration infrastructure provisions a multi-module environment—including auth, ledger, payments, orchestration, reconciliation, search, wallets, and webhooks—and can use Temporalite for workflow-oriented testing. This indicates services are composed and exercised as independently managed modules behind the common gateway.

Paths: `releases/openapi-merge.json`, `releases/openapi-overlay.json`, `tests/integration/docker-compose.yml`, `tests/integration/temporalite.Dockerfile`.

#### Operational Validation
Separate load and benchmark environments drive ledger write/read workloads and observe service behavior. Benchmark tooling includes PostgreSQL plus OpenTelemetry collection, Prometheus, and Grafana dashboard provisioning, making performance and telemetry part of the composed-stack operating model.

Paths: `tests/benchmarks/tools/docker-compose.yml`, `tests/benchmarks/tools/otel-collector-config.yaml`, `tests/loadtesting/docker-compose.ledger.yml`.

Main entry points: [`.local/gateway/Caddyfile`](https://github.com/mikashboks/formance-stack/blob/release/v3.0/.local/gateway/Caddyfile) (HTTP gateway), [`tests/integration/docker-compose.yml`](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/integration/docker-compose.yml) (Integration environment), [`libs/events/generated/all.json`](https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/generated/all.json) (Generated event catalog), [`docker-compose.yml`](https://github.com/mikashboks/formance-stack/blob/release/v3.0/docker-compose.yml) (Stack topology)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_composition["Stack Composition"]
  node_earthfile["Build orchestration"]
  node_compose["Stack topology<br/>compose<br/>[docker-compose.yml]"]
  node_local_compose["Local stack variant<br/>compose<br/>[docker-compose.yml]"]
  node_gateway{{"HTTP gateway<br/>Caddy config<br/>[Caddyfile]"}}
  node_postgres[("PostgreSQL<br/>persistent store")]
  node_broker["Kafka / NATS<br/>event broker"]
end

subgraph group_contracts["Event Contracts"]
  node_event_generator["Event schema generator<br/>Go package<br/>[events.go]"]
  node_payment_event_schema["Payments event definitions<br/>YAML contract"]
  node_ledger_event_schema["Ledger v2 event definitions<br/>YAML contract"]
  node_event_catalog["Generated event catalog<br/>JSON schema<br/>[all.json]"]
end

subgraph group_domains["Module Domains"]
  node_ledger["Ledger<br/>external module"]
  node_payments["Payments<br/>external module"]
  node_orchestration["Orchestration<br/>external module"]
end

subgraph group_release["Release &amp; Integration"]
  node_release_api["Release API assembly<br/>OpenAPI merge<br/>[openapi-merge.json]"]
  node_integration_stack["Integration environment<br/>compose<br/>[docker-compose.yml]"]
  node_temporalite["Temporalite<br/>workflow runtime"]
end

subgraph group_operations["Operational Validation"]
  node_benchmark_stack["Benchmark telemetry stack<br/>compose<br/>[docker-compose.yml]"]
  node_otel["OpenTelemetry collector<br/>telemetry config"]
  node_ledger_load["Ledger load environment<br/>load test compose"]
end

node_earthfile -->|"builds stack"| node_compose
node_local_compose -->|"configures"| node_gateway
node_gateway -->|"routes API"| node_ledger
node_gateway -->|"routes API"| node_payments
node_gateway -->|"routes API"| node_orchestration
node_compose -->|"provisions"| node_postgres
node_compose -->|"provisions"| node_broker
node_ledger -->|"persists records"| node_postgres
node_payments -->|"persists data"| node_postgres
node_payment_event_schema -->|"canonical input"| node_event_generator
node_ledger_event_schema -->|"canonical input"| node_event_generator
node_event_generator -->|"generates"| node_event_catalog
node_ledger -->|"publishes events"| node_broker
node_payments -->|"publishes events"| node_broker
node_orchestration -->|"publishes events"| node_broker
node_event_catalog -.->|"compatibility contract"| node_ledger
node_event_catalog -.->|"compatibility contract"| node_payments
node_event_catalog -.->|"compatibility contract"| node_orchestration
node_release_api -.->|"assembles published API"| node_gateway
node_integration_stack -->|"includes"| node_temporalite
node_integration_stack -.->|"exercises"| node_ledger
node_integration_stack -.->|"exercises"| node_payments
node_integration_stack -.->|"exercises"| node_orchestration
node_benchmark_stack -->|"configures"| node_otel
node_ledger_load -.->|"loads"| node_ledger

click node_earthfile "https://github.com/mikashboks/formance-stack/blob/release/v3.0/Earthfile"
click node_compose "https://github.com/mikashboks/formance-stack/blob/release/v3.0/docker-compose.yml"
click node_local_compose "https://github.com/mikashboks/formance-stack/blob/release/v3.0/.local/docker-compose.yml"
click node_gateway "https://github.com/mikashboks/formance-stack/blob/release/v3.0/.local/gateway/Caddyfile"
click node_event_generator "https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/events.go"
click node_payment_event_schema "https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/services/payments/v3.0.0/SAVED_PAYMENT_INITIATION.yaml"
click node_ledger_event_schema "https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/services/ledger/v2.0.0/COMMITTED_TRANSACTIONS.yaml"
click node_event_catalog "https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/generated/all.json"
click node_release_api "https://github.com/mikashboks/formance-stack/blob/release/v3.0/releases/openapi-merge.json"
click node_integration_stack "https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/integration/docker-compose.yml"
click node_temporalite "https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/integration/temporalite.Dockerfile"
click node_benchmark_stack "https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/benchmarks/tools/docker-compose.yml"
click node_otel "https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/benchmarks/tools/otel-collector-config.yaml"
click node_ledger_load "https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/loadtesting/docker-compose.ledger.yml"

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_earthfile,node_compose,node_local_compose,node_gateway,node_postgres,node_broker toneBlue
class node_event_generator,node_payment_event_schema,node_ledger_event_schema,node_event_catalog toneAmber
class node_ledger,node_payments,node_orchestration toneMint
class node_release_api,node_integration_stack,node_temporalite toneRose
class node_benchmark_stack,node_otel,node_ledger_load toneIndigo
```

## Components

### Stack Composition

- [Build orchestration](https://github.com/mikashboks/formance-stack/blob/release/v3.0/Earthfile): build · `Earthfile`
- [Stack topology](https://github.com/mikashboks/formance-stack/blob/release/v3.0/docker-compose.yml): compose · `docker-compose.yml`
- [Local stack variant](https://github.com/mikashboks/formance-stack/blob/release/v3.0/.local/docker-compose.yml): compose · `.local/docker-compose.yml`
- [HTTP gateway](https://github.com/mikashboks/formance-stack/blob/release/v3.0/.local/gateway/Caddyfile): Caddy config · Exposes module APIs under /api. · `.local/gateway/Caddyfile`
- **PostgreSQL**: persistent store · Primary platform persistence backend.
- **Kafka / NATS**: event broker · Asynchronous inter-service transport.

### Event Contracts

- [Event schema generator](https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/events.go): Go package · `libs/events/events.go`
- [Payments event definitions](https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/services/payments/v3.0.0/SAVED_PAYMENT_INITIATION.yaml): YAML contract · Canonical versioned payment event schema. · `libs/events/services/payments/v3.0.0/SAVED_PAYMENT_INITIATION.yaml`
- [Ledger v2 event definitions](https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/services/ledger/v2.0.0/COMMITTED_TRANSACTIONS.yaml): YAML contract · Committed and reverted transaction contract family. · `libs/events/services/ledger/v2.0.0/COMMITTED_TRANSACTIONS.yaml`
- [Generated event catalog](https://github.com/mikashboks/formance-stack/blob/release/v3.0/libs/events/generated/all.json): JSON schema · Aggregate metadata and schemas for consumers. · `libs/events/generated/all.json`

### Module Domains

Independently deployed modules consume the shared contracts.

- **Ledger**: external module · Immutable double-entry system of record.
- **Payments**: external module · Payment-processing data layer and lifecycle publisher.
- **Orchestration**: external module · Asynchronous trigger and workflow execution.

### Release & Integration

- [Release API assembly](https://github.com/mikashboks/formance-stack/blob/release/v3.0/releases/openapi-merge.json): OpenAPI merge · Consolidates module API specifications. · `releases/openapi-merge.json`
- [Integration environment](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/integration/docker-compose.yml): compose · Composes platform modules and test infrastructure. · `tests/integration/docker-compose.yml`
- [Temporalite](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/integration/temporalite.Dockerfile): workflow runtime · Workflow-oriented integration test runtime. · `tests/integration/temporalite.Dockerfile`

### Operational Validation

- [Benchmark telemetry stack](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/benchmarks/tools/docker-compose.yml): compose · Provides PostgreSQL, telemetry, metrics, and dashboards. · `tests/benchmarks/tools/docker-compose.yml`
- [OpenTelemetry collector](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/benchmarks/tools/otel-collector-config.yaml): telemetry config · `tests/benchmarks/tools/otel-collector-config.yaml`
- [Ledger load environment](https://github.com/mikashboks/formance-stack/blob/release/v3.0/tests/loadtesting/docker-compose.ledger.yml): load test compose · Drives ledger read/write workloads. · `tests/loadtesting/docker-compose.ledger.yml`

## Connections

- Build orchestration → Stack topology: builds stack
- Local stack variant → HTTP gateway: configures
- HTTP gateway → Ledger: routes API
- HTTP gateway → Payments: routes API
- HTTP gateway → Orchestration: routes API
- Stack topology → PostgreSQL: provisions
- Stack topology → Kafka / NATS: provisions
- Ledger → PostgreSQL: persists records
- Payments → PostgreSQL: persists data
- Payments event definitions → Event schema generator: canonical input
- Ledger v2 event definitions → Event schema generator: canonical input
- Event schema generator → Generated event catalog: generates
- Ledger → Kafka / NATS: publishes events
- Payments → Kafka / NATS: publishes events
- Orchestration → Kafka / NATS: publishes events
- Generated event catalog → Ledger: compatibility contract
- Generated event catalog → Payments: compatibility contract
- Generated event catalog → Orchestration: compatibility contract
- Release API assembly → HTTP gateway: assembles published API
- Integration environment → Temporalite: includes
- Integration environment → Ledger: exercises
- Integration environment → Payments: exercises
- Integration environment → Orchestration: exercises
- Benchmark telemetry stack → OpenTelemetry collector: configures
- Ledger load environment → Ledger: loads
