# risvey-hasan/banking_api architecture

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

- Interactive diagram: https://gitdiagram.com/risvey-hasan/banking_api
- Repository: https://github.com/risvey-hasan/banking_api

## Overview

This is a reliability-focused financial transaction service. Customers and administrators use its HTTP API to sign up or authenticate, inspect accounts and transactions, submit transfers or reversals, and receive accepted work for asynchronous processing. PostgreSQL holds account, session, and transaction state; Redis supports the work queue. Workers apply accepted transactions, while a sweeper supports recovery and redispatch. The excerpts show API routing and several dependency calls; links for unsampled worker and recovery internals are limited to documented behavior or omitted where not established.

Main entry points: [`app/db.py`](https://github.com/risvey-hasan/banking_api/blob/main/app/db.py) (Database pool), [`app/main.py`](https://github.com/risvey-hasan/banking_api/blob/main/app/main.py) (HTTP API), [`app/redis_client.py`](https://github.com/risvey-hasan/banking_api/blob/main/app/redis_client.py) (Redis client), [`app/api/auth.py`](https://github.com/risvey-hasan/banking_api/blob/main/app/api/auth.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_api_app["HTTP API<br/>[main.py]"]
  node_auth_routes["Auth routes<br/>[auth.py]"]
  node_identity["Identity and sessions<br/>[auth.py]"]
  node_security["Credential security<br/>[security.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_ledger["Accounts and ledger"]
  node_accounts["Account operations<br/>[accounts.py]"]
  node_account_numbers["Account numbers<br/>[account_number.py]"]
  node_transactions["Transaction routes<br/>[transactions.py]"]
  node_transfers["Transfer routes<br/>[transfers.py]"]
  node_sql["SQL projections<br/>[sql.py]"]
end

subgraph group_processing["Async processing"]
  node_worker["Queue worker<br/>[main.py]"]
  node_apply["Transaction applier<br/>[apply.py]"]
  node_sweeper["Recovery sweeper<br/>[sweeper.py]"]
  node_queue["Queue interface<br/>[queue.py]"]
end

subgraph group_infra["Runtime infrastructure"]
  node_postgres[("PostgreSQL")]
  node_redis[("Redis")]
  node_db_layer["Database pool<br/>[db.py]"]
  node_redis_client["Redis client<br/>[redis_client.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_metrics["Health and metrics<br/>[metrics.py]"]
end

node_customer(("Customer"))
node_admin(("Administrator"))

node_customer -->|"submits requests"| node_api_app
node_admin -->|"uses API"| node_api_app
node_api_app -->|"registers routes"| node_auth_routes
node_api_app -->|"registers routes"| node_accounts
node_api_app -->|"registers routes"| node_transactions
node_api_app -->|"registers routes"| node_transfers
node_auth_routes -->|"creates sessions"| node_identity
node_auth_routes -->|"hashes passwords"| node_security
node_auth_routes -->|"opens account"| node_accounts
node_auth_routes -->|"queries database"| node_db_layer
node_identity -->|"verifies credentials"| node_security
node_identity -->|"resolves sessions"| node_db_layer
node_accounts -->|"generates numbers"| node_account_numbers
node_accounts -->|"reads and writes"| node_db_layer
node_transactions -->|"checks ownership"| node_accounts
node_transactions -->|"accepts transactions"| node_db_layer
node_transactions -->|"nudges worker"| node_queue
node_transfers -->|"resolves recipient"| node_account_numbers
node_transfers -->|"records transfer"| node_db_layer
node_transfers -->|"nudges worker"| node_queue
node_worker -->|"invokes applier"| node_apply
node_worker -->|"consumes queue"| node_redis_client
node_worker -->|"uses database"| node_db_layer
node_apply -.->|"applies ledger work"| node_postgres
node_queue -->|"publishes nudges"| node_redis_client
node_db_layer -->|"connects to"| node_postgres
node_redis_client -->|"connects to"| node_redis
node_db_layer -->|"loads settings"| node_config
node_redis_client -->|"loads settings"| node_config
node_api_app -->|"starts pool"| node_db_layer
node_api_app -->|"starts client"| node_redis_client
node_api_app -->|"serves metrics"| node_metrics
node_metrics -->|"probes database"| node_db_layer
node_metrics -->|"probes Redis"| node_redis_client
node_sweeper -->|"scans pending work"| node_db_layer
node_sweeper -.->|"redispatches work"| node_redis_client

click node_api_app "https://github.com/risvey-hasan/banking_api/blob/main/app/main.py"
click node_auth_routes "https://github.com/risvey-hasan/banking_api/blob/main/app/api/auth.py"
click node_identity "https://github.com/risvey-hasan/banking_api/blob/main/app/auth.py"
click node_security "https://github.com/risvey-hasan/banking_api/blob/main/app/security.py"
click node_schemas "https://github.com/risvey-hasan/banking_api/blob/main/app/schemas.py"
click node_accounts "https://github.com/risvey-hasan/banking_api/blob/main/app/api/accounts.py"
click node_account_numbers "https://github.com/risvey-hasan/banking_api/blob/main/app/account_number.py"
click node_transactions "https://github.com/risvey-hasan/banking_api/blob/main/app/api/transactions.py"
click node_transfers "https://github.com/risvey-hasan/banking_api/blob/main/app/api/transfers.py"
click node_sql "https://github.com/risvey-hasan/banking_api/blob/main/app/sql.py"
click node_worker "https://github.com/risvey-hasan/banking_api/blob/main/app/worker/main.py"
click node_apply "https://github.com/risvey-hasan/banking_api/blob/main/app/worker/apply.py"
click node_sweeper "https://github.com/risvey-hasan/banking_api/blob/main/app/sweeper.py"
click node_queue "https://github.com/risvey-hasan/banking_api/blob/main/app/queue.py"
click node_db_layer "https://github.com/risvey-hasan/banking_api/blob/main/app/db.py"
click node_redis_client "https://github.com/risvey-hasan/banking_api/blob/main/app/redis_client.py"
click node_config "https://github.com/risvey-hasan/banking_api/blob/main/app/config.py"
click node_metrics "https://github.com/risvey-hasan/banking_api/blob/main/app/metrics.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_app,node_auth_routes,node_identity,node_security,node_schemas toneBlue
class node_accounts,node_account_numbers,node_transactions,node_transfers,node_sql toneAmber
class node_worker,node_apply,node_sweeper,node_queue toneMint
class node_postgres,node_redis,node_db_layer,node_redis_client,node_config,node_metrics toneRose
class node_customer,node_admin toneIndigo
```

## Components

### API and identity

- [HTTP API](https://github.com/risvey-hasan/banking_api/blob/main/app/main.py): `app/main.py`
- [Auth routes](https://github.com/risvey-hasan/banking_api/blob/main/app/api/auth.py): `app/api/auth.py`
- [Identity and sessions](https://github.com/risvey-hasan/banking_api/blob/main/app/auth.py): `app/auth.py`
- [Credential security](https://github.com/risvey-hasan/banking_api/blob/main/app/security.py): `app/security.py`
- [API schemas](https://github.com/risvey-hasan/banking_api/blob/main/app/schemas.py): `app/schemas.py`

### Accounts and ledger

- [Account operations](https://github.com/risvey-hasan/banking_api/blob/main/app/api/accounts.py): `app/api/accounts.py`
- [Account numbers](https://github.com/risvey-hasan/banking_api/blob/main/app/account_number.py): `app/account_number.py`
- [Transaction routes](https://github.com/risvey-hasan/banking_api/blob/main/app/api/transactions.py): `app/api/transactions.py`
- [Transfer routes](https://github.com/risvey-hasan/banking_api/blob/main/app/api/transfers.py): `app/api/transfers.py`
- [SQL projections](https://github.com/risvey-hasan/banking_api/blob/main/app/sql.py): `app/sql.py`

### Async processing

- [Queue worker](https://github.com/risvey-hasan/banking_api/blob/main/app/worker/main.py): `app/worker/main.py`
- [Transaction applier](https://github.com/risvey-hasan/banking_api/blob/main/app/worker/apply.py): `app/worker/apply.py`
- [Recovery sweeper](https://github.com/risvey-hasan/banking_api/blob/main/app/sweeper.py): `app/sweeper.py`
- [Queue interface](https://github.com/risvey-hasan/banking_api/blob/main/app/queue.py): `app/queue.py`

### Runtime infrastructure

- **PostgreSQL**
- **Redis**
- [Database pool](https://github.com/risvey-hasan/banking_api/blob/main/app/db.py): `app/db.py`
- [Redis client](https://github.com/risvey-hasan/banking_api/blob/main/app/redis_client.py): `app/redis_client.py`
- [Configuration](https://github.com/risvey-hasan/banking_api/blob/main/app/config.py): `app/config.py`
- [Health and metrics](https://github.com/risvey-hasan/banking_api/blob/main/app/metrics.py): `app/metrics.py`

### Other components

- **Customer**
- **Administrator**

## Connections

- Customer → HTTP API: submits requests (evidence: `README.md`)
- Administrator → HTTP API: uses API (evidence: `README.md`)
- HTTP API → Auth routes: registers routes (evidence: `app/main.py`)
- HTTP API → Account operations: registers routes (evidence: `app/main.py`)
- HTTP API → Transaction routes: registers routes (evidence: `app/main.py`)
- HTTP API → Transfer routes: registers routes (evidence: `app/main.py`)
- Auth routes → Identity and sessions: creates sessions (evidence: `app/api/auth.py`)
- Auth routes → Credential security: hashes passwords (evidence: `app/api/auth.py`)
- Auth routes → Account operations: opens account (evidence: `app/api/auth.py`)
- Auth routes → Database pool: queries database (evidence: `app/api/auth.py`)
- Identity and sessions → Credential security: verifies credentials (evidence: `app/auth.py`)
- Identity and sessions → Database pool: resolves sessions (evidence: `app/auth.py`)
- Account operations → Account numbers: generates numbers (evidence: `app/api/accounts.py`)
- Account operations → Database pool: reads and writes (evidence: `app/api/accounts.py`)
- Transaction routes → Account operations: checks ownership (evidence: `app/api/transactions.py`)
- Transaction routes → Database pool: accepts transactions (evidence: `app/api/transactions.py`)
- Transaction routes → Queue interface: nudges worker (evidence: `app/api/transactions.py`)
- Transfer routes → Account numbers: resolves recipient (evidence: `app/api/transfers.py`)
- Transfer routes → Database pool: records transfer (evidence: `app/api/transfers.py`)
- Transfer routes → Queue interface: nudges worker (evidence: `app/api/transfers.py`)
- Queue worker → Transaction applier: invokes applier (evidence: `app/worker/main.py`)
- Queue worker → Redis client: consumes queue (evidence: `app/worker/main.py`)
- Queue worker → Database pool: uses database (evidence: `app/worker/main.py`)
- Transaction applier → PostgreSQL: applies ledger work (evidence: `README.md`)
- Queue interface → Redis client: publishes nudges (evidence: `app/queue.py`)
- Database pool → PostgreSQL: connects to (evidence: `app/db.py`)
- Redis client → Redis: connects to (evidence: `app/redis_client.py`)
- Database pool → Configuration: loads settings (evidence: `app/db.py`)
- Redis client → Configuration: loads settings (evidence: `app/redis_client.py`)
- HTTP API → Database pool: starts pool (evidence: `app/main.py`)
- HTTP API → Redis client: starts client (evidence: `app/main.py`)
- HTTP API → Health and metrics: serves metrics (evidence: `app/main.py`)
- Health and metrics → Database pool: probes database (evidence: `app/metrics.py`)
- Health and metrics → Redis client: probes Redis (evidence: `app/metrics.py`)
- Recovery sweeper → Database pool: scans pending work (evidence: `app/sweeper.py`)
- Recovery sweeper → Redis client: redispatches work (evidence: `app/sweeper.py`)
