# phuhoang07/esms_api architecture

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

- Interactive diagram: https://gitdiagram.com/phuhoang07/esms_api
- Repository: https://github.com/phuhoang07/esms_api

## Overview

##### Main components of the system
- ESMS API (Presentation/API Layer):
- Contains API controllers (Admin, Auth, Email, Exam, Lecturer, Staff, Student, User) that serve as the HTTP entry points for client requests.
- Hosts the Web API project (ESMS API.csproj) and includes configurations such as appsettings and launchSettings files.
- Business Layer:
- Implements the core business logic.
- Organized into a Services folder with distinct service classes (AuthService, EmailService, ExamService, LecturerService, StaffService, StudentService, UserService) along with their respective interfaces.
- May also contain utility functions aiding the business logic.
- Data Layer:
- Handles persistence and data mapping.
- Contains entities, models, and the database context (ESMSContext.cs) that defines tables such as Users, Exams, ExamSchedules, Participations, Registrations, and more.
- Repository pattern is used with implementations in subdirectories like ExamRepository, ExamScheduleRepository, UserRepository, etc.
- Holds definitions for data transfer objects and request/response models.
- Database:

##### Relationships and interactions
- The ESMS API (Controller layer) receives HTTP requests, routes them to the appropriate controllers.
- Controllers call methods in the Business services, delegating the business logic.
- Business services utilize the Data layer’s repositories to query and update the database.
- The repositories encapsulate data access logic, ensuring separation of concerns.
- There is a pipeline flow: External client → API Controllers → Business Logic → Data Repositories → Database.
- In addition, elements such as the Swagger UI interface for API documentation and the CI/CD pipelines (as evident from the GitHub Actions workflows) should be included as auxiliary components.

##### Important architectural patterns and principles
- Layered Architecture:
- Clear separation between presentation (API), business logic, and data access.
- Repository Pattern:
- Detailed repository implementations for different data models ensure decoupling between business logic and the underlying datastore.
- Dependency Injection:
- Likely used since there are service interfaces for each implemented service class, making the architecture modular and testable.
- Service-Oriented Approach:
- Each domain (User, Exam, Email, etc.) is managed by dedicated services in the Business layer, encapsulating business rules.
- CI/CD Integration:
- Incorporates automated build and deployment pipelines as seen in the .github/workflows configuration for Azure Web App deployment.

##### Relevant technologies, frameworks, or libraries
- ASP.NET Core for Web API development.
- Entity Framework for ORM and data persistence.
- C# as the programing language (based on .cs files and .csproj files).
- Swagger for API documentation.
- GitHub Actions for CI/CD.
- Likely SQL-based database given EF Core context usage and structured entities (e.g., Users, ExamSchedules).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external

    subgraph "API Layer (ESMS API)"
        AdminController["Admin Controller"]:::api
        AuthController["Auth Controller"]:::api
        EmailController["Email Controller"]:::api
        ExamController["Exam Controller"]:::api
        LecturerController["Lecturer Controller"]:::api
        StaffController["Staff Controller"]:::api
        StudentController["Student Controller"]:::api
        UserController["User Controller"]:::api
        APIConfig["API Configuration"]:::api
        APIProject["API Project Files"]:::api
    end

    subgraph "Business Layer (Services)"
        AuthService["Auth Service"]:::business
        EmailService["Email Service"]:::business
        ExamService["Exam Service"]:::business
        LecturerService["Lecturer Service"]:::business
        StaffService["Staff Service"]:::business
        StudentService["Student Service"]:::business
        UserService["User Service"]:::business
        SecretService["Secret Service"]:::business
        Utils["Utility Functions"]:::business
    end

    subgraph "Data Layer (Repositories & Entities)"
        Entities["Entities"]:::data
        ESMSContext["ESMSContext"]:::data
        ExamRepo["Exam Repository"]:::data
        ExamScheduleRepo["ExamSchedule Repository"]:::data
        ParticipationRepo["Participation Repository"]:::data
        RegistrationRepo["Registration Repository"]:::data
        UserRepo["User Repository"]:::data
        RepositoryBase["Repository Base"]:::data
    end

    Database["Database"]:::database
    CICDPipeline["CI/CD Pipeline"]:::cicd
    SwaggerUI["Swagger UI"]:::docs

    %% Data Flow Connections
    Client -->|"request"| AuthController
    UserController -->|"calls"| UserService
    AuthController -->|"delegates"| AuthService
    AuthService -->|"accesses"| ESMSContext
    EmailController -->|"calls"| EmailService
    ExamController -->|"calls"| ExamService
    LecturerController -->|"calls"| LecturerService
    StaffController -->|"calls"| StaffService
    StudentController -->|"calls"| StudentService

    %% Business to Data Layer Connections
    UserService -->|"uses"| UserRepo
    EmailService -->|"uses"| RegistrationRepo
    ExamService -->|"uses"| ExamRepo
    LecturerService -->|"uses"| UserRepo
    StaffService -->|"uses"| UserRepo
    AuthService -->|"accesses"| ESMSContext
    SecretService -->|"utilizes"| Utils

    %% Data Layer to Database Connections
    UserRepo -->|"queries"| Database
    ExamRepo -->|"queries"| Database
    RegistrationRepo -->|"interacts"| Database
    ESMSContext -->|"maps to"| Database
    ExamScheduleRepo -->|"accesses"| ESMSContext
    ParticipationRepo -->|"accesses"| ESMSContext
    RepositoryBase -->|"supports"| ExamRepo
    RepositoryBase -->|"supports"| UserRepo

    %% Additional Auxiliary Connections
    APIProject -->|"configures"| SwaggerUI
    CICDPipeline -->|"deploys"| APIProject

    %% Click Events for API Layer
    click AdminController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/AdminController.cs"
    click AuthController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/AuthController.cs"
    click EmailController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/EmailController.cs"
    click ExamController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/ExamController.cs"
    click LecturerController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/LecturerController.cs"
    click StaffController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/StaffController.cs"
    click StudentController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/StudentController.cs"
    click UserController "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/Controllers/UserController.cs"
    click APIConfig "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/appsettings.json"
    click APIProject "https://github.com/phuhoang07/esms_api/blob/main/ESMS API/ESMS API.csproj"

    %% Click Events for Business Layer
    click AuthService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/AuthService/"
    click EmailService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/EmailService/"
    click ExamService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/ExamService/"
    click LecturerService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/LecturerService/"
    click StaffService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/StaffService/"
    click StudentService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/StudentService/"
    click UserService "https://github.com/phuhoang07/esms_api/tree/main/Business/Services/UserService/"
    click SecretService "https://github.com/phuhoang07/esms_api/blob/main/Business/Services/SecretService/SecretService.cs"
    click Utils "https://github.com/phuhoang07/esms_api/blob/main/Business/Utils/Utils.cs"

    %% Click Events for Data Layer
    click Entities "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Entities/"
    click ESMSContext "https://github.com/phuhoang07/esms_api/blob/main/ESMS Data/Models/ESMSContext.cs"
    click ExamRepo "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/ExamRepository/"
    click ExamScheduleRepo "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/ExamScheduleRepository/"
    click ParticipationRepo "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/ParticipationRepository/"
    click RegistrationRepo "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/RegistrationRepository/"
    click UserRepo "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/UserRepository/"
    click RepositoryBase "https://github.com/phuhoang07/esms_api/tree/main/ESMS Data/Repositories/RepositoryBase/"

    %% Click Event for CI/CD Pipeline
    click CICDPipeline "https://github.com/phuhoang07/esms_api/blob/main/.github/workflows/main_swp-esms-api.yml"

    %% Styles
    classDef api fill:#f9f,stroke:#333,stroke-width:2px;
    classDef business fill:#cff,stroke:#333,stroke-width:2px;
    classDef data fill:#fcf,stroke:#333,stroke-width:2px;
    classDef database fill:#bbf,stroke:#333,stroke-width:2px;
    classDef cicd fill:#cfc,stroke:#333,stroke-width:2px;
    classDef docs fill:#ff9,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd,stroke:#333,stroke-width:2px;
```
