# kadapalanikith/secure-banking-transaction-engine architecture

> Architecture diagram of the GitHub repository kadapalanikith/secure-banking-transaction-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kadapalanikith/secure-banking-transaction-engine
- Repository: https://github.com/kadapalanikith/secure-banking-transaction-engine

## Overview

1. **Top-level runtime shape**
   - This is a **Node.js + Express.js** REST API backed by **MongoDB/Mongoose**.
   - The entry path is `server.js`, which loads environment config, connects to the database via `src/config/db.js`, and starts the HTTP server around the Express app in `src/app.js`.

2. **Request routing boundary**
   - `src/app.js` is the composition root for the API: it wires global middleware and mounts route modules.
   - Routes are split by domain:
     - `src/routes/auth.routes.js`
     - `src/routes/account.routes.js`
     - `src/routes/transaction.routes.js`
   - This creates a clean separation between HTTP concerns and business logic.

3. **Authentication subsystem**
   - `src/controllers/auth.controller.js` handles **register, login, logout**.
   - JWTs are the core auth mechanism, with password hashing handled by the `user.model`.
   - Logout is implemented by writing tokens to `blackList.model`, which implies token invalidation is stateful rather than purely stateless JWT auth.

4. **Authorization boundary**
   - `src/middleware/auth.middleware.js` protects authenticated routes and likely enforces:
     - valid JWT presence/verification
     - blacklist checks
     - special “system user” access for privileged operations
   - This middleware sits in front of account and transaction endpoints, acting as the security gate before controller logic runs.

5. **Account management subsystem**
   - `src/controllers/account.controller.js` exposes account creation, account listing, and balance lookup.
   - `src/models/account.model.js` is the durable account record; balance is likely derived from account state and/or ledger entries rather than only from client input.
   - Account endpoints are user-scoped, so the API boundary is “authenticated user ↔ their accounts.”

6. **Transaction processing subsystem**
   - `src/controllers/transaction.controller.js` is the core financial workflow.
   - It handles peer-to-peer transfers and the special system seeding endpoint (`/api/transactions/system/initial-funds`).
   - The README indicates transactions use **MongoDB sessions** for ACID-style atomicity, so transfer creation, balance updates, and ledger writes happen as one unit.

7. **Double-entry accounting boundary**
   - `src/models/ledger.model.js` and `src/models/transaction.model.js` form the accounting core.
   - Each transfer creates exactly **two ledger entries**: one debit and one credit.
   - The ledger is described as **immutable / append-only**, which is important for auditability and means historical entries are preserved instead of edited in place.

8. **Idempotency and duplicate protection**
   - Transaction requests accept an `idempotencyKey`, and the system prevents duplicate processing of the same request.
   - This is an important architectural boundary between client retries and financial side effects: repeated API calls should not double-spend funds or duplicate ledger entries.

9. **User and session state**
   - `src/models/user.model.js` stores user identity and credentials.
   - `src/models/blackList.model.js` stores revoked JWTs, likely with TTL expiry so stale logout records are cleaned automatically.
   - Together, these models provide the user/session state needed for secure API access without a separate session store.

10. **Email notification side channel**
   - `src/services/email.service.js` is an integration boundary to external email delivery via **Nodemailer** and Gmail OAuth2.
   - It is used for welcome emails and transaction alerts, so it is triggered from business workflows rather than from the transport layer.

11. **Configuration and shared constants**
   - `src/config/db.js` centralizes MongoDB connectivity.
   - `src/utils/constants.js` holds app-wide values that keep controllers/models aligned on shared statuses or roles.
   - Environment variables in `.env` drive runtime behavior such as port, Mongo URI, JWT secret, and Gmail OAuth credentials.

12. **Observability and operational endpoint**
   - The API includes a public **health check** endpoint (`/api/health`) for uptime monitoring.
   - The presence of a health route plus explicit DB connection setup indicates the service expects infrastructure-level monitoring and deployment readiness checks.

13. **How the main data flows fit together**
   - **Auth flow:** client → auth route → auth controller → user model / blacklist model.
   - **Account flow:** client → auth middleware → account controller → account model.
   - **Transfer flow:** client → auth middleware → transaction controller → MongoDB session → transaction model + ledger model + account model → email service.
   - The transaction flow is the most coupled and is the system’s primary consistency boundary.

14. **Diagrammatic takeaways**
   - The repository is organized around three major domains: **identity**, **accounts**, and **transactions**.
   - The critical trust boundaries are:
     - public API vs authenticated API
     - authenticated user vs system user
     - request layer vs transactional persistence layer
     - mutable operational records vs immutable ledger history

Main entry points: [`src/controllers/transaction.controller.js`](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/transaction.controller.js) (Txn Controller), [`src/app.js`](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/app.js) (Express App), [`src/middleware/auth.middleware.js`](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/middleware/auth.middleware.js) (Auth Guard), [`src/controllers/auth.controller.js`](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/auth.controller.js) (Auth Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server["Server<br/>entrypoint<br/>[server.js]"]
  node_db[("Mongo DB<br/>connector<br/>[db.js]")]
  node_constants["Constants<br/>shared config<br/>[constants.js]"]
end

subgraph group_http["HTTP API"]
  node_app["Express App<br/>composition root<br/>[app.js]"]
end

subgraph group_identity["Identity"]
  node_authmw["Auth Guard<br/>middleware<br/>[auth.middleware.js]"]
  node_authroutes["Auth Routes<br/>route module<br/>[auth.routes.js]"]
  node_authctl["Auth Controller<br/>[auth.controller.js]"]
  node_user[("User Model<br/>mongoose model<br/>[user.model.js]")]
  node_blacklist[("Token Blacklist<br/>revocation store<br/>[blackList.model.js]")]
end

subgraph group_accounts["Accounts"]
  node_accountroutes["Account Routes<br/>route module<br/>[account.routes.js]"]
  node_acctctl["Account Controller"]
  node_account[("Account Model<br/>mongoose model<br/>[account.model.js]")]
end

subgraph group_transactions["Transactions"]
  node_txroutes["Txn Routes<br/>route module"]
  node_txctl["Txn Controller"]
  node_txmodel[("Transaction Model<br/>mongoose model")]
  node_ledger[("Ledger Model<br/>append-only ledger<br/>[ledger.model.js]")]
end

subgraph group_integrations["Integrations"]
  node_email["Email Service<br/>integration<br/>[email.service.js]"]
end

node_server -->|"starts"| node_app
node_server -->|"connects"| node_db
node_app -->|"mounts"| node_authroutes
node_app -->|"mounts"| node_accountroutes
node_app -->|"mounts"| node_txroutes
node_accountroutes -->|"protects"| node_authmw
node_txroutes -->|"protects"| node_authmw
node_authroutes -->|"delegates"| node_authctl
node_authctl -->|"reads/writes"| node_user
node_authctl -->|"revokes"| node_blacklist
node_accountroutes -->|"delegates"| node_acctctl
node_acctctl -->|"reads/writes"| node_account
node_txroutes -->|"delegates"| node_txctl
node_txctl -->|"records"| node_txmodel
node_txctl -->|"appends"| node_ledger
node_txctl -->|"updates"| node_account
node_txctl -->|"notifies"| node_email
node_authmw -->|"checks"| node_blacklist
node_authmw -->|"verifies"| node_user
node_txctl -->|"uses session"| node_db
node_app -->|"uses"| node_constants

click node_server "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/server.js"
click node_app "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/app.js"
click node_db "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/config/db.js"
click node_authmw "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/middleware/auth.middleware.js"
click node_authroutes "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/auth.routes.js"
click node_accountroutes "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/account.routes.js"
click node_txroutes "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/transaction.routes.js"
click node_authctl "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/auth.controller.js"
click node_user "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/user.model.js"
click node_blacklist "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/blackList.model.js"
click node_acctctl "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/account.controller.js"
click node_account "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/account.model.js"
click node_txctl "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/transaction.controller.js"
click node_txmodel "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/transaction.model.js"
click node_ledger "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/ledger.model.js"
click node_constants "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/utils/constants.js"
click node_email "https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/services/email.service.js"

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_server,node_db,node_constants toneBlue
class node_app toneAmber
class node_authmw,node_authroutes,node_authctl,node_user,node_blacklist toneMint
class node_accountroutes,node_acctctl,node_account toneRose
class node_txroutes,node_txctl,node_txmodel,node_ledger toneIndigo
class node_email toneTeal
```

## Components

### Runtime

Process startup, app composition, and configuration

- [Server](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/server.js): entrypoint · Starts the application, loads config, connects the database, and launches the HTTP server · `server.js`
- [Mongo DB](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/config/db.js): connector · MongoDB connection bootstrap used by the runtime · `src/config/db.js`
- [Constants](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/utils/constants.js): shared config · Shared application values used across the codebase · `src/utils/constants.js`

### HTTP API

Routing, middleware, and request entrypoints

- [Express App](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/app.js): composition root · Wires middleware and mounts API routes · `src/app.js`

### Identity

Authentication, users, and token revocation

- [Auth Guard](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/middleware/auth.middleware.js): middleware · Protects authenticated routes and enforces access checks · `src/middleware/auth.middleware.js`
- [Auth Routes](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/auth.routes.js): route module · HTTP routes for register, login, and logout · `src/routes/auth.routes.js`
- [Auth Controller](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/auth.controller.js): controller · Handles registration, login, and logout workflows · `src/controllers/auth.controller.js`
- [User Model](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/user.model.js): mongoose model · Stores user identity and credentials · `src/models/user.model.js`
- [Token Blacklist](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/blackList.model.js): revocation store · Persists revoked JWTs for logout and invalidation · `src/models/blackList.model.js`

### Accounts

Account creation and balance access

- [Account Routes](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/account.routes.js): route module · HTTP routes for account operations · `src/routes/account.routes.js`
- [Account Controller](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/account.controller.js): controller · Creates accounts and exposes account balance lookup · `src/controllers/account.controller.js`
- [Account Model](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/account.model.js): mongoose model · Durable account record and balance source · `src/models/account.model.js`

### Transactions

Transfers, ledgering, and idempotent financial workflows

- [Txn Routes](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/routes/transaction.routes.js): route module · HTTP routes for transfers and system funding · `src/routes/transaction.routes.js`
- [Txn Controller](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/controllers/transaction.controller.js): controller · Runs transfers and system initial-funds workflows · `src/controllers/transaction.controller.js`
- [Transaction Model](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/transaction.model.js): mongoose model · Stores transfer records and duplicate-protection state · `src/models/transaction.model.js`
- [Ledger Model](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/models/ledger.model.js): append-only ledger · Immutable debit and credit entries for audit history · `src/models/ledger.model.js`

### Integrations

External notification delivery

- [Email Service](https://github.com/kadapalanikith/secure-banking-transaction-engine/blob/main/src/services/email.service.js): integration · Sends welcome and transaction alert emails via Nodemailer and Gmail OAuth2 · `src/services/email.service.js`

## Connections

- Server → Express App: starts · Bootstraps the Express application after loading runtime config
- Server → Mongo DB: connects · Initializes MongoDB before serving requests
- Express App → Auth Routes: mounts · Registers auth endpoints under the API
- Express App → Account Routes: mounts · Registers account endpoints under the API
- Express App → Txn Routes: mounts · Registers transaction endpoints under the API
- Account Routes → Auth Guard: protects · Requires authentication before account handlers run
- Txn Routes → Auth Guard: protects · Requires authentication before transaction handlers run
- Auth Routes → Auth Controller: delegates · Routes auth requests into controller workflows
- Auth Controller → User Model: reads/writes · Creates users and verifies credentials
- Auth Controller → Token Blacklist: revokes · Stores logout tokens for later rejection
- Account Routes → Account Controller: delegates · Routes account requests into controller workflows
- Account Controller → Account Model: reads/writes · Creates accounts and fetches balances
- Txn Routes → Txn Controller: delegates · Routes transfer and funding requests into controller workflows
- Txn Controller → Transaction Model: records · Persists transaction state and idempotency protection
- Txn Controller → Ledger Model: appends · Writes immutable debit and credit entries
- Txn Controller → Account Model: updates · Adjusts account balances during transfers
- Txn Controller → Email Service: notifies · Sends welcome and transaction alerts as a side effect
- Auth Guard → Token Blacklist: checks · Rejects revoked tokens during authentication
- Auth Guard → User Model: verifies · Confirms JWT subject and privileged access context
- Txn Controller → Mongo DB: uses session · Runs transfer work inside MongoDB sessions for atomicity
- Express App → Constants: uses · Shares common app-wide values across handlers
