# cuongtq1210/ocms_be architecture

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

- Interactive diagram: https://gitdiagram.com/cuongtq1210/ocms_be
- Repository: https://github.com/cuongtq1210/ocms_be

## Overview

##### Project Type & Purpose
- This is a back-end system meant to handle certification, user management, and related administrative tasks for an online certification platform.
- The README simply identifies it as the “Online Certification Management System – BackEnd,” which confirms its scope mainly consists of business logic, data access, and web API endpoints.

##### Key Architectural Components
a. Business Objects (OCMS_BOs):
- Contains entity classes (e.g., Candidate, Certificate, Course, User, etc.), data models, and database migrations that define your database schema.
- Includes helper classes for JWT token creation, password hashing, and mapping between models.
- Has dedicated folders for Request and Response models, as well as ViewModels, ensuring a clear separation between data transfer objects (DTOs) and business entities.

b. Repository Layer (OCMS_Repositories):
- Implements generic repositories and specific repository interfaces (e.g., ICandidateRepository, ICourseRepository) to abstract database access.
- Uses a UnitOfWork pattern (UnitOfWork.cs) to coordinate and commit repository changes.
- This layer is responsible for all data interactions, providing a decoupled mechanism for CRUD operations.

c. Service Layer (OCMS_Services):
- Contains service interfaces and their concrete implementations (e.g., IAuthenticationService, IEmailService) that encapsulate business logic.
- This layer consumes the repository layer to process data and applies various business rules before handing data off to the API layer.
- Implements important services like authentication, blob handling, and email notifications.

d. Presentation/API Layer (OCMS_WebAPI):
- Contains controllers (e.g., CandidateController, CertificateTemplateController, etc.) that expose RESTful endpoints.
- Integrates authorization through custom attributes (see the AuthorizeSettings folder) and settings defined in appsettings.json.
- Includes the Program.cs and Docker-related files (Dockerfile, .dockerignore) for application startup and deployment.

##### Relationships and Interactions
- Front Door: API Controllers act as the gateway, receiving HTTP requests and orchestrating service operations.
- The Service Layer sits between the controllers and the repository layer. Controllers call service methods, which in turn use the repositories to interact with the database.
- The Repository Layer abstracts direct database operations; repositories execute CRUD operations leveraging the migrations and Entity Framework context (OCMSDbContext.cs in OCMS_BOs).
- Business Objects and DTOs facilitate data exchange across layers, ensuring data integrity and clean mapping between external requests/responses and internal structures.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly separates concerns into Business (BOs), Data Access (Repositories), Business Logic (Services), and Presentation (WebAPI Controllers).
- Unit of Work: Coordinating various repository transactions to ensure atomic operations.
- Dependency Injection: Likely used to inject repositories into services and services into controllers.
- RESTful API Design: Controllers expose endpoints in a standard RESTful manner.
- Security: JWT token handling for authentication and custom authorization attributes safeguard endpoints.

##### Relevant Technologies, Frameworks, & Deployment
- ASP.NET Core for building and hosting the WebAPI.
- Entity Framework for managing migrations and database interactions.
- Docker for containerizing the application (as evident from the Dockerfile and .dockerignore).
- GitHub Actions for CI/CD (see the .github/workflows folder).

- Service Layer (with various services like CandidateService, CertificateTemplateService, etc.).
- Business Logic (through entities and DTOs that enforce state and transformations).
- Next, connect the Service Layer to the Repository Layer that abstracts data operations.
- Finally, illustrate the database (or data store) that the repository operations interact with.
- Side components like authentication utilities (JWT token helper) and background tasks (EmailService, BlobService).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client / External Consumer"]:::client

    subgraph "API Layer"
        API["API Controllers (OCMS_WebAPI)"]:::api
        AUTH["Authorization Utilities"]:::api
        DCKR["Docker Configuration"]:::deploy
    end

    subgraph "Service Layer"
        SVC["Services (OCMS_Services)"]:::service
    end

    subgraph "Repository Layer"
        REPO["Repositories (OCMS_Repositories)"]:::repo
    end

    subgraph "Business Layer"
        BO["Business Objects (OCMS_BOs)"]:::bo
    end

    DB(("Database")):::external

    subgraph "Deployment / CI/CD"
        CICD["CI/CD Pipeline Configuration"]:::deploy
    end

    A -->|"sendRequest"| API
    API -->|"calls"| SVC
    SVC -->|"uses"| REPO
    REPO -->|"operatesOn"| BO
    BO -->|"persistsData"| DB

    click BO "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_BOs"
    click REPO "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_Repositories"
    click SVC "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_Services"
    click API "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_WebAPI"
    click AUTH "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_WebAPI/AuthorizeSettings"
    click DCKR "https://github.com/cuongtq1210/ocms_be/tree/main/OCMS_WebAPI_Solution/OCMS_WebAPI/Dockerfile"
    click CICD "https://github.com/cuongtq1210/ocms_be/blob/main/.github/workflows/main_ocms-vjvn.yml"

    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef api fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#bfb,stroke:#333,stroke-width:2px;
    classDef repo fill:#ffb,stroke:#333,stroke-width:2px;
    classDef bo fill:#fbb,stroke:#333,stroke-width:2px;
    classDef deploy fill:#ddd,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
```
