# linhdangdev/exam-management-system architecture

> Architecture diagram of the GitHub repository linhdangdev/exam-management-system, 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/linhdangdev/exam-management-system
- Repository: https://github.com/linhdangdev/exam-management-system

## Overview

##### Main Components
- Frontend Client:
- Built with Blazor.
- Contains various pages such as Login, Exam, Result, Admin (for both login and monitoring), and Info.
- Handles UI presentation, session management, and event handling.
- Backend Server:
- A C#/.NET Core project handling business logic.
- Contains Controllers (e.g., ExamController, InfoController, AdminController, UserController) and goes through various business (BUS) services.
- Uses Dependency Injection to hook up authentication, caching, repository patterns, and service installers.
- Data Access Layer (DAL) & Models:
- Presents in both the Server and Shared projects with DataReaders, Repositories (for each domain object like AudioListened, CauHoi, DeThi, etc.) and models (e.g., CaThi, SinhVien, etc.)
- Implements the Repository pattern for SQL Server interactions.
- Caching - Redis:
- Redis is used to cache exam content and other frequently accessed data improving performance (e.g., Result page).
- External Dependencies:
- SQL Server as the relational database.
- Redis running on the configured host and port.
- Third-party libraries such as MathJax (from the JS files) to render LaTeX expressions for mathematical formulas.

##### Relationships and Interactions
- The Blazor client sends HTTP requests to the backend’s API endpoints (controllers) to authenticate users, load exam data, and report results.
- Backend controllers delegate work to Business Services which implement the application’s logic (using services such as Exam, User, and Admin services).
- Business Services in turn use the Data Access Layer (repositories) for CRUD operations on SQL Server.
- For performance, certain calls (e.g., loading exam questions or resuming sessions) may be optimized using Redis caching. So, the backend retrieves or updates data from/to the cache as needed.
- Shared models facilitate type consistency between the client and server.

##### Important Architectural Patterns
- Layered Architecture:
- Presentation Layer (Blazor frontend)
- Business Logic Layer (BUS services in the Server)
- Data Access Layer (DAL repositories and Entity Framework context)
- Cross-cutting concerns such as authentication and caching.
- Dependency Injection:
- Used across the backend to modularize components (authentication, caching, repository/service installers).
- Repository Pattern:
- CRUD operations and database logic are abstracted behind repository interfaces
- Micro Frontend Components:
- The client side is segmented into various pages addressing distinct functionalities (exam, admin, info, login).

##### Technologies and Their Roles
- Blazor for building the client-side web UI.
- C# and .NET Core for the server-side logic.
- SQL Server for persistent storage.
- Redis for caching and improving performance.
- Standard web assets (HTML, CSS, JavaScript) to provide styling and dynamic behavior.

##### Additional Details
- Provide configuration highlights such as the use of installer classes (like AuthenticationInstaller, CacheInstaller) which set up dependencies at runtime.
- Mention any utilities or extensions (for example, session storage extension methods on the client) as their own small nodes if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Blazor Client)
    subgraph "Frontend (Blazor Client)"
        FE_Pages["UI Pages: Login, Exam, Result, Admin, Info"]:::frontend
        FE_Auth["CustomAuthenticationStateProvider"]:::frontend
        FE_Session["SessionStorage Extension"]:::frontend
        FE_DataAccess["ApplicationDataService"]:::frontend
        FE_MathJax["MathJax Script"]:::frontend_ext
        FE_Bootstrap["Bootstrap Assets"]:::frontend_ext
    end

    %% Backend (API Controllers & Services)
    subgraph "Backend (API Controllers & Services)"
        subgraph "API Layer"
            BE_Controllers["API Controllers"]:::backend
        end
        subgraph "Business Layer"
            BE_BUS_Class["BUS - Classes"]:::backend
            BE_BUS_Interface["BUS - Interfaces"]:::backend
        end
        subgraph "Data Access Layer"
            BE_Context["ApplicationDbContext"]:::backend_dal
            BE_Repositories["Repositories"]:::backend_dal
            BE_Shared["Shared Models"]:::backend_dal
        end
        subgraph "System Configuration"
            BE_DI["Dependency Injection & Installers"]:::backend_di
        end
        subgraph "Caching Services"
            BE_RedisConfig["Redis Configuration"]:::backend_cache
            BE_CacheInstaller["Cache Installer"]:::backend_cache
            BE_ResponseCache["Response Cache Service"]:::backend_cache
        end
    end

    %% Databases & External Cache
    subgraph "Databases & Cache"
        SQL["SQL Server Database"]:::database
        Redis["Redis Cache"]:::cache
    end

    %% Relationships
    FE_Pages -->|"HTTPRequest"| BE_Controllers
    FE_DataAccess -->|"API Calls"| BE_Controllers
    BE_Controllers -->|"Delegates"| BE_BUS_Class
    BE_Controllers -->|"Delegates"| BE_BUS_Interface
    BE_BUS_Class -->|"Uses"| BE_Repositories
    BE_BUS_Interface -->|"Uses"| BE_Repositories
    BE_Repositories -->|"Connects"| BE_Context
    BE_Repositories -->|"Accesses"| BE_Shared
    BE_BUS_Class -->|"CachesData"| BE_RedisConfig
    BE_BUS_Class -->|"CachesData"| BE_CacheInstaller
    BE_BUS_Class -->|"CachesData"| BE_ResponseCache
    BE_Repositories -->|"Queries"| SQL
    BE_Context -->|"ORM"| SQL
    BE_RedisConfig -->|"Configures"| Redis
    BE_CacheInstaller -->|"SetsUp"| Redis
    BE_ResponseCache -->|"Caches"| Redis
    FE_Pages -->|"Uses"| FE_Auth
    FE_Pages -->|"Uses"| FE_Session
    FE_Pages -->|"Renders"| FE_MathJax
    FE_Pages -->|"Renders"| FE_Bootstrap
    BE_DI -->|"Configures"| BE_Controllers
    BE_DI -->|"Configures"| BE_BUS_Class
    BE_DI -->|"Configures"| BE_Repositories

    %% Click Events for Frontend
    click FE_Pages "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Client/Pages"
    click FE_Auth "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Client/Authentication/CustomAuthenticationStateProvider.cs"
    click FE_Session "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Client/Extensions/SessionStorageServiceExtension.cs"
    click FE_DataAccess "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Client/DAL/ApplicationDataService.cs"
    click FE_MathJax "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Client/wwwroot/js/mathJaxBlazor.js"
    click FE_Bootstrap "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Client/wwwroot/bootstrap/"

    %% Click Events for Backend
    click BE_Controllers "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Server/Controllers"
    click BE_BUS_Class "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Server/BUS/class"
    click BE_BUS_Interface "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Server/BUS/interface"
    click BE_Context "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Server/DAL/Models/ApplicationDbContext.cs"
    click BE_Repositories "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Server/DAL/Repositories"
    click BE_Shared "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Shared/Models"
    click BE_DI "https://github.com/linhdangdev/exam-management-system/tree/main/GettingStarted/Server/Installers"
    click BE_RedisConfig "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Server/Configurations/RedisConfiguration.cs"
    click BE_CacheInstaller "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Server/Installers/CacheInstaller.cs"
    click BE_ResponseCache "https://github.com/linhdangdev/exam-management-system/blob/main/GettingStarted/Server/DAL/Repositories/ResponseCacheService.cs"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef frontend_ext fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef backend_dal fill:#b8daff,stroke:#004085,stroke-width:2px;
    classDef backend_di fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef backend_cache fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#f5c6cb,stroke:#721c24,stroke-width:2px,stroke-dasharray: 5 5;
    classDef cache fill:#e2e3e5,stroke:#6c757d,stroke-width:2px,stroke-dasharray: 5 5;
```
