# luongxuannhat/hrm-project architecture

> Architecture diagram of the GitHub repository luongxuannhat/hrm-project, 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/luongxuannhat/hrm-project
- Repository: https://github.com/luongxuannhat/hrm-project

## Overview

##### Main Components
- Server Entry Point: Represent the main Node.js server (BE/app.js and BE/server.js) which bootstraps and starts the application.
- Configuration: Include a component for “Configuration” (from BE/config). This handles environment settings, system responses, etc.
- Routing & Controllers: Show that incoming HTTP requests hit “Routes” (BE/routes) which then delegate to various “Controllers” (found in BE/controllers). Label controllers for activities like attendances, leave_requests, late_early_requests, projects, teams, system_logs, users, and work_shifts.
- Models & Database: Highlight that domain entities (e.g., Attendance, LeaveRequest, Project, User, Team, WorkShift, etc.) are defined in BE/models. Even if the actual database isn’t directly shown, these models imply a connection with a database (likely a relational DB). You might denote a “Database” component connected to these models.
- Static/Public Assets: Note that there’s a “Public” directory (BE/public) holding static assets like images and js files (for Swagger customization).
- Seeders & Swagger: Include additional components showing “Seeders” for initializing data (found in BE/seeders) and “Swagger” for API documentation (found in BE/swagger).

##### Relationships/Interactions
- Start the flow from “Client” sending HTTP requests to the “Server Entry Point.”
- The Server processes these requests via “Routes” which pass them on to corresponding “Controllers.”
- “Controllers” call “Services/Helpers” where additional business logic is processed.
- “Middlewares” intercept requests during their journey to validate authentication and authorization.

##### Architectural Patterns and Design Principles
- MVC Structure: Clearly separate Controllers (handling business logic) from Models (database entities) and include Routes that buffer between external requests and controllers.
- Middleware Chain: Show a sequence where middlewares (authentication, authorization) process requests before they reach their designated controllers.
- Service Layer: Indicate that certain common operations (logging, file upload) are abstracted into service components, enhancing modularity and reusability.
- Environment Configuration: Emphasize the use of configuration files separated under BE/config to manage environment-specific variables and responses.

##### Relevant Technologies
- Node.js/Express: As the runtime and web framework driving the application.
- Swagger: For API documentation, as seen in BE/swagger.
- Potential Database (not explicitly shown but implied with the use of Models): Mention this if known.
- Additional modules and libraries are managed via BE/package.json.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["API Consumer"]:::client
    A --> B["Server Application"]:::server

    subgraph "Server Application"
        direction TB
        B1["app.js"]:::server
        B2["server.js"]:::server
    end
    B --> C["Configuration"]:::config
    C --> D["Routes"]:::routes
    D --> E["Middlewares"]:::middleware

    subgraph "Controllers Layer"
        direction TB
        F1["Attendances Controller"]:::controller
        F2["Late Early Requests Controller"]:::controller
        F3["Leave Requests Controller"]:::controller
        F4["Projects Controller"]:::controller
        F5["System Logs Controller"]:::controller
        F6["Teams Controller"]:::controller
        F7["Users Controller"]:::controller
        F8["Work Shifts Controller"]:::controller
    end
    E -->|"validatedRequest"| F1
    E -->|"validatedRequest"| F2
    E -->|"validatedRequest"| F3
    E -->|"validatedRequest"| F4
    E -->|"validatedRequest"| F5
    E -->|"validatedRequest"| F6
    E -->|"validatedRequest"| F7
    E -->|"validatedRequest"| F8

    subgraph "Services and Helpers"
        direction TB
        subgraph "Services"
            direction TB
            H1["System Log Service"]:::service
            H2["Upload File Service"]:::service
        end
        subgraph "Helpers"
            direction TB
            I1["Color Factory Helper"]:::helper
            I2["Time Helper"]:::helper
        end
    end
    F1 --> J["Models"]:::model
    F2 --> J
    F3 --> J
    F4 --> J
    F5 --> J
    F6 --> J
    F7 --> J
    F8 --> J

    J --> K["Database"]:::db

    B --> L["Swagger API Documentation"]:::swagger
    B --> M["Public Assets"]:::public
    B --> N["Seeders"]:::seeder

    %% Click Events for Server Entry Point
    click B1 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/app.js"
    click B2 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/server.js"

    %% Click Events for Configuration
    click C "https://github.com/luongxuannhat/hrm-project/tree/main/BE/config"
    click C "https://github.com/luongxuannhat/hrm-project/blob/main/BE/config/config.js"
    click C "https://github.com/luongxuannhat/hrm-project/blob/main/BE/config/response.js"

    %% Click Events for Routing
    click D "https://github.com/luongxuannhat/hrm-project/tree/main/BE/routes"
    click D "https://github.com/luongxuannhat/hrm-project/blob/main/BE/routes/attendance.route.js"
    click D "https://github.com/luongxuannhat/hrm-project/blob/main/BE/routes/late_early_request.route.js"

    %% Click Events for Middlewares
    click E "https://github.com/luongxuannhat/hrm-project/tree/main/BE/middlewares"
    click E "https://github.com/luongxuannhat/hrm-project/blob/main/BE/middlewares/authenticate.middleware.js"
    click E "https://github.com/luongxuannhat/hrm-project/blob/main/BE/middlewares/authorize.middleware.js"
    click E "https://github.com/luongxuannhat/hrm-project/blob/main/BE/middlewares/leader_project.middleware.js"
    click E "https://github.com/luongxuannhat/hrm-project/blob/main/BE/middlewares/leader_team.middleware.js"

    %% Click Events for Controllers
    click F1 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/attendances.controller.js"
    click F2 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/late_early_requests.controller.js"
    click F3 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/leave_requests.controller.js"
    click F4 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/projects.controller.js"
    click F5 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/system_logs.controller.js"
    click F6 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/teams.controller.js"
    click F7 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/users.controller.js"
    click F8 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/controllers/work_shifts.controller.js"

    %% Click Events for Models
    click J "https://github.com/luongxuannhat/hrm-project/tree/main/BE/models"
    click J "https://github.com/luongxuannhat/hrm-project/blob/main/BE/models/Attendance.js"
    click J "https://github.com/luongxuannhat/hrm-project/tree/main/BE/models/enums"

    %% Click Events for Services
    click H1 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/services/system_log.service.js"
    click H2 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/services/upload_file.service.js"

    %% Click Events for Helpers
    click I1 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/helpers/color_factory.hepler.js"
    click I2 "https://github.com/luongxuannhat/hrm-project/blob/main/BE/helpers/time.helper.js"

    %% Click Events for Public Assets
    click M "https://github.com/luongxuannhat/hrm-project/tree/main/BE/public"
    click M "https://github.com/luongxuannhat/hrm-project/tree/main/BE/public/images"
    click M "https://github.com/luongxuannhat/hrm-project/tree/main/BE/public/js"

    %% Click Events for Seeders
    click N "https://github.com/luongxuannhat/hrm-project/tree/main/BE/seeders"
    click N "https://github.com/luongxuannhat/hrm-project/blob/main/BE/seeders/seed_account_and_role.js"
    click N "https://github.com/luongxuannhat/hrm-project/blob/main/BE/seeders/seed_attendance.js"
    click N "https://github.com/luongxuannhat/hrm-project/blob/main/BE/seeders/seed_work_shifts.js"

    %% Click Events for Swagger
    click L "https://github.com/luongxuannhat/hrm-project/tree/main/BE/swagger"
    click L "https://github.com/luongxuannhat/hrm-project/blob/main/BE/swagger/autogen.js"
    click L "https://github.com/luongxuannhat/hrm-project/blob/main/BE/swagger/index.js"
    click L "https://github.com/luongxuannhat/hrm-project/blob/main/BE/swagger/sanitizeSchemas.js"

    %% Styles
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef server fill:#bbf,stroke:#333,stroke-width:2px;
    classDef config fill:#aff,stroke:#333,stroke-width:2px;
    classDef routes fill:#cfc,stroke:#333,stroke-width:2px;
    classDef middleware fill:#fcf,stroke:#333,stroke-width:2px;
    classDef controller fill:#ff9,stroke:#333,stroke-width:2px;
    classDef service fill:#9ff,stroke:#333,stroke-width:2px;
    classDef helper fill:#ffc,stroke:#333,stroke-width:2px;
    classDef model fill:#fdd,stroke:#333,stroke-width:2px;
    classDef db fill:#ddd,stroke:#333,stroke-width:2px;
    classDef swagger fill:#dff,stroke:#333,stroke-width:2px;
    classDef seeder fill:#dfd,stroke:#333,stroke-width:2px;
    classDef public fill:#fdf,stroke:#333,stroke-width:2px;

    class A client;
    class B,B1,B2 server;
    class C config;
    class D routes;
    class E middleware;
    class F1,F2,F3,F4,F5,F6,F7,F8 controller;
    class H1,H2 service;
    class I1,I2 helper;
    class J model;
    class K db;
    class L swagger;
    class N seeder;
    class M public;
```
