# sakincse21/digital-banking-system architecture

> Architecture diagram of the GitHub repository sakincse21/digital-banking-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sakincse21/digital-banking-system
- Repository: https://github.com/sakincse21/digital-banking-system

## Overview

##### Project type and purpose
- This is a backend-only, full-stack API for a digital wallet/banking system built with Node.js, Express.js, TypeScript, and MongoDB (Mongoose).
- It exposes role-based REST endpoints for users, agents, and admins to register, authenticate, manage wallets, and process transactions atomically.

##### File structure
- Top-level:
- src/app: contains all application layers (config, errorHelpers, interface, middlewares, modules, routes, utils)
- src/app/modules: feature folders (auth, user, wallet, transaction) each with route, controller, service, model, validation, constants
- src/server.ts & src/app.ts: entry points—setup Express app, middleware, error handling, route mounting
- dist/: compiled output mirroring src structure
- Config files: .env.example, tsconfig.json, vercel.json, postman-config.json
- Patterns:
- Layered (Router → Controller → Service → Model), error-handling middleware, validation, JWT-based auth, Mongoose sessions for atomic transactions

##### README for additional insights
- Features: JWT auth, bcrypt password hashing, role checks, transaction statuses, atomic operations
- ERD: shows relationships between User, Wallet, Transaction
- Modules and endpoints mapping

##### Elements
- Clear labels:
- “Client” (Web/Mobile)
- “Express App” with sub-blocks: Config, Middlewares, Routes, Controllers, Services, Models
- “JWT & bcrypt” as external utility services
- Data flow from Client → Express → MongoDB → Express → Client
- Rectangles for layers (blue for Routes, green for Services, orange for Models)

##### Detail
- Feature module (Auth, User, Wallet, Transaction) as its own sub-component in the Services layer
- Error-handling chain: catchAsync → globalErrorHandler
- Validation layer invoking Zod or Joi validators
- Mongoose session transactions in the Transaction service

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Web/Mobile Client"]:::client

    subgraph "API Gateway - Express App"
        Server["Express App Entry Points"]:::gateway
        Config["Environment Config"]:::config

        subgraph "Middlewares"
            AuthCheck["Authentication Check"]:::middleware
            Validate["Request Validation"]:::middleware
            NotFound["Not Found Handler"]:::middleware
            ErrorHandler["Global Error Handler"]:::middleware
        end

        subgraph "Routes Layer"
            RootRouter["Root Router"]:::routes
            AuthRoute["Auth Module Routes"]:::routes
            UserRoute["User Module Routes"]:::routes
            WalletRoute["Wallet Module Routes"]:::routes
            TransactionRoute["Transaction Module Routes"]:::routes
        end

        subgraph "Controllers Layer"
            AuthCtrl["Auth Module Controller"]:::controller
            UserCtrl["User Module Controller"]:::controller
            WalletCtrl["Wallet Module Controller"]:::controller
            TransactionCtrl["Transaction Module Controller"]:::controller
        end

        subgraph "Services Layer"
            AuthSvc["Auth Module Service"]:::service
            UserSvc["User Module Service"]:::service
            WalletSvc["Wallet Module Service"]:::service
            TransactionSvc["Transaction Module Service"]:::service
            TxnUtils["Transaction Utilities"]:::service
        end

        subgraph "Models Layer"
            UserModel["User Mongoose Model"]:::model
            WalletModel["Wallet Mongoose Model"]:::model
            TransactionModel["Transaction Mongoose Model"]:::model
        end

        Validation["Validation Schemas"]:::validation
        Constants["Transaction Constants"]:::constant
        ErrorHelpers["Error Helper Utilities"]:::error
        Interfaces["Shared Interfaces"]:::interface
        Utils["Shared Utility Functions"]:::util
    end

    DB["MongoDB"]:::db
    JWT["JWT & bcrypt"]:::external

    Client -->|HTTP Request| Server
    Server --> Config
    Server --> AuthCheck
    Server --> Validate
    Server --> NotFound
    Server --> ErrorHandler
    Server --> RootRouter

    RootRouter --> AuthRoute
    RootRouter --> UserRoute
    RootRouter --> WalletRoute
    RootRouter --> TransactionRoute

    AuthRoute --> AuthCtrl --> AuthSvc --> UserModel --> DB
    UserRoute --> UserCtrl --> UserSvc --> UserModel --> DB
    WalletRoute --> WalletCtrl --> WalletSvc --> WalletModel --> DB
    TransactionRoute --> TransactionCtrl --> TransactionSvc --> TransactionModel --> DB
    TransactionSvc --> TxnUtils

    AuthSvc --> JWT
    AuthSvc --> Utils
    AuthCtrl --> Validation
    UserSvc --> Validation
    WalletSvc --> Validation
    TransactionSvc --> Validation
    TransactionSvc --> Constants
    ErrorHandler --> ErrorHelpers
    AuthCheck --> Interfaces
    Validate --> Interfaces
    Utils --> Interfaces

    classDef client fill:#D5E8D4,stroke:#82B366;
    classDef gateway fill:#FFF2CC,stroke:#D6B656;
    classDef config fill:#F8CECC,stroke:#B85450;
    classDef middleware fill:#E1D5E7,stroke:#9673A6;
    classDef routes fill:#DAE8FC,stroke:#6C8EBF;
    classDef controller fill:#E6F4EA,stroke:#579F55;
    classDef service fill:#FFF2CC,stroke:#D6B656;
    classDef model fill:#F4CCCC,stroke:#B85450;
    classDef validation fill:#F7E0C0,stroke:#C38932;
    classDef constant fill:#E8E8E8,stroke:#A3A3A3;
    classDef error fill:#FDE9D9,stroke:#E69138;
    classDef interface fill:#E2EFDA,stroke:#6AA84F;
    classDef util fill:#D0E0E3,stroke:#45818E;
    classDef db fill:#DDEBF7,stroke:#6C8EBF,stroke-width:2px;
    classDef external fill:#F2F2F2,stroke:#7F7F7F,stroke-dasharray: 5 5;

    click Server "https://github.com/sakincse21/digital-banking-system/blob/main/src/server.ts"
    click Server "https://github.com/sakincse21/digital-banking-system/blob/main/src/app.ts"
    click Config "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/config/env.ts"
    click AuthCheck "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/middlewares/authCheck.ts"
    click Validate "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/middlewares/validateRequest.ts"
    click NotFound "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/middlewares/notFound.ts"
    click ErrorHandler "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/middlewares/globalErrorHandler.ts"
    click RootRouter "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/routes/index.ts"
    click AuthRoute "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/auth/auth.route.ts"
    click AuthCtrl "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/auth/auth.controller.ts"
    click AuthSvc "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/auth/auth.service.ts"
    click UserRoute "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/user/user.route.ts"
    click UserCtrl "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/user/user.controller.ts"
    click UserSvc "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/user/user.service.ts"
    click UserModel "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/user/user.model.ts"
    click WalletRoute "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/wallet/wallet.route.ts"
    click WalletCtrl "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/wallet/wallet.controller.ts"
    click WalletSvc "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/wallet/wallet.service.ts"
    click WalletModel "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/wallet/wallet.model.ts"
    click TransactionRoute "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.route.ts"
    click TransactionCtrl "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.controller.ts"
    click TransactionSvc "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.service.ts"
    click TransactionModel "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.model.ts"
    click TxnUtils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.utils.ts"
    click Constants "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.constant.ts"
    click Validation "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/auth/auth.validation.ts"
    click Validation "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/user/user.validation.ts"
    click Validation "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/wallet/wallet.validation.ts"
    click Validation "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/modules/transaction/transaction.validation.ts"
    click ErrorHelpers "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/errorHelpers/appErrorHandler.ts"
    click ErrorHelpers "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/errorHelpers/handleCastError.ts"
    click ErrorHelpers "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/errorHelpers/handleDuplicateError.ts"
    click ErrorHelpers "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/errorHelpers/handleValidationError.ts"
    click ErrorHelpers "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/errorHelpers/handleZodError.ts"
    click Interfaces "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/interface/error.types.ts"
    click Interfaces "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/interface/index.d.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/catchAsync.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/jwt.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/sendResponse.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/setAuthCookies.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/queryBuilder.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/amountChecker.ts"
    click Utils "https://github.com/sakincse21/digital-banking-system/blob/main/src/app/utils/seedSuperAdmin.ts"
```
