# dang252/nmcnpm_quan_ly_so_tiet_kiem architecture

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

- Interactive diagram: https://gitdiagram.com/dang252/nmcnpm_quan_ly_so_tiet_kiem
- Repository: https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem

## Overview

##### Project type and purpose
- This is a full-stack web application (“Đồ án … Quản lý Sổ Tiết Kiệm”) built on Node.js/Express for the back end, Handlebars for server‐side rendering of HTML, vanilla JS/CSS for the front end, and PostgreSQL as the relational database.
- It implements user registration/login (via Passport), CRUD operations on “sổ tiết kiệm” (passbooks), deposit/withdraw flows, user profile management, and balance‐change notifications.

##### High-level architectural components
a. Client (Web Browser)
- Static assets (HTML/CSS/JS in public/)
- Requests the Express server for dynamic pages (handled by Handlebars templates in views/)
b. Web Server (Node.js + Express – Server.js)
- Routing layer (routes/*.r.js)
- Controller layer (controllers/*.c.js)
- View rendering (views/ + layouts/ + partials/)
- Middleware & Configuration (config/*)
– cnStr.js: DB connection string
– connectDB.js: Sequelize/pg connection setup
– exphbsConfig.js: Handlebars engine setup
– passportConfig.js: Passport.js authentication strategies
c. Data Access Layer (models/*.m.js)
- Sequelize or pg-based models for User and Passbook
d. Database (PostgreSQL)
- Tables created via nmcnpm_postgre.sql
e. External/Internal Services
- Passport.js middleware for authentication
- (Future) Email/Notification service or reporting engine

- Use a three-tier depiction:
1. Presentation Tier (Client)
2. Application Tier (Express)
3. Data Tier (PostgreSQL)

- Components & Layout:
– Static resources (css/, js/, img/)
– Sends HTTP GET/POST to Server.js
– Configuration & Middleware
▶ config/connectDB.js → Database connection
▶ config/passportConfig.js → Auth flow
– Router Layer (routes/*.r.js)
– Controller Layer (controllers/*.c.js)
– View Engine (config/exphbsConfig.js + views/)
– Public folder → static assets
– user table
– passbook table
– Transaction history tables

##### Relationships & Data Flows
1. Browser → HTTP request → Express Router
2. Router dispatches to Controller
3. Controller invokes Model (via Sequelize or pg client)
4. Model queries PostgreSQL
5. Response streams back: JSON or Handlebars‐rendered HTML
6. Browser updates UI or navigates to new page
7. Authentication:
– Login request → passport.authenticate() in middleware → session cookie → subsequent requests include session

##### Architectural Patterns & Principles
- MVC (Model-View-Controller) separation
- Layered architecture (Presentation, Application, Data)
- Single Express instance as monolith server (future scope: microservices)
- Configuration segregation (config folder)
- RESTful routes for resource handling

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Tier
    subgraph "Presentation Tier"
        Browser["Web Browser"]:::presentation
        StaticFiles["Static Assets\n(public/)"]:::presentation
    end

    %% Application Tier
    subgraph "Application Tier"
        Server["Express App Server\n(Server.js)"]:::application
        subgraph "Configuration & Middleware"
            cnStr["cnStr.js"]:::application
            connectDB["connectDB.js"]:::application
            exphbs["exphbsConfig.js"]:::application
            passport["passportConfig.js"]:::application
        end
        subgraph "Routing Layer"
            dashR["dashboard.r.js"]:::application
            loginR["login.r.js"]:::application
            passR["passbook.r.js"]:::application
            profR["profile.r.js"]:::application
            regR["register.r.js"]:::application
        end
        subgraph "Controller Layer"
            dashC["dashboard.c.js"]:::application
            loginC["login.c.js"]:::application
            passC["passbook.c.js"]:::application
            profC["profile.c.js"]:::application
            regC["register.c.js"]:::application
        end
        subgraph "Data Access Layer (Models)"
            userM["user.m.js"]:::application
            passM["passbook.m.js"]:::application
        end
        subgraph "View Rendering (Handlebars)"
            cp["createPassbook.hbs"]:::application
            dashV["dashboard.hbs"]:::application
            dep["depositMoney.hbs"]:::application
            loginV["login.hbs"]:::application
            pd["passbookDetails.hbs"]:::application
            pl["passbookList.hbs"]:::application
            profV["profile.hbs"]:::application
            regV["register.hbs"]:::application
            wit["withdrawMoney.hbs"]:::application
            layouts["layouts"]:::application
            partials["partials"]:::application
        end
    end

    %% Data Tier
    subgraph "Data Tier"
        DB["PostgreSQL\n(user, passbook, transactions)"]:::data
    end

    %% External Service
    Future["Reporting / Notification Service"]:::external

    %% Connections
    Browser -->|"HTTP GET/POST"| Server
    Browser -->|"serves static"| StaticFiles
    StaticFiles --> Server

    Server --> cnStr
    Server --> connectDB
    Server --> exphbs
    Server --> passport

    Server --> dashR
    Server --> loginR
    Server --> passR
    Server --> profR
    Server --> regR

    dashR --> dashC
    loginR --> loginC
    passR --> passC
    profR --> profC
    regR --> regC

    loginR --> passport
    passport --> loginC

    dashC --> userM
    loginC --> userM
    regC --> userM
    profC --> userM
    passC --> passM

    userM --> DB
    passM --> DB

    dashC --> dashV
    dashC --> pl
    passC --> cp
    passC --> pd
    passC --> dep
    passC --> wit
    loginC --> loginV
    regC --> regV
    profC --> profV

    layouts --> dashV
    layouts --> cp
    layouts --> dep
    layouts --> loginV
    layouts --> pd
    layouts --> pl
    layouts --> profV
    layouts --> regV
    layouts --> wit

    partials --> dashV
    partials --> cp
    partials --> dep
    partials --> loginV
    partials --> pd
    partials --> pl
    partials --> profV
    partials --> regV
    partials --> wit

    DB -->|SQL results| userM
    DB -->|SQL results| passM

    Server --> Future

    %% Click Events
    click Server "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/Server.js"
    click cnStr "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/config/cnStr.js"
    click connectDB "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/config/connectDB.js"
    click exphbs "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/config/exphbsConfig.js"
    click passport "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/config/passportConfig.js"
    click dashR "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/routes/dashboard.r.js"
    click loginR "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/routes/login.r.js"
    click passR "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/routes/passbook.r.js"
    click profR "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/routes/profile.r.js"
    click regR "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/routes/register.r.js"
    click dashC "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/controllers/dashboard.c.js"
    click loginC "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/controllers/login.c.js"
    click passC "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/controllers/passbook.c.js"
    click profC "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/controllers/profile.c.js"
    click regC "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/controllers/register.c.js"
    click userM "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/models/user.m.js"
    click passM "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/models/passbook.m.js"
    click cp "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/createPassbook.hbs"
    click dashV "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/dashboard.hbs"
    click dep "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/depositMoney.hbs"
    click loginV "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/login.hbs"
    click pd "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/passbookDetails.hbs"
    click pl "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/passbookList.hbs"
    click profV "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/profile.hbs"
    click regV "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/register.hbs"
    click wit "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/withdrawMoney.hbs"
    click layouts "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/layouts/main.hbs"
    click partials "https://github.com/dang252/nmcnpm_quan_ly_so_tiet_kiem/blob/master/views/partials/navbar.hbs"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000
    classDef application fill:#90EE90,stroke:#000
    classDef data fill:#FFA500,stroke:#000
    classDef external fill:#ffffff,stroke:#000,stroke-dasharray: 5 5
```
