# varunsahu258/ledgerpay architecture

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

- Interactive diagram: https://gitdiagram.com/varunsahu258/ledgerpay
- Repository: https://github.com/varunsahu258/ledgerpay

## Overview

LedgerPay is a money-transfer API whose main workflow accepts validated account or transfer requests, delegates business operations to services, and persists state in PostgreSQL. Transfers and reversals use idempotency, ordered balance locking, ledger postings, and audit records; account history and reconciliation provide inspection and drift detection. The browser console is served by the API, while a demo seeder exercises the public HTTP endpoints. Some subsystem links are based on README documentation or the SOURCE INDEX because their implementations were not excerpted.

Main entry points: [`app/main.py`](https://github.com/varunsahu258/ledgerpay/blob/main/app/main.py) (FastAPI app), [`app/api/routes.py`](https://github.com/varunsahu258/ledgerpay/blob/main/app/api/routes.py) (HTTP routes), [`app/models/entities.py`](https://github.com/varunsahu258/ledgerpay/blob/main/app/models/entities.py) (Ledger entities), [`app/services/transfers.py`](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/transfers.py) (Transfer service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and clients"]
  node_browser["Browser console<br/>[app.js]"]
  node_main["FastAPI app<br/>[main.py]"]
  node_routes["HTTP routes<br/>[routes.py]"]
  node_account_schema["Account schemas<br/>[account.py]"]
  node_transfer_schema["Transfer schemas<br/>[transfer.py]"]
end

subgraph group_operations["Money operations"]
  node_account_service["Account service<br/>[accounts.py]"]
  node_transfer_service["Transfer service<br/>[transfers.py]"]
  node_reversal_service["Reversal service<br/>[reversals.py]"]
  node_history_service["History service<br/>[transactions.py]"]
  node_reconciliation["Reconciliation<br/>[reconciliation.py]"]
  node_balance_locking["Balance locking<br/>[balance_locking.py]"]
  node_reconcile_cli["Reconciliation CLI<br/>[reconcile.py]"]
end

subgraph group_storage["Persistence and invariants"]
  node_db_session["Async DB sessions<br/>[db.py]"]
  node_entities["Ledger entities<br/>[entities.py]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_demo["Demo and safety"]
  node_config["Settings<br/>[config.py]"]
  node_demo_safety["Demo safeguards<br/>[demo_safety.py]"]
  node_demo_seed["Demo seeder<br/>[demo.py]"]
end

node_client(("API client"))

node_client -->|"HTTP requests"| node_main
node_browser -->|"HTTP requests"| node_main
node_main -->|"registers routes"| node_routes
node_main -->|"limits writes"| node_demo_safety
node_main -->|"health check"| node_db_session
node_main -->|"serves console"| node_browser
node_routes -->|"calls"| node_account_service
node_routes -->|"calls"| node_transfer_service
node_routes -->|"calls"| node_reversal_service
node_routes -->|"calls"| node_history_service
node_routes -->|"validates and returns"| node_account_schema
node_routes -->|"validates and returns"| node_transfer_schema
node_routes -->|"gets session"| node_db_session
node_account_service -->|"queries and writes"| node_entities
node_transfer_service -->|"writes transfer ledger"| node_entities
node_transfer_service -->|"locks balances"| node_balance_locking
node_reversal_service -->|"writes reversal ledger"| node_entities
node_reversal_service -->|"locks balances"| node_balance_locking
node_history_service -->|"reads history"| node_entities
node_reconciliation -->|"checks balances"| node_entities
node_reconcile_cli -->|"runs checks"| node_reconciliation
node_db_session -->|"connects"| node_postgres
node_transfer_service -->|"persists transaction"| node_postgres
node_reversal_service -->|"persists reversal"| node_postgres
node_config -->|"configures engine"| node_db_session
node_main -->|"reads settings"| node_config
node_main -->|"configures demo limits"| node_config
node_demo_seed -->|"calls public API"| node_main
node_demo_seed -->|"funds demo accounts"| node_postgres
node_demo_seed -->|"reads settings"| node_config

click node_browser "https://github.com/varunsahu258/ledgerpay/blob/main/app/static/console/app.js"
click node_main "https://github.com/varunsahu258/ledgerpay/blob/main/app/main.py"
click node_routes "https://github.com/varunsahu258/ledgerpay/blob/main/app/api/routes.py"
click node_account_schema "https://github.com/varunsahu258/ledgerpay/blob/main/app/schemas/account.py"
click node_transfer_schema "https://github.com/varunsahu258/ledgerpay/blob/main/app/schemas/transfer.py"
click node_account_service "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/accounts.py"
click node_transfer_service "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/transfers.py"
click node_reversal_service "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/reversals.py"
click node_history_service "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/transactions.py"
click node_reconciliation "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/reconciliation.py"
click node_balance_locking "https://github.com/varunsahu258/ledgerpay/blob/main/app/services/balance_locking.py"
click node_reconcile_cli "https://github.com/varunsahu258/ledgerpay/blob/main/app/reconcile.py"
click node_db_session "https://github.com/varunsahu258/ledgerpay/blob/main/app/db.py"
click node_entities "https://github.com/varunsahu258/ledgerpay/blob/main/app/models/entities.py"
click node_config "https://github.com/varunsahu258/ledgerpay/blob/main/app/core/config.py"
click node_demo_safety "https://github.com/varunsahu258/ledgerpay/blob/main/app/core/demo_safety.py"
click node_demo_seed "https://github.com/varunsahu258/ledgerpay/blob/main/app/demo.py"

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_browser,node_main,node_routes,node_account_schema,node_transfer_schema,node_client toneBlue
class node_account_service,node_transfer_service,node_reversal_service,node_history_service,node_reconciliation,node_balance_locking,node_reconcile_cli toneAmber
class node_db_session,node_entities,node_postgres toneMint
class node_config,node_demo_safety,node_demo_seed toneRose
```

## Components

### API and clients

- [Browser console](https://github.com/varunsahu258/ledgerpay/blob/main/app/static/console/app.js): `app/static/console/app.js`
- [FastAPI app](https://github.com/varunsahu258/ledgerpay/blob/main/app/main.py): `app/main.py`
- [HTTP routes](https://github.com/varunsahu258/ledgerpay/blob/main/app/api/routes.py): `app/api/routes.py`
- [Account schemas](https://github.com/varunsahu258/ledgerpay/blob/main/app/schemas/account.py): `app/schemas/account.py`
- [Transfer schemas](https://github.com/varunsahu258/ledgerpay/blob/main/app/schemas/transfer.py): `app/schemas/transfer.py`

### Money operations

- [Account service](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/accounts.py): `app/services/accounts.py`
- [Transfer service](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/transfers.py): `app/services/transfers.py`
- [Reversal service](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/reversals.py): `app/services/reversals.py`
- [History service](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/transactions.py): `app/services/transactions.py`
- [Reconciliation](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/reconciliation.py): `app/services/reconciliation.py`
- [Balance locking](https://github.com/varunsahu258/ledgerpay/blob/main/app/services/balance_locking.py): `app/services/balance_locking.py`
- [Reconciliation CLI](https://github.com/varunsahu258/ledgerpay/blob/main/app/reconcile.py): `app/reconcile.py`

### Persistence and invariants

- [Async DB sessions](https://github.com/varunsahu258/ledgerpay/blob/main/app/db.py): `app/db.py`
- [Ledger entities](https://github.com/varunsahu258/ledgerpay/blob/main/app/models/entities.py): `app/models/entities.py`
- **PostgreSQL**

### Demo and safety

- [Settings](https://github.com/varunsahu258/ledgerpay/blob/main/app/core/config.py): `app/core/config.py`
- [Demo safeguards](https://github.com/varunsahu258/ledgerpay/blob/main/app/core/demo_safety.py): `app/core/demo_safety.py`
- [Demo seeder](https://github.com/varunsahu258/ledgerpay/blob/main/app/demo.py): `app/demo.py`

### Other components

- **API client**

## Connections

- API client → FastAPI app: HTTP requests (evidence: `README.md`)
- Browser console → FastAPI app: HTTP requests (evidence: `README.md`)
- FastAPI app → HTTP routes: registers routes (evidence: `app/main.py`)
- FastAPI app → Demo safeguards: limits writes (evidence: `app/main.py`)
- FastAPI app → Async DB sessions: health check (evidence: `app/main.py`)
- FastAPI app → Browser console: serves console (evidence: `app/main.py`)
- HTTP routes → Account service: calls (evidence: `app/api/routes.py`)
- HTTP routes → Transfer service: calls (evidence: `app/api/routes.py`)
- HTTP routes → Reversal service: calls (evidence: `app/api/routes.py`)
- HTTP routes → History service: calls (evidence: `app/api/routes.py`)
- HTTP routes → Account schemas: validates and returns (evidence: `app/api/routes.py`)
- HTTP routes → Transfer schemas: validates and returns (evidence: `app/api/routes.py`)
- HTTP routes → Async DB sessions: gets session (evidence: `app/api/routes.py`)
- Account service → Ledger entities: queries and writes (evidence: `app/services/accounts.py`)
- Transfer service → Ledger entities: writes transfer ledger (evidence: `app/services/transfers.py`)
- Transfer service → Balance locking: locks balances (evidence: `app/services/transfers.py`)
- Reversal service → Ledger entities: writes reversal ledger (evidence: `app/services/reversals.py`)
- Reversal service → Balance locking: locks balances (evidence: `app/services/reversals.py`)
- History service → Ledger entities: reads history (evidence: `app/services/transactions.py`)
- Reconciliation → Ledger entities: checks balances (evidence: `app/services/reconciliation.py`)
- Reconciliation CLI → Reconciliation: runs checks (evidence: `app/reconcile.py`)
- Async DB sessions → PostgreSQL: connects (evidence: `app/db.py`)
- Transfer service → PostgreSQL: persists transaction (evidence: `app/services/transfers.py`)
- Reversal service → PostgreSQL: persists reversal (evidence: `app/services/reversals.py`)
- Settings → Async DB sessions: configures engine (evidence: `app/db.py`)
- FastAPI app → Settings: reads settings (evidence: `app/main.py`)
- FastAPI app → Settings: configures demo limits (evidence: `app/main.py`)
- Demo seeder → FastAPI app: calls public API (evidence: `app/demo.py`)
- Demo seeder → PostgreSQL: funds demo accounts (evidence: `app/demo.py`)
- Demo seeder → Settings: reads settings (evidence: `app/demo.py`)
