# khoahd7621/prn231-group-project architecture

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

- Interactive diagram: https://gitdiagram.com/khoahd7621/prn231-group-project
- Repository: https://github.com/khoahd7621/prn231-group-project

## Overview

##### Project Type and Overall Purpose
- This is a full-stack salary management application designed for an IT company. It handles core business processes such as employee management, contracts, timekeeping (attendance), leaves, and payroll.
- The backend is built using .NET Core 7 and ASP.NET Core Web API (with OData and JWT authentication) while the frontend is built using ReactJS with TypeScript, Vite, and Redux Toolkit. A SQL script in the Resources folder suggests the use of Microsoft SQL Server as the database.

##### Main Components
a. Backend:
- Business Layer: Contains business objects (e.g., Attendance, Employee, Contract, Payroll, Position, TakeLeave, Level) and Entity Framework (migrations, DbContext) for data persistence.
- Data Access Layer: Consists of specific DAO (Data Access Objects) files for accessing data for each business object.
- Data Transfer Layer: Contains Request and Response DTOs. These ensure proper communication between backend and client.
- Repositories: Implements repository patterns (with interfaces and implementations) to abstract database operations. This layer often includes helper classes and base repositories.
- Web API Layer: Controllers (for Attendance, Authentication, Contract, etc.) present RESTful endpoints and configurations (e.g., AutoMapperConfiguration). They serve as the entry point for client requests.
- Configuration/Authentication: Leverages JWT authentication and OData, and there is a configuration folder to set up mapping and possibly service registration.

b. Frontend:
- Main Application Shell: This includes index.html, main.tsx, and routing configuration files that bootstrap the React application.
- Modules: Organized by feature area (attendance, authentication, contract, dashboard, employee, leave, level, payroll, position). Each module further divides into APIs, components, and models which follow a consistent structure.
- State Management: Redux slices for authentication and profile management.
- Layouts: Default and secondary layouts are provided to route or display content based on the type of user (Admin or Employee).
- Styling and Assets: Includes CSS/SCSS, fonts, and public assets which set up the theme consistent with Ant Design.

c. Database:
- A SQL script in the Resources folder indicates that the project uses Microsoft SQL Server. The EF Core migrations in the backend indicate that the schema is managed via code-first migrations for the business objects.

##### Relationships and Interactions
- API Layers: The backend’s WebAPI controllers serve as intermediaries that receive requests, invoke services (which in turn use repository methods) and return responses to the client.
- Security: Add a note showing the authentication process, where the Authentication Controller issues JWT tokens after validating credentials, and these tokens secure subsequent API access.

##### Architectural Patterns
- Layered Pattern: Divide the backend into layers (Controller, Business Object/Services, Data Access, Repositories).
- Repository Pattern: Clearly show that data access is abstracted through repositories.
- Separation of Concerns: With distinct modules in the frontend, represent modularity (different features have their dedicated folders for APIs, views/components, and state management).
- Micro Frontend Features: Not strictly microservices, but the clear separation of modules in the React app reflects a modular design.
- JWT Authentication Flow: Emphasize how security is centrally managed via the authentication controller and middleware.

##### Detailing Essential Architectural Elements
- Major backend directories (BusinessObject, DataAccess, DataTransfer, WebAPI, Repositories) and outline their roles.
- For the React project, break down the modules (attendance, authentication, etc.) indicating that each module interacts through API calls and shares a common layout and state management setup.
- Optionally, use the provided “Local Development Architecture” image as a reference for drawing network boundaries (i.e., local development environment, backend hosted on a local server, and frontend served via Vite).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend (ReactJS)"
        N_Main["Main Application Shell"]:::frontend
        N_Modules["Modules (attendance, authentication, contract, dashboard, employee, leave, level, payroll, position)"]:::frontend
        N_State["State Management (Redux)"]:::frontend
        N_Layouts["Layouts"]:::frontend
    end

    %% Backend
    subgraph "Backend (.NET Core Web API)"
        B_Controller["Web API Layer (Controllers)"]:::backend
        B_Auth["Authentication Controller"]:::backend
        B_Business["Business Layer"]:::backend
        B_DataTransfer["Data Transfer Layer (DTOs)"]:::backend
        B_Repo["Repositories"]:::backend
        B_DataAccess["Data Access Layer"]:::backend
        B_Config["Configuration & Authentication"]:::backend
    end

    %% Database
    Database["MS SQL Server Database"]:::database

    %% Connections between Frontend and Backend
    N_Main -->|"HTTP_Request/Response"| B_Controller
    N_Modules -->|"API_Calls"| B_Controller

    %% Internal Backend Flows
    B_Controller -->|"Process_Request"| B_Business
    B_Business -->|"Map_DTOs"| B_DataTransfer
    B_Business -->|"Business_Logic"| B_Repo
    B_Repo -->|"Access_Data"| B_DataAccess
    B_DataAccess -->|"EF_Core_Operations"| Database

    %% Authentication Flow within Backend
    B_Controller -->|"Authenticate"| B_Auth
    B_Auth -->|"Issue_JWT"| B_Config

    %% Styling classes
    classDef frontend fill:#DDEEFF,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef database fill:#CCFFCC,stroke:#333,stroke-width:2px;

    %% Click Events for Backend Components
    click B_Business "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/BusinessObject"
    click B_DataAccess "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/DataAccess"
    click B_DataTransfer "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/DataTransfer"
    click B_Repo "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/Repositories"
    click B_Controller "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/ITManagementSystemWebAPI"
    click B_Config "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/ITManagementSystemWebAPI/Configuration"
    click B_Auth "https://github.com/khoahd7621/prn231-group-project/blob/main/ITManagementSystemBackend/ITManagementSystemWebAPI/Controllers/AuthenticationController.cs"

    %% Click Events for Frontend Components
    click N_Main "https://github.com/khoahd7621/prn231-group-project/blob/main/ITSalaryManagementSystemFrontend/index.html"
    click N_Main "https://github.com/khoahd7621/prn231-group-project/blob/main/ITSalaryManagementSystemFrontend/src/main.tsx"
    click N_Modules "https://github.com/khoahd7621/prn231-group-project/tree/main/ITSalaryManagementSystemFrontend/src/modules"
    click N_State "https://github.com/khoahd7621/prn231-group-project/tree/main/ITSalaryManagementSystemFrontend/src/reduxs/slices"
    click N_Layouts "https://github.com/khoahd7621/prn231-group-project/tree/main/ITSalaryManagementSystemFrontend/src/layouts"

    %% Click Events for Database Components
    click Database "https://github.com/khoahd7621/prn231-group-project/tree/main/ITManagementSystemBackend/BusinessObject/Migrations"
    click Database "https://github.com/khoahd7621/prn231-group-project/blob/main/Resources/script.sql"
```
