How kadapalanikith/secure-banking-transaction-engine works
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: transaction.controller.js Txn Controller · app.js Express App · auth.middleware.js Auth Guard · auth.controller.js Auth Controller
Components 17
Runtime
Process startup, app composition, and configuration
HTTP API
Routing, middleware, and request entrypoints
- Express App · Wires middleware and mounts API routes
src/app.js
Identity
Authentication, users, and token revocation
- Auth Guard · Protects authenticated routes and enforces access checks
src/middleware/auth.middleware.js - Auth Routes · HTTP routes for register, login, and logout
src/routes/auth.routes.js - Auth Controller · Handles registration, login, and logout workflows
src/controllers/auth.controller.js - User Model · Stores user identity and credentials
src/models/user.model.js - Token Blacklist · Persists revoked JWTs for logout and invalidation
src/models/blackList.model.js
Accounts
Account creation and balance access
- Account Routes · HTTP routes for account operations
src/routes/account.routes.js - Account Controller · Creates accounts and exposes account balance lookup
src/controllers/account.controller.js - Account Model · Durable account record and balance source
src/models/account.model.js
Transactions
Transfers, ledgering, and idempotent financial workflows
- Txn Routes · HTTP routes for transfers and system funding
src/routes/transaction.routes.js - Txn Controller · Runs transfers and system initial-funds workflows
src/controllers/transaction.controller.js - Transaction Model · Stores transfer records and duplicate-protection state
src/models/transaction.model.js - Ledger Model · Immutable debit and credit entries for audit history
src/models/ledger.model.js
Integrations
External notification delivery
- Email Service · Sends welcome and transaction alert emails via Nodemailer and Gmail OAuth2
src/services/email.service.js
Connections 21
- 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