# sisovin/pern-stack-banking-system architecture

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

- Interactive diagram: https://gitdiagram.com/sisovin/pern-stack-banking-system
- Repository: https://github.com/sisovin/pern-stack-banking-system

## Overview

##### Main Components
- Frontend: The React application (using Vite, Material-UI, Tailwind CSS, Redux for state management, and internationalization support). This side handles all the UI concerns and client-side logic.
- Backend: The Express API (written in TypeScript) that contains:
- Configuration files (database, JWT, logging, environment variables).
- Controllers (for authentication, accounts, customers, transactions, reporting, etc.).
- Routes which define the REST API endpoints.
- Middleware for authentication, session management, RBAC, error handling, and audit logging.
- Models representing business entities (such as User, Account, Transaction, etc.).
- Services that implement business logic like auth, account, transaction, etc.
- Utility modules and TypeScript types.
- Database: PostgreSQL along with Drizzle ORM which is used in migrations, schema definitions, and seeding data.
- Shared Types: A separate directory for shared interfaces and enums that are used across both backend and frontend. This promotes consistency in data handling.

##### Relationships and Flows
- Backend Internal Interactions: Within the backend, illustrate layers such as:
- Routes leading to Controllers,
- Controllers invoking Services,
- Services interacting with Models and the Database.
- Database Interactions: Clearly show that the backend connects to a PostgreSQL database, mediated by ORM components.
- External Services/Integrations (if applicable): If any external payment gateways or external APIs are used (although not explicitly mentioned, a banking system might extend in that direction), include them as separate components interacting with the backend.

##### Architectural Patterns and Design Principles
- Layered Architecture: Emphasize separation of concerns between the presentation/UI (frontend), business logic (backend controllers and services), and data persistence (database).
- Modular/Domain-Driven Organization: The backend uses domain-driven separation (e.g., separate directories for authentication, user management, accounts, transactions, and reporting) which should be captured by grouping related components.
- Security & Authentication: Include dedicated elements for JWT-based authentication and role-based access control (RBAC) to illustrate secure communication.
- Utilize Code Quality Tools: Tools like ESLint, Prettier, and the testing layers (unit, integration, e2e tests) could be noted as supporting components for development and CI/CD (shown at the periphery rather than being central in the runtime architecture).

## Diagram (Mermaid)

```mermaid
graph TD
  %% Frontend Subgraph
  subgraph "Frontend"
    FE_Node["Frontend (React/Vite)"]:::frontend
    FE_HTML["Entry HTML"]:::frontend
    mainTSX["Main TSX"]:::frontend
    appTSX["App TSX"]:::frontend
  end

  %% Shared Types Node
  sharedTypes["Shared Types"]:::shared

  %% Backend Subgraph
  subgraph "Backend"
    B_Node["Backend (Express API Server)"]:::backend

    %% Configuration Subgraph
    subgraph "Configuration"
      config["Database Config"]:::config
    end

    %% Middleware Subgraph
    subgraph "Middleware"
      authMid["Authentication Middleware"]:::middleware
      sessionMid["Session Middleware"]:::middleware
    end

    %% Routes Subgraph
    subgraph "Routes"
      acctRoute["Account Routes"]:::routes
      authRoute["Auth Routes"]:::routes
      custRoute["Customer Routes"]:::routes
      ledgeRoute["Ledger Routes"]:::routes
      transRoute["Transaction Routes"]:::routes
      repRoute["Reporting Routes"]:::routes
    end

    %% Controllers Subgraph
    subgraph "Controllers"
      acctCtrl["Account Controller"]:::controllers
      authCtrl["User Authentication Controller"]:::controllers
      custCtrl["Customer Controller"]:::controllers
      ledgerCtrl["Ledger Controller"]:::controllers
      transCtrl["Transaction Controller"]:::controllers
      repCtrl["Reporting Controller"]:::controllers
    end

    %% Services Subgraph
    subgraph "Services"
      svc["Business Services"]:::services
    end

    %% Models Subgraph
    subgraph "Models"
      acctModel["Account Model"]:::models
      custModel["Customer Model"]:::models
      transModel["Transaction Model"]:::models
      journalModel["Journal Entry Model"]:::models
      userModel["User Model"]:::models
      roleModel["Role Model"]:::models
      permModel["Permission Model"]:::models
    end
  end

  %% Database Node
  db["Database (PostgreSQL)"]:::db

  %% Connections between Frontend, Backend, and Shared Types
  FE_Node -- "RESTAPICall" --> B_Node
  FE_Node -- "uses" --> sharedTypes
  B_Node -- "uses" --> sharedTypes

  %% Configuration arrow
  B_Node -- "configures" --> config

  %% Routes to Controllers connections
  acctRoute -- "calls" --> acctCtrl
  authRoute -- "calls" --> authCtrl
  custRoute -- "calls" --> custCtrl
  ledgeRoute -- "calls" --> ledgerCtrl
  transRoute -- "calls" --> transCtrl
  repRoute -- "calls" --> repCtrl

  %% Middleware to Controllers connections
  authMid -- "auth" --> acctCtrl
  sessionMid -- "session" --> authCtrl

  %% Controllers to Services connections
  acctCtrl -- "calls" --> svc
  authCtrl -- "calls" --> svc
  custCtrl -- "calls" --> svc
  ledgerCtrl -- "calls" --> svc
  transCtrl -- "calls" --> svc
  repCtrl -- "calls" --> svc

  %% Services to Models connections
  svc -- "accesses" --> acctModel
  svc -- "accesses" --> custModel
  svc -- "accesses" --> transModel
  svc -- "accesses" --> journalModel
  svc -- "accesses" --> userModel
  svc -- "accesses" --> roleModel
  svc -- "accesses" --> permModel

  %% Models to Database connections
  acctModel -- "ORM" --> db
  custModel -- "ORM" --> db
  transModel -- "ORM" --> db
  journalModel -- "ORM" --> db
  userModel -- "ORM" --> db
  roleModel -- "ORM" --> db
  permModel -- "ORM" --> db

  %% Click Events
  click FE_Node "https://github.com/sisovin/pern-stack-banking-system/tree/main/frontend/"
  click FE_HTML "https://github.com/sisovin/pern-stack-banking-system/blob/main/frontend/index.html"
  click mainTSX "https://github.com/sisovin/pern-stack-banking-system/blob/main/frontend/src/main.tsx"
  click appTSX "https://github.com/sisovin/pern-stack-banking-system/blob/main/frontend/src/App.tsx"
  click B_Node "https://github.com/sisovin/pern-stack-banking-system/tree/main/backend/"
  click config "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/config/database.ts"
  click acctCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/accountController.ts"
  click authCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/authController.ts"
  click custCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/customerController.ts"
  click ledgerCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/ledgerController.ts"
  click transCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/transactionController.ts"
  click repCtrl "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/controllers/reportingController.ts"
  click acctRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/accountRoutes.ts"
  click authRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/authRoutes.ts"
  click custRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/customerRoutes.ts"
  click ledgeRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/ledgerRoutes.ts"
  click transRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/transactionRoutes.ts"
  click repRoute "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/routes/reportingRoutes.ts"
  click authMid "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/middleware/authMiddleware.ts"
  click sessionMid "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/middleware/sessionMiddleware.ts"
  click acctModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/Account.ts"
  click custModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/Customer.ts"
  click transModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/Transaction.ts"
  click journalModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/JournalEntry.ts"
  click userModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/User.ts"
  click roleModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/Role.ts"
  click permModel "https://github.com/sisovin/pern-stack-banking-system/blob/main/backend/src/models/Permission.ts"

  %% Styles
  classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
  classDef backend fill:#C7F9CC,stroke:#333,stroke-width:2px;
  classDef db fill:#FFE0B2,stroke:#333,stroke-width:2px;
  classDef shared fill:#FBE7C6,stroke:#333,stroke-width:2px;
  classDef middleware fill:#F5C6E2,stroke:#333,stroke-width:2px;
  classDef routes fill:#D1C4E9,stroke:#333,stroke-width:2px;
  classDef controllers fill:#FFCDD2,stroke:#333,stroke-width:2px;
  classDef config fill:#D7CCC8,stroke:#333,stroke-width:2px;
  classDef models fill:#FFF9C4,stroke:#333,stroke-width:2px;
  classDef services fill:#C8E6C9,stroke:#333,stroke-width:2px;
```
