# dthuy0224/hr-system architecture

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

- Interactive diagram: https://gitdiagram.com/dthuy0224/hr-system
- Repository: https://github.com/dthuy0224/hr-system

## Overview

##### Main Components
- Frontend: Represented by the “public” folder (static assets like JavaScript, CSS, images) and “views” directory (EJS templates). Highlight that the frontend handles the presentation layer for different user roles (Admin, Employee, Manager, Accounts Manager).
- Backend: The central Express application encapsulated in app.js, with the “routes” folder containing separate route files for admin, employee, and manager functions. The “config” folder (including passport.js) represents configuration (such as authentication) and middleware logic may be found in “routes/middleware.js”.
- Database: Referenced through db.js and the connection to MongoDB mentioned in the README. This will be a central data repository that holds employee records, attendance, projects, payslips, etc.
- Models: Found in the “models” directory, these files (attendance.js, leave.js, payslip.js, etc.) represent the data structures and business logic tied to the database.
- Seed Data: The “seed” folder with user-seeder.js and project-seeder.js indicates initial data population to bootstrap the application.
- Tests: The “test” directory which holds automated tests for routes and overall application functionality.

##### Relationships and Interactions
- That route files in the “routes” folder delegate requests to the appropriate business logic, often interacting with the “models” to query or modify data in the database.
- Authentication and role-based access control (configured in “config/passport.js” and “routes/middleware.js”) that govern permission levels for Admins, Employees, Project Managers, and Accounts Managers.
- How Seed components preload essential data that the backend uses upon startup.

##### Architectural Patterns & Design Principles
- Separation of Concerns: There’s clear separation between the presentation (views/public), application (routes, controllers in app.js), business logic (models), and data layers.
- MVC Pattern: Although not strictly enforced by framework conventions, there is an MVC-like structure with views (EJS templates), models (business logic), and controllers (Express routes).
- Role-Based Access: Emphasize the differentiated modules for various users as described in the README.
- Use of Middlewares: Indicate that middleware functions for authentication and request handling are integrated (e.g., inside the routes/middleware.js file).

##### Technologies, Frameworks, and Libraries
- Backend: Node.js with Express framework, Passport for authentication.
- Frontend: HTML, Bootstrap, JavaScript, jQuery, and additional JavaScript libraries found in “public/javascripts.”
- Database: MongoDB (as instructed in the README).
- Testing framework for backend integration tests (as seen in the “test” folder).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        direction TB
        A1["Views (EJS Templates)"]
        A2["Public (Static Assets)"]
    end

    %% Application Logic Layer
    subgraph "Application Logic Layer"
        direction TB
        B1["Express Server: app.js & bin/www"]
        B2["Routes Handlers"]
        B3["Middleware & Authentication"]
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        C1["Models"]
        C2["Database (MongoDB) Connection"]
    end

    %% Configuration & Initial Setup
    subgraph "Configuration & Initial Setup"
        direction TB
        D1["Configuration (Passport & Environment)"]
        D2["Seed Data"]
    end

    %% Testing Layer
    subgraph "Testing"
        direction TB
        E1["Test Suite"]
    end

    %% Data Flow Connections
    A1 -->|"HTTP_Request"| B1
    A2 -->|"Serves_Assets"| A1
    B1 -->|"Routes_Request"| B2
    B2 -->|"Auth_Check"| B3
    B2 -->|"BusinessLogic"| C1
    C1 -->|"DB_Operations"| C2
    D1 -->|"Configures"| B1
    D2 -->|"Preloads_Data"| C1
    C2 -.->|"Data_Response"| B2
    E1 -.->|"Tests"| B1

    %% Click Events for Component Mapping
    click A1 "https://github.com/dthuy0224/hr-system/tree/master/views"
    click A2 "https://github.com/dthuy0224/hr-system/tree/master/public"
    click B1 "https://github.com/dthuy0224/hr-system/blob/master/app.js"
    click B2 "https://github.com/dthuy0224/hr-system/tree/master/routes"
    click B3 "https://github.com/dthuy0224/hr-system/blob/master/routes/middleware.js"
    click D1 "https://github.com/dthuy0224/hr-system/blob/master/config/passport.js"
    click C2 "https://github.com/dthuy0224/hr-system/blob/master/db.js"
    click C1 "https://github.com/dthuy0224/hr-system/tree/master/models"
    click D2 "https://github.com/dthuy0224/hr-system/tree/master/seed"
    click E1 "https://github.com/dthuy0224/hr-system/tree/master/test"

    %% Class Definitions for Colors
    class A1,A2 ui
    class B1,B2,B3 app
    class C1,C2 data
    class D1,D2 config
    class E1 test

    %% Styles
    classDef ui fill:#FFC107,stroke:#333,stroke-width:2px;
    classDef app fill:#03A9F4,stroke:#333,stroke-width:2px;
    classDef data fill:#8BC34A,stroke:#333,stroke-width:2px;
    classDef config fill:#9C27B0,stroke:#333,stroke-width:2px;
    classDef test fill:#607D8B,stroke:#333,stroke-width:2px;
```
