# saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs architecture

> Architecture diagram of the GitHub repository saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs
- Repository: https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs

## Overview

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: [`app/event_store.py`](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/event_store.py) (Event and snapshot store), [`app/commands.py`](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py) (Deposit and withdraw), [`app/projections.py`](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py) (Projection processor), [`app/main.py`](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_api["FastAPI app<br/>[main.py]"]
end

subgraph group_commands["Command side"]
  node_command_routes["Command routes<br/>[commands.py]"]
  node_command_schemas["Command schemas<br/>[schemas.py]"]
  node_account_create["Create account<br/>[commands.py]"]
  node_money_commands["Deposit and withdraw<br/>[commands.py]"]
  node_account_close["Close account<br/>[commands.py]"]
  node_aggregate["Bank account aggregate<br/>[aggregates.py]"]
end

subgraph group_persistence["Persistence"]
  node_event_store["Event and snapshot store<br/>[event_store.py]"]
  node_event_records[("Event records<br/>[001_init.sql]")]
  node_snapshot_records[("Snapshot records<br/>[001_init.sql]")]
end

subgraph group_reads["Read side"]
  node_projection_processor["Projection processor<br/>[projections.py]"]
  node_summary_records[("Account summaries<br/>[001_init.sql]")]
  node_transaction_records[("Transaction history<br/>[001_init.sql]")]
  node_query_routes["Account queries<br/>[projections.py]"]
  node_audit_route["Event audit query<br/>[projections.py]"]
end

node_client(("Banking client"))

node_client -->|"sends requests"| node_api
node_api -->|"mounts commands"| node_command_routes
node_api -->|"mounts queries"| node_query_routes
node_command_routes -.->|"dispatches to"| node_account_create
node_command_routes -.->|"dispatches to"| node_money_commands
node_command_routes -.->|"dispatches to"| node_account_close
node_account_create -->|"accepts"| node_command_schemas
node_money_commands -->|"accepts"| node_command_schemas
node_account_create -->|"loads and appends"| node_event_store
node_money_commands -->|"loads and appends"| node_event_store
node_account_close -->|"loads and appends"| node_event_store
node_money_commands -->|"rebuilds state"| node_aggregate
node_account_close -->|"rebuilds state"| node_aggregate
node_account_create -->|"processes appended events"| node_projection_processor
node_money_commands -->|"processes appended events"| node_projection_processor
node_account_close -->|"processes appended events"| node_projection_processor
node_event_store -->|"reads and writes"| node_event_records
node_event_store -->|"reads and writes"| node_snapshot_records
node_account_create -->|"creates snapshots"| node_event_store
node_money_commands -->|"creates snapshots"| node_event_store
node_account_close -->|"creates snapshots"| node_event_store
node_projection_processor -->|"updates"| node_summary_records
node_projection_processor -->|"updates"| node_transaction_records
node_query_routes -->|"reads"| node_summary_records
node_query_routes -->|"reads"| node_transaction_records
node_audit_route -->|"reads events"| node_event_records

click node_api "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/main.py"
click node_command_routes "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py"
click node_command_schemas "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/schemas.py"
click node_account_create "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py"
click node_money_commands "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py"
click node_account_close "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py"
click node_aggregate "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/aggregates.py"
click node_event_store "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/event_store.py"
click node_event_records "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql"
click node_snapshot_records "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql"
click node_projection_processor "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py"
click node_summary_records "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql"
click node_transaction_records "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql"
click node_query_routes "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py"
click node_audit_route "https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.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_api,node_client toneBlue
class node_command_routes,node_command_schemas,node_account_create,node_money_commands,node_account_close,node_aggregate toneAmber
class node_event_store,node_event_records,node_snapshot_records toneMint
class node_projection_processor,node_summary_records,node_transaction_records,node_query_routes,node_audit_route toneRose
```

## Components

### API layer

- [FastAPI app](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/main.py): `app/main.py`

### Command side

- [Command routes](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py): `app/commands.py`
- [Command schemas](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/schemas.py): `app/schemas.py`
- [Create account](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py): `app/commands.py`
- [Deposit and withdraw](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py): `app/commands.py`
- [Close account](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/commands.py): `app/commands.py`
- [Bank account aggregate](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/aggregates.py): `app/aggregates.py`

### Persistence

- [Event and snapshot store](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/event_store.py): `app/event_store.py`
- [Event records](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql): `seeds/001_init.sql`
- [Snapshot records](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql): `seeds/001_init.sql`

### Read side

- [Projection processor](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py): `app/projections.py`
- [Account summaries](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql): `seeds/001_init.sql`
- [Transaction history](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/seeds/001_init.sql): `seeds/001_init.sql`
- [Account queries](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py): `app/projections.py`
- [Event audit query](https://github.com/saihemanth2006/bank-account-management-system-with-event-sourcing-and-cqrs/blob/main/app/projections.py): `app/projections.py`

### Other components

- **Banking client**

## Connections

- Banking client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Command routes: mounts commands (evidence: `app/main.py`)
- FastAPI app → Account queries: mounts queries (evidence: `app/main.py`)
- Command routes → Create account: dispatches to (evidence: `app/commands.py`)
- Command routes → Deposit and withdraw: dispatches to (evidence: `app/commands.py`)
- Command routes → Close account: dispatches to (evidence: `app/commands.py`)
- Create account → Command schemas: accepts (evidence: `app/commands.py`)
- Deposit and withdraw → Command schemas: accepts (evidence: `app/commands.py`)
- Create account → Event and snapshot store: loads and appends (evidence: `app/commands.py`)
- Deposit and withdraw → Event and snapshot store: loads and appends (evidence: `app/commands.py`)
- Close account → Event and snapshot store: loads and appends (evidence: `app/commands.py`)
- Deposit and withdraw → Bank account aggregate: rebuilds state (evidence: `app/commands.py`)
- Close account → Bank account aggregate: rebuilds state (evidence: `app/commands.py`)
- Create account → Projection processor: processes appended events (evidence: `app/commands.py`)
- Deposit and withdraw → Projection processor: processes appended events (evidence: `app/commands.py`)
- Close account → Projection processor: processes appended events (evidence: `app/commands.py`)
- Event and snapshot store → Event records: reads and writes (evidence: `app/event_store.py`)
- Event and snapshot store → Snapshot records: reads and writes (evidence: `app/event_store.py`)
- Create account → Event and snapshot store: creates snapshots (evidence: `app/commands.py`)
- Deposit and withdraw → Event and snapshot store: creates snapshots (evidence: `app/commands.py`)
- Close account → Event and snapshot store: creates snapshots (evidence: `app/commands.py`)
- Projection processor → Account summaries: updates (evidence: `app/projections.py`)
- Projection processor → Transaction history: updates (evidence: `app/projections.py`)
- Account queries → Account summaries: reads (evidence: `app/projections.py`)
- Account queries → Transaction history: reads (evidence: `app/projections.py`)
- Event audit query → Event records: reads events (evidence: `app/projections.py`)
