How saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs works
This is a FastAPI bank-account backend using event sourcing and CQRS. Clients submit account-creation, deposit, withdrawal, and close commands; handlers validate state with the BankAccount aggregate, append events, synchronously update read models, and create snapshots every 50 events. Query routes expose account summaries, transaction history, and an event audit. The graph separates command handling, event persistence, projections, and query views. Relationships are based on the excerpts and README; database table names are documented in the README and SQL queries, but the seed SQL contents were not excerpted.
Main entry points: event_store.py Event and snapshot store · commands.py Deposit and withdraw · projections.py Projection processor · main.py FastAPI app
Components 16
API layer
- FastAPI app
app/main.py
Command side
- Command routes
app/commands.py - Command schemas
app/schemas.py - Create account
app/commands.py - Deposit and withdraw
app/commands.py - Close account
app/commands.py - Bank account aggregate
app/aggregates.py
Persistence
- Event and snapshot store
app/event_store.py - Event records
seeds/001_init.sql - Snapshot records
seeds/001_init.sql
Read side
- Projection processor
app/projections.py - Account summaries
seeds/001_init.sql - Transaction history
seeds/001_init.sql - Account queries
app/projections.py - Event audit query
app/projections.py
Other components
- Banking client
Connections 26
- Banking client → FastAPI app: sends requests
README.md - FastAPI app → Command routes: mounts commands
app/main.py - FastAPI app → Account queries: mounts queries
app/main.py - Command routes → Create account: dispatches to
app/commands.py - Command routes → Deposit and withdraw: dispatches to
app/commands.py - Command routes → Close account: dispatches to
app/commands.py - Create account → Command schemas: accepts
app/commands.py - Deposit and withdraw → Command schemas: accepts
app/commands.py - Create account → Event and snapshot store: loads and appends
app/commands.py - Deposit and withdraw → Event and snapshot store: loads and appends
app/commands.py - Close account → Event and snapshot store: loads and appends
app/commands.py - Deposit and withdraw → Bank account aggregate: rebuilds state
app/commands.py - Close account → Bank account aggregate: rebuilds state
app/commands.py - Create account → Projection processor: processes appended events
app/commands.py - Deposit and withdraw → Projection processor: processes appended events
app/commands.py - Close account → Projection processor: processes appended events
app/commands.py - Event and snapshot store → Event records: reads and writes
app/event_store.py - Event and snapshot store → Snapshot records: reads and writes
app/event_store.py - Create account → Event and snapshot store: creates snapshots
app/commands.py - Deposit and withdraw → Event and snapshot store: creates snapshots
app/commands.py - Close account → Event and snapshot store: creates snapshots
app/commands.py - Projection processor → Account summaries: updates
app/projections.py - Projection processor → Transaction history: updates
app/projections.py - Account queries → Account summaries: reads
app/projections.py - Account queries → Transaction history: reads
app/projections.py - Event audit query → Event records: reads events
app/projections.py