# anbinh93/project-it4082 architecture

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

- Interactive diagram: https://gitdiagram.com/anbinh93/project-it4082
- Repository: https://github.com/anbinh93/project-it4082

## Overview

##### Project type and purpose
- This is a RESTful backend API service built with Node.js, Express and Sequelize.
- Its domain is population and household management plus fee/payment tracking (entities: users, residents (nhankhau), households (hokhau), temporary stay/absence, fees (khoanthu), payment records (nopphi), statistics).

##### File structure
- Top-level “03_Developement/server” holds the entire runtime service.
- config/: database connection settings
- controllers/: business-logic handlers per resource
- routes/: Express route definitions mapping URLs → controllers
- middlewares/: e.g. auth token validation
- db/migrations & db/seeders: versioned database schema evolution & initial data
- db/models: Sequelize models, ORM layer
- docs/: API specifications & Postman guides
- scripts/: ad-hoc CLI utilities (createAdmin, updateUserRole)
- server.js: entry point, Express app initialization
- package.json: lists dependencies (Express, Sequelize, authentication libs)
- No frontend code is present—this is purely a backend microservice.

##### README
- Confirms this is a class-project API server.

##### Detail
- Layer/component from the file tree (config, routes, controllers, models, migrations).
- Don’t omit the middleware or scripts—they are part of the operational architecture.
- The goal is a “bird’s-eye” view that still pinpoints every major piece of code in the repo.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    subgraph "API Consumers"
        Client((Client)):::client
        Postman((API Tester)):::client
    end

    %% Server Entry
    Express["Express Server<br/>(server.js)"]:::server
    click Express "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/server.js"

    %% Middleware Layer
    AuthMiddleware["Authentication Middleware"]:::server
    click AuthMiddleware "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/middlewares/authMiddleware.js"

    %% Routing Layer
    subgraph "Routing Layer"
        AccountantRoutes["Accountant Routes"]:::server
        click AccountantRoutes "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/routes/accountantRoutes.js"
        AuthRoutes["Auth Routes"]:::server
        click AuthRoutes "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/routes/authRoutes.js"
        PaymentRoutes["Payment Routes"]:::server
        click PaymentRoutes "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/routes/paymentRoutes.js"
        PopStatsRoutes["Population Statistics Routes"]:::server
        click PopStatsRoutes "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/routes/populationStatisticsRoutes.js"
        StatsRoutes["General Statistics Routes"]:::server
        click StatsRoutes "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/routes/statisticsRoutes.js"
    end

    %% Controller Layer
    subgraph "Controller Layer"
        AccountantController["Accountant Controller"]:::server
        click AccountantController "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/controllers/accountantController.js"
        AuthController["Auth Controller"]:::server
        click AuthController "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/controllers/authController.js"
        PaymentController["Payment Controller"]:::server
        click PaymentController "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/controllers/paymentController.js"
        PopStatsController["Population Statistics Controller"]:::server
        click PopStatsController "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/controllers/populationStatisticsController.js"
        StatsController["General Statistics Controller"]:::server
        click StatsController "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/controllers/statisticsController.js"
    end

    %% ORM Layer
    subgraph "ORM Layer"
        ModelIndex["Model Index"]:::persistence
        click ModelIndex "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/index.js"
        UserModel["User Model"]:::persistence
        click UserModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/user.js"
        ResidentModel["Resident Model"]:::persistence
        click ResidentModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/nhankhau.js"
        HouseholdModel["Household Model"]:::persistence
        click HouseholdModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/hokhau.js"
        TempStayModel["Temp Stay/Absence Model"]:::persistence
        click TempStayModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/tamtrutamvang.js"
        FeeModel["Fee Model"]:::persistence
        click FeeModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/khoanthu.js"
        MembershipModel["Membership Model"]:::persistence
        click MembershipModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/thanhvienhokhau.js"
        HistModel["Household History Model"]:::persistence
        click HistModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/lichsuthaydoihokhau.js"
        PaymentRecordModel["Payment Record Model"]:::persistence
        click PaymentRecordModel "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/models/nopphi.js"
        subgraph "Migrations/Seeders" 
            Migrations["Database Migrations"]:::tooling
            click Migrations "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/migrations/*.js"
            Seeders["Database Seeders"]:::tooling
            click Seeders "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/db/seeders/*.js"
        end
    end

    %% Database
    DB[(Relational Database)]:::database

    %% CLI Scripts
    subgraph "CLI Scripts"
        CreateAdmin["Create Admin"]:::tooling
        click CreateAdmin "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/scripts/createAdmin.js"
        CreateTestUsers["Create Test Users"]:::tooling
        click CreateTestUsers "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/scripts/createTestUsers.js"
        UpdateUserRole["Update User Role"]:::tooling
        click UpdateUserRole "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/scripts/updateUserRole.js"
    end

    %% API Documentation
    subgraph "API Documentation"
        DocsPayment["Payment API Docs"]:::tooling
        click DocsPayment "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/payment-api.md"
        DocsPaymentPostman["Payment Postman Guide"]:::tooling
        click DocsPaymentPostman "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/payment-api-postman-guide.md"
        DocsPopStats["Population Stats API Docs"]:::tooling
        click DocsPopStats "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/population-statistics-api.md"
        DocsPopExamples["Population Stats Examples"]:::tooling
        click DocsPopExamples "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/population-statistics-examples.md"
        DocsStats["General Stats API Docs"]:::tooling
        click DocsStats "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/statistics-api.md"
        DocsStatsExamples["General Stats Examples"]:::tooling
        click DocsStatsExamples "https://github.com/anbinh93/project-it4082/blob/main/03_Developement/server/docs/statistics-api-examples.md"
    end

    %% Flow Connections
    Client -->|"HTTP REST"| Express
    Postman -->|"HTTP REST"| Express
    Express --> AuthMiddleware
    AuthMiddleware --> AccountantRoutes
    AuthMiddleware --> AuthRoutes
    AuthMiddleware --> PaymentRoutes
    AuthMiddleware --> PopStatsRoutes
    AuthMiddleware --> StatsRoutes

    AccountantRoutes --> AccountantController
    AuthRoutes --> AuthController
    PaymentRoutes --> PaymentController
    PopStatsRoutes --> PopStatsController
    StatsRoutes --> StatsController

    AccountantController --> ModelIndex
    AuthController --> ModelIndex
    PaymentController --> ModelIndex
    PopStatsController --> ModelIndex
    StatsController --> ModelIndex

    ModelIndex --> UserModel
    ModelIndex --> ResidentModel
    ModelIndex --> HouseholdModel
    ModelIndex --> TempStayModel
    ModelIndex --> FeeModel
    ModelIndex --> MembershipModel
    ModelIndex --> HistModel
    ModelIndex --> PaymentRecordModel

    UserModel --> DB
    ResidentModel --> DB
    HouseholdModel --> DB
    TempStayModel --> DB
    FeeModel --> DB
    MembershipModel --> DB
    HistModel --> DB
    PaymentRecordModel --> DB

    Migrations --> DB
    Seeders --> DB

    CreateAdmin --> ModelIndex
    CreateTestUsers --> ModelIndex
    UpdateUserRole --> ModelIndex

    %% Styling
    classDef client fill:#E0F7FA,stroke:#00796B,color:#004D40
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef persistence fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef database fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef tooling fill:#ECEFF1,stroke:#455A64,color:#263238
```
