# parthawasthi-30/double-entry-ledger-api architecture

> Architecture diagram of the GitHub repository parthawasthi-30/double-entry-ledger-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/parthawasthi-30/double-entry-ledger-api
- Repository: https://github.com/parthawasthi-30/double-entry-ledger-api

## Overview

This is a Node.js/Express API for authenticated account management and double-entry financial transactions. Clients enter through the Express app and API routes; transaction handlers validate requests, check idempotency and balances, then record a transaction with debit and credit ledger entries in a MongoDB session. Account balance reads derive totals from ledger entries. Authentication, registration, transaction history, and email notifications are additional product capabilities. The graph uses the sampled route and controller wiring; some database and external-service links rely on README documentation rather than inspected runtime configuration.

Main entry points: [`src/controller/transaction.controller.js`](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/transaction.controller.js) (Transaction handlers), [`src/app.js`](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/app.js) (Express application), [`src/controller/auth.controller.js`](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/auth.controller.js) (Auth handlers), [`src/middleware/auth.middleware.js`](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/middleware/auth.middleware.js) (Auth middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry and routing"]
  node_app["Express application<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_account_routes["Account routes<br/>[accounts.routes.js]"]
  node_transaction_routes["Transaction routes"]
end

subgraph group_identity["Identity and access"]
  node_auth_controller["Auth handlers<br/>[auth.controller.js]"]
  node_auth_middleware["Auth middleware<br/>[auth.middleware.js]"]
  node_users[("User records<br/>[user.models.js]")]
  node_token_blacklist[("Token blacklist<br/>[blacklist.model.js]")]
end

subgraph group_finance["Accounts and ledger"]
  node_account_controller["Account handlers"]
  node_transaction_controller["Transaction handlers"]
  node_accounts[("Account records<br/>[account.model.js]")]
  node_ledger[("Ledger entries<br/>[ledger.model.js]")]
  node_transactions[("Transaction records")]
end

subgraph group_integrations["Persistence and notifications"]
  node_database_config["MongoDB connection<br/>[db.js]"]
  node_mongodb[("MongoDB")]
  node_email_service["Email service<br/>[email.service.js]"]
  node_email_provider["Email provider"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_account_routes
node_app -->|"mounts"| node_transaction_routes
node_auth_routes -->|"routes to"| node_auth_controller
node_account_routes -->|"guards with"| node_auth_middleware
node_account_routes -->|"routes to"| node_account_controller
node_transaction_routes -->|"guards with"| node_auth_middleware
node_transaction_routes -->|"routes to"| node_transaction_controller
node_auth_controller -->|"reads and writes"| node_users
node_auth_controller -->|"blacklists tokens"| node_token_blacklist
node_auth_controller -->|"sends notices"| node_email_service
node_auth_middleware -->|"loads user"| node_users
node_auth_middleware -->|"checks token"| node_token_blacklist
node_account_controller -->|"manages accounts"| node_accounts
node_transaction_controller -->|"checks accounts"| node_accounts
node_transaction_controller -->|"records transfers"| node_transactions
node_transaction_controller -->|"writes entries"| node_ledger
node_transaction_controller -->|"sends notice"| node_email_service
node_accounts -->|"derives balance"| node_ledger
node_database_config -.->|"connects to"| node_mongodb
node_email_service -->|"sends email"| node_email_provider
node_users -.->|"persists records"| node_mongodb
node_accounts -.->|"persists records"| node_mongodb
node_ledger -.->|"persists entries"| node_mongodb
node_transactions -.->|"persists records"| node_mongodb

click node_app "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/app.js"
click node_auth_routes "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/auth.routes.js"
click node_account_routes "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/accounts.routes.js"
click node_transaction_routes "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/transaction.routes.js"
click node_auth_controller "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/auth.controller.js"
click node_auth_middleware "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/middleware/auth.middleware.js"
click node_users "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/user.models.js"
click node_token_blacklist "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/blacklist.model.js"
click node_account_controller "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/account.controller.js"
click node_transaction_controller "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/transaction.controller.js"
click node_accounts "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/account.model.js"
click node_ledger "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/ledger.model.js"
click node_transactions "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/transaction.model.js"
click node_database_config "https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/config/db.js"
click node_email_service "https://github.com/parthawasthi-30/double-entry-ledger-api/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_app,node_auth_routes,node_account_routes,node_transaction_routes,node_client toneBlue
class node_auth_controller,node_auth_middleware,node_users,node_token_blacklist toneAmber
class node_account_controller,node_transaction_controller,node_accounts,node_ledger,node_transactions toneMint
class node_database_config,node_mongodb,node_email_service,node_email_provider toneRose
```

## Components

### API entry and routing

- [Express application](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/auth.routes.js): `src/routes/auth.routes.js`
- [Account routes](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/accounts.routes.js): `src/routes/accounts.routes.js`
- [Transaction routes](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/routes/transaction.routes.js): `src/routes/transaction.routes.js`

### Identity and access

- [Auth handlers](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/auth.controller.js): `src/controller/auth.controller.js`
- [Auth middleware](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/middleware/auth.middleware.js): `src/middleware/auth.middleware.js`
- [User records](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/user.models.js): `src/models/user.models.js`
- [Token blacklist](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/blacklist.model.js): `src/models/blacklist.model.js`

### Accounts and ledger

- [Account handlers](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/account.controller.js): `src/controller/account.controller.js`
- [Transaction handlers](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/controller/transaction.controller.js): `src/controller/transaction.controller.js`
- [Account records](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/account.model.js): `src/models/account.model.js`
- [Ledger entries](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/ledger.model.js): `src/models/ledger.model.js`
- [Transaction records](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/models/transaction.model.js): `src/models/transaction.model.js`

### Persistence and notifications

- [MongoDB connection](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/config/db.js): `src/config/db.js`
- **MongoDB**
- [Email service](https://github.com/parthawasthi-30/double-entry-ledger-api/blob/main/src/services/email.service.js): `src/services/email.service.js`
- **Email provider**

### Other components

- **API client**

## Connections

- API client → Express application: sends requests (evidence: `README.md`)
- Express application → Auth routes: mounts (evidence: `src/app.js`)
- Express application → Account routes: mounts (evidence: `src/app.js`)
- Express application → Transaction routes: mounts (evidence: `src/app.js`)
- Auth routes → Auth handlers: routes to (evidence: `src/routes/auth.routes.js`)
- Account routes → Auth middleware: guards with (evidence: `src/routes/accounts.routes.js`)
- Account routes → Account handlers: routes to (evidence: `src/routes/accounts.routes.js`)
- Transaction routes → Auth middleware: guards with (evidence: `src/routes/transaction.routes.js`)
- Transaction routes → Transaction handlers: routes to (evidence: `src/routes/transaction.routes.js`)
- Auth handlers → User records: reads and writes (evidence: `src/controller/auth.controller.js`)
- Auth handlers → Token blacklist: blacklists tokens (evidence: `src/controller/auth.controller.js`)
- Auth handlers → Email service: sends notices (evidence: `src/controller/auth.controller.js`)
- Auth middleware → User records: loads user (evidence: `src/middleware/auth.middleware.js`)
- Auth middleware → Token blacklist: checks token (evidence: `src/middleware/auth.middleware.js`)
- Account handlers → Account records: manages accounts (evidence: `src/controller/account.controller.js`)
- Transaction handlers → Account records: checks accounts (evidence: `src/controller/transaction.controller.js`)
- Transaction handlers → Transaction records: records transfers (evidence: `src/controller/transaction.controller.js`)
- Transaction handlers → Ledger entries: writes entries (evidence: `src/controller/transaction.controller.js`)
- Transaction handlers → Email service: sends notice (evidence: `src/controller/transaction.controller.js`)
- Account records → Ledger entries: derives balance (evidence: `src/models/account.model.js`)
- MongoDB connection → MongoDB: connects to
- Email service → Email provider: sends email (evidence: `src/services/email.service.js`)
- User records → MongoDB: persists records (evidence: `README.md`)
- Account records → MongoDB: persists records (evidence: `README.md`)
- Ledger entries → MongoDB: persists entries (evidence: `README.md`)
- Transaction records → MongoDB: persists records (evidence: `README.md`)
