How aryan-sagar/idempotent-payments-ledger-reconciliation-backend works
Payments Ledger is a FastAPI service for creating, capturing, settling, refunding, and inspecting payments backed by a double-entry ledger. A client submits a payment with an idempotency key; the API checks Redis and PostgreSQL for replay or in-progress work, then ledger logic advances transaction state and posts balanced entries. Settlement and refunds create further entries rather than editing history. A separate reconciliation command checks ledger totals, cached account balances, and duplicate owners. The map follows the README and sampled runtime source; unsampled details are represented only where documented.
Main entry points: routes_payments.py Payment Routes · reconciliation.py Ledger Reconciliation · idempotency.py Idempotency Checks · ledger.py Payment State And Posting
Components 13
Payment API
- FastAPI App
app/main.py - Payment Routes
app/routes_payments.py - Request And Response Schemas
app/schemas.py
Request Reliability
- Idempotency Checks
app/idempotency.py - Redis Client
app/redis_client.py
Payment Ledger
- Payment State And Posting
app/ledger.py
Persistence And Audit
- Ledger Data Models
app/models.py - Database Sessions
app/database.py - Ledger Reconciliation
app/reconciliation.py
Other components
- Payment Client
- Redis
- PostgreSQL
- Reconciliation Operator
Connections 16
- Payment Client → FastAPI App: sends requests
- FastAPI App → Payment Routes: dispatches routes
- Payment Routes → Request And Response Schemas: validates and shapes
- Payment Routes → Idempotency Checks: checks and stores replay
- Idempotency Checks → Redis Client: uses cache and locks
- Redis Client → Redis: reads and writes
- Payment Routes → Payment State And Posting: invokes payment operations
- Payment Routes → Database Sessions: gets request session
- Database Sessions → PostgreSQL: connects sessions
- Idempotency Checks → PostgreSQL: reads and writes records
- Payment State And Posting → Ledger Data Models: queries and updates
- Payment State And Posting → PostgreSQL: persists state and entries
- Reconciliation Operator → Ledger Reconciliation: runs audit
- Ledger Reconciliation → Database Sessions: opens session
- Ledger Reconciliation → Ledger Data Models: checks ledger data
- Ledger Reconciliation → PostgreSQL: reads balances and entries