# tqthy/furniture-store-management-be architecture

> Architecture diagram of the GitHub repository tqthy/furniture-store-management-be, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tqthy/furniture-store-management-be
- Repository: https://github.com/tqthy/furniture-store-management-be

## Overview

##### Main Components
- Express.js Server: Represent the REST API server that coordinates all incoming requests.
- Middleware & Authentication: Include JWT-based authentication and any other middleware (as seen from JwtService.js).
- Controllers & Routes: List all controllers (e.g., ProductController.js, InvoiceController.js, etc.) and map them to their corresponding routes under the src/routes directory. This layer handles request parsing and delegates to services.
- Service Layer: Represent services (in the src/services folder) that implement business logic for products, inventory, customers, and orders.
- External Integrations: Highlight AWS S3 integration (as indicated in s3config.js) for file storage, and any integrations for payment processing (e.g., order-momo.js, order-vnpay.js).
- Testing: Note the inclusion of unit tests (Jest configuration and tests in src/__tests__) for quality control.

- From Routes, show directional calls to Controllers.
- Controllers should then indicate delegation to the Services layer.
- Services interact with the Models which in turn access the PostgreSQL database. Include directional flows (e.g., “create”, “read”, “update”, “delete” operations).
- External links:
– Payment routes (momo, vnpay) interacting with external payment services.
- Additionally, include the configuration folder for DB connections, S3 setup, and other initializations.

##### Architectural Patterns and Design Principles
- MVC/MVCS Pattern: The clear separation into routes, controllers, and services indicates an MVC-like architecture.
- Layered Architecture: Demonstrate how the application is divided into presentation (routes), business logic (controllers/services), and data access (models/migrations) layers.
- Modular Design: Notice the separation of concerns throughout the different directories.

##### Relevant Technologies
- Express.js as the backend framework.
- Sequelize as the ORM for PostgreSQL.
- JWT for authentication.
- Docker (via Dockerfile and docker-compose.yml) for containerization and deployment.
- AWS S3 for storage.
- GitHub Actions for CI/CD and Jest for unit testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Express Server and Middleware
    ES["Express.js Server"]:::server
    JWT["JWT Middleware"]:::middleware
    ES -->|"uses"| JWT

    %% API Layer Subgraph
    subgraph "API Layer"
        RT["Routes"]:::api
        CT["Controllers"]:::api
        RT -->|"calls"| CT
        PM1["Order Momo Route"]:::api
        PM2["Order VNPay Route"]:::api
        RT -->|"includes"| PM1
        RT -->|"includes"| PM2
        FC["File Controller"]:::api
        CT -->|"delegates to"| FC
    end

    %% Service Layer Subgraph
    subgraph "Service Layer"
        SV["Services"]:::service
        FS["File Service"]:::service
        CT -->|"delegates to"| SV
        FC -->|"invokes"| FS
    end

    %% Data Access Layer Subgraph
    subgraph "Data Access Layer"
        MD["Models"]:::data
        MIG["Migrations"]:::data
        SD["Seeders"]:::data
        DB[(PostgreSQL DB)]:::db
        SV -->|"operates on"| MD
        MD -->|"CRUD"| DB
        MIG -->|"setup"| DB
        SD -->|"seed"| DB
    end

    %% External Integrations Subgraph
    subgraph "External Integrations"
        AWS["AWS S3"]:::external
        PAY["Payment Gateway"]:::external
    end

    %% Connections to External Integrations
    FS -->|"uploads to"| AWS
    PM1 -->|"processes with"| PAY
    PM2 -->|"processes with"| PAY

    %% Testing Node
    TEST["Testing"]:::testing

    %% Deployment & CI/CD Subgraph
    subgraph "Deployment & CI/CD"
        DF["Dockerfile"]:::deployment
        DC["docker-compose.yml"]:::deployment
        DI[".dockerignore"]:::deployment
        CICD["CI/CD Pipeline"]:::deployment
    end

    %% Overall Flow Connections
    ES --> RT
    SV --> MD

    %% Standalone Connections (non linear, shown at bottom)
    DB --- TEST
    DB --- CICD

    %% Click Events
    click ES "https://github.com/tqthy/furniture-store-management-be/blob/main/src/server.js"
    click JWT "https://github.com/tqthy/furniture-store-management-be/blob/main/src/middleware/JwtService.js"
    click RT "https://github.com/tqthy/furniture-store-management-be/tree/main/src/routes"
    click PM1 "https://github.com/tqthy/furniture-store-management-be/blob/main/src/routes/order-momo.js"
    click PM2 "https://github.com/tqthy/furniture-store-management-be/blob/main/src/routes/order-vnpay.js"
    click CT "https://github.com/tqthy/furniture-store-management-be/tree/main/src/controllers"
    click FC "https://github.com/tqthy/furniture-store-management-be/blob/main/src/controllers/FileController.js"
    click SV "https://github.com/tqthy/furniture-store-management-be/tree/main/src/services"
    click FS "https://github.com/tqthy/furniture-store-management-be/blob/main/src/services/FileService.js"
    click MD "https://github.com/tqthy/furniture-store-management-be/tree/main/src/models"
    click MIG "https://github.com/tqthy/furniture-store-management-be/tree/main/src/migrations"
    click SD "https://github.com/tqthy/furniture-store-management-be/tree/main/src/seeders"
    click AWS "https://github.com/tqthy/furniture-store-management-be/blob/main/src/config/s3config.js"
    click TEST "https://github.com/tqthy/furniture-store-management-be/tree/main/src/__tests__"
    click DF "https://github.com/tqthy/furniture-store-management-be/tree/main/Dockerfile"
    click DC "https://github.com/tqthy/furniture-store-management-be/blob/main/docker-compose.yml"
    click DI "https://github.com/tqthy/furniture-store-management-be/blob/main/.dockerignore"
    click CICD "https://github.com/tqthy/furniture-store-management-be/tree/main/.github/workflows"

    %% Class Definitions for Colors and Styles
    classDef server fill:#F8C,stroke:#333,stroke-width:2px
    classDef middleware fill:#FC9,stroke:#333,stroke-width:2px
    classDef api fill:#9CF,stroke:#333,stroke-width:2px
    classDef service fill:#AFC,stroke:#333,stroke-width:2px
    classDef data fill:#CFC,stroke:#333,stroke-width:2px
    classDef db fill:#FF9,stroke:#333,stroke-width:2px
    classDef external fill:#FCF,stroke:#333,stroke-width:2px
    classDef testing fill:#CFF,stroke:#333,stroke-width:2px
    classDef deployment fill:#FFC,stroke:#333,stroke-width:2px
```
