# kirtijha-devloper/whitelable-server architecture

> Architecture diagram of the GitHub repository kirtijha-devloper/whitelable-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kirtijha-devloper/whitelable-server
- Repository: https://github.com/kirtijha-devloper/whitelable-server

## Overview

This is a multi-tenant payments and merchant operations API. Users and administrators enter through HTTP routes; the application handles bill payments, payouts, POS transaction processing, wallet/ledger accounting, settlement, and operational configuration. Its README also documents OTP delivery and Razorpay/Everlife webhook authentication. The graph emphasizes sampled runtime flows and major product areas visible in the tree; several unsampled subsystems are represented at their existing directory paths, without asserting internal calls that the excerpts do not establish.

Main entry points: [`server.js`](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/server.js) (HTTP API), [`services/ledgerService.js`](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/ledgerService.js) (Ledger accounting), [`workers/razorpayWebhookWorker.js`](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/workers/razorpayWebhookWorker.js) (Razorpay processing), [`middleware/validateTokenHandler.js`](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/middleware/validateTokenHandler.js) (Token and roles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and administration"]
  node_auth["Token and roles"]
  node_tenant["Tenant domain"]
  node_useradmin["User administration<br/>[userController.js]"]
  node_admin["Admin operations<br/>[adminController.js]"]
  node_settings["Service settings"]
end

subgraph group_money["Payments and accounting"]
  node_bbps["BBPS credit bills"]
  node_billavenue["Bill Avenue bills"]
  node_payout["Payouts"]
  node_credxpay["Credxpay payouts"]
  node_ledger["Ledger accounting<br/>[ledgerService.js]"]
  node_ledgerdb[("Ledger records<br/>[Ledger.js]")]
end

subgraph group_operations["POS and settlement"]
  node_pos["POS operations"]
  node_charges["Transaction charges<br/>[chargeService.js]"]
  node_settlement["Settlement management"]
  node_reports["Reports and reconciliation"]
  node_inventory["Inventory management"]
end

subgraph group_integrations["Payment integrations"]
  node_razorroute["Razorpay webhook routes"]
  node_razorcontroller["Razorpay notifications"]
  node_razorworker["Razorpay processing"]
  node_webhookdb[("Webhook notifications")]
  node_sms["Bulk9 SMS gateway"]
end

subgraph group_runtime["Application runtime"]
  node_api["HTTP API<br/>[server.js]"]
end

node_user(("Merchant or admin"))

node_user -.->|"sends requests"| node_api
node_api -.->|"validates tokens"| node_auth
node_api -.->|"checks domain"| node_tenant
node_auth -->|"authorizes users"| node_useradmin
node_auth -->|"loads company"| node_tenant
node_api -->|"routes requests"| node_admin
node_api -->|"routes bill requests"| node_bbps
node_api -->|"routes bill requests"| node_billavenue
node_api -->|"routes payouts"| node_payout
node_api -.->|"routes payouts"| node_credxpay
node_admin -.->|"manages services"| node_settings
node_bbps -->|"checks balance"| node_ledger
node_bbps -->|"records payment"| node_ledger
node_billavenue -->|"records accounting"| node_ledger
node_payout -->|"records payout"| node_ledger
node_credxpay -->|"records payout"| node_ledger
node_ledger -->|"reads and writes"| node_ledgerdb
node_api -->|"mounts routes"| node_razorroute
node_razorroute -->|"dispatches events"| node_razorcontroller
node_razorcontroller -->|"stores notifications"| node_webhookdb
node_razorcontroller -->|"processes events"| node_razorworker
node_razorworker -->|"loads notifications"| node_webhookdb
node_razorworker -->|"calculates charges"| node_charges
node_razorworker -->|"posts entries"| node_ledger
node_api -.->|"routes operations"| node_pos
node_api -.->|"runs settlement"| node_settlement
node_api -.->|"routes reports"| node_reports
node_api -.->|"routes inventory"| node_inventory
node_useradmin -.->|"sends OTP"| node_sms

click node_api "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/server.js"
click node_auth "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/middleware/validateTokenHandler.js"
click node_tenant "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/middleware/validateWhitelabelDomain.js"
click node_useradmin "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/userController.js"
click node_admin "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/adminController.js"
click node_settings "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/serviceSettingsService.js"
click node_bbps "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/cc/bbps/bbpsCCBillController.js"
click node_billavenue "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/cc/billAvenue/billAvenueBillController.js"
click node_payout "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/payments/branchxController.js"
click node_credxpay "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/credxpay/payoutController.js"
click node_ledger "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/ledgerService.js"
click node_ledgerdb "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/models/Ledger.js"
click node_pos "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/posMachineController.js"
click node_charges "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/chargeService.js"
click node_settlement "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/settlementService.js"
click node_razorroute "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/routes/razorpay/webhook/notificationRoutes.js"
click node_razorcontroller "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/razorpay/webhook/notificationController.js"
click node_razorworker "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/workers/razorpayWebhookWorker.js"
click node_webhookdb "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/models/RazorpayNotification.js"
click node_reports "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/reportController.js"
click node_inventory "https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/inventoryController.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_auth,node_tenant,node_useradmin,node_admin,node_settings toneBlue
class node_bbps,node_billavenue,node_payout,node_credxpay,node_ledger,node_ledgerdb toneAmber
class node_pos,node_charges,node_settlement,node_reports,node_inventory toneMint
class node_razorroute,node_razorcontroller,node_razorworker,node_webhookdb,node_sms toneRose
class node_api,node_user toneIndigo
```

## Components

### Access and administration

- [Token and roles](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/middleware/validateTokenHandler.js): `middleware/validateTokenHandler.js`
- [Tenant domain](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/middleware/validateWhitelabelDomain.js): `middleware/validateWhitelabelDomain.js`
- [User administration](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/userController.js): `controllers/userController.js`
- [Admin operations](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/adminController.js): `controllers/adminController.js`
- [Service settings](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/serviceSettingsService.js): `services/serviceSettingsService.js`

### Payments and accounting

- [BBPS credit bills](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/cc/bbps/bbpsCCBillController.js): `controllers/cc/bbps/bbpsCCBillController.js`
- [Bill Avenue bills](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/cc/billAvenue/billAvenueBillController.js): `controllers/cc/billAvenue/billAvenueBillController.js`
- [Payouts](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/payments/branchxController.js): `controllers/payments/branchxController.js`
- [Credxpay payouts](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/credxpay/payoutController.js): `controllers/credxpay/payoutController.js`
- [Ledger accounting](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/ledgerService.js): `services/ledgerService.js`
- [Ledger records](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/models/Ledger.js): `models/Ledger.js`

### POS and settlement

- [POS operations](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/posMachineController.js): `controllers/posMachineController.js`
- [Transaction charges](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/chargeService.js): `services/chargeService.js`
- [Settlement management](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/services/settlementService.js): `services/settlementService.js`
- [Reports and reconciliation](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/reportController.js): `controllers/reportController.js`
- [Inventory management](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/inventoryController.js): `controllers/inventoryController.js`

### Payment integrations

- [Razorpay webhook routes](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/routes/razorpay/webhook/notificationRoutes.js): `routes/razorpay/webhook/notificationRoutes.js`
- [Razorpay notifications](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/controllers/razorpay/webhook/notificationController.js): `controllers/razorpay/webhook/notificationController.js`
- [Razorpay processing](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/workers/razorpayWebhookWorker.js): `workers/razorpayWebhookWorker.js`
- [Webhook notifications](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/models/RazorpayNotification.js): `models/RazorpayNotification.js`
- **Bulk9 SMS gateway**

### Application runtime

- [HTTP API](https://github.com/kirtijha-devloper/whitelable-server/blob/feature/complaint/server.js): `server.js`

### Other components

- **Merchant or admin**

## Connections

- Merchant or admin → HTTP API: sends requests
- HTTP API → Token and roles: validates tokens
- HTTP API → Tenant domain: checks domain
- Token and roles → User administration: authorizes users (evidence: `middleware/validateTokenHandler.js`)
- Token and roles → Tenant domain: loads company (evidence: `middleware/validateWhitelabelDomain.js`)
- HTTP API → Admin operations: routes requests
- HTTP API → BBPS credit bills: routes bill requests
- HTTP API → Bill Avenue bills: routes bill requests
- HTTP API → Payouts: routes payouts
- HTTP API → Credxpay payouts: routes payouts
- Admin operations → Service settings: manages services
- BBPS credit bills → Ledger accounting: checks balance (evidence: `controllers/cc/bbps/bbpsCCBillController.js`)
- BBPS credit bills → Ledger accounting: records payment (evidence: `controllers/cc/bbps/bbpsCCBillController.js`)
- Bill Avenue bills → Ledger accounting: records accounting (evidence: `controllers/cc/billAvenue/billAvenueBillController.js`)
- Payouts → Ledger accounting: records payout (evidence: `controllers/payments/branchxController.js`)
- Credxpay payouts → Ledger accounting: records payout (evidence: `controllers/credxpay/payoutController.js`)
- Ledger accounting → Ledger records: reads and writes (evidence: `services/ledgerService.js`)
- HTTP API → Razorpay webhook routes: mounts routes (evidence: `server.js`)
- Razorpay webhook routes → Razorpay notifications: dispatches events (evidence: `routes/razorpay/webhook/notificationRoutes.js`)
- Razorpay notifications → Webhook notifications: stores notifications (evidence: `controllers/razorpay/webhook/notificationController.js`)
- Razorpay notifications → Razorpay processing: processes events (evidence: `controllers/razorpay/webhook/notificationController.js`)
- Razorpay processing → Webhook notifications: loads notifications (evidence: `workers/razorpayWebhookWorker.js`)
- Razorpay processing → Transaction charges: calculates charges (evidence: `workers/razorpayWebhookWorker.js`)
- Razorpay processing → Ledger accounting: posts entries (evidence: `workers/razorpayWebhookWorker.js`)
- HTTP API → POS operations: routes operations
- HTTP API → Settlement management: runs settlement
- HTTP API → Reports and reconciliation: routes reports
- HTTP API → Inventory management: routes inventory
- User administration → Bulk9 SMS gateway: sends OTP
