# dinhnhat2504/doanwebthitracnghiem architecture

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

- Interactive diagram: https://gitdiagram.com/dinhnhat2504/doanwebthitracnghiem
- Repository: https://github.com/dinhnhat2504/doanwebthitracnghiem

## Overview

##### Project type and purpose
- This is a full-stack, monolithic web application built on ASP.NET Core MVC.
- Purpose: an online testing platform with three user roles (Admin, Teacher, Student) plus general public pages (login, register, home).

##### File structure
- Top-level directories
- Areas/Admin, Areas/Teacher, Areas/Student – each holds MVC Controllers, Views, and Models for that role’s UI.
- Controllers – global controllers for home and user management.
- Views/Shared, Views/Home, Views/Users – common layouts, partials, and root-level UI.
- Models – EF Core entity classes that map to database tables.
- Data – AppDbContext for DbSets and EF Core configuration.
- Migrations – EF Core schema migration files.
- Repositories + Interfaces (I…Repository) – data access layer using the Repository pattern.
- Services – business-logic/services layer (e.g., ChatbotService, EmailService).
- Middleware – custom authorization middleware for each role.
- ViewModel – DTOs passed between Controllers and Views.
- wwwroot – static assets (CSS, JS, images, Tailwind, Bootstrap, jQuery).

##### Key architecture insights from README and code
- Uses layered MVC architecture: Presentation (Views + Controllers), Business (Services), Data (Repositories + EF Core + Database).
- Dependency Injection is configured in Program.cs.
- Supports role-based authorization via custom middleware.
- Integrates external services: email sending, AI/chatbot.
- Static files served from wwwroot; UI styled with Bootstrap and Tailwind CSS, dynamic behavior via jQuery.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        Browser["Web Browser"]:::presentation
        Static["Static Asset Server (wwwroot)"]:::presentation
    end

    %% Backend Layer
    subgraph "Backend: ASP.NET Core MVC"
        %% Presentation Layer
        subgraph "Presentation Layer"
            Middleware["Middleware Pipeline"]:::presentation
            subgraph "Controllers"
                GC["Global Controllers"]:::presentation
                AdminC["Admin Area Controllers"]:::presentation
                TeacherC["Teacher Area Controllers"]:::presentation
                StudentC["Student Area Controllers"]:::presentation
            end
            subgraph "Views & ViewModels"
                SharedV["Shared & Root Views"]:::presentation
                AdminV["Admin Area Views"]:::presentation
                TeacherV["Teacher Area Views"]:::presentation
                StudentV["Student Area Views"]:::presentation
                VM["View Models (DTOs)"]:::presentation
            end
        end

        %% Business Logic Layer
        subgraph "Business Logic Layer"
            ChatService["ChatbotService"]:::services
            EmailService["EmailService"]:::services
        end

        %% Data Access Layer
        subgraph "Data Access Layer"
            ReposI["Repository Interfaces"]:::data
            ReposImpl["Repository Implementations"]:::data
            DbCtx["AppDbContext"]:::data
            Entities["Entity Models (EF Core)"]:::data
            Migrations["EF Core Migrations"]:::data
        end

        Program["Program.cs (Startup & DI)"]:::presentation
    end

    %% Database
    Database["Database (SQL Server)"]:::data

    %% External Services
    subgraph "External Services"
        EmailProv["SMTP/Email Provider"]:::external
        AI["AI/Chatbot Endpoint"]:::external
    end

    %% Connections
    Browser -->|"HTTPS Request"| Middleware
    Browser -->|"GET static assets"| Static
    Static -->|"Serves CSS/JS/Images"| Browser

    Middleware -->|"Route request"| GC
    Middleware -->|"Route request"| AdminC
    Middleware -->|"Route request"| TeacherC
    Middleware -->|"Route request"| StudentC

    GC -->|"Returns ViewModel"| VM
    GC -->|"Renders View"| SharedV

    AdminC -->|"Returns ViewModel"| VM
    AdminC -->|"Renders View"| AdminV

    TeacherC -->|"Returns ViewModel"| VM
    TeacherC -->|"Renders View"| TeacherV

    StudentC -->|"Returns ViewModel"| VM
    StudentC -->|"Renders View"| StudentV

    GC -->|"Calls Services"| ChatService
    GC -->|"Calls Services"| EmailService
    AdminC -->|"Calls Services"| ChatService
    TeacherC -->|"Calls Services"| ChatService
    StudentC -->|"Calls Services"| ChatService

    ChatService -->|"Uses Repositories"| ReposI
    EmailService -->|"Uses Repositories"| ReposI

    ReposI -->|"Implemented by"| ReposImpl
    ReposImpl -->|"Uses EF Core"| DbCtx
    DbCtx -->|"Maps Entities"| Entities
    DbCtx -->|"Applies Migrations"| Migrations
    DbCtx -->|"Executes SQL"| Database

    ChatService -->|"HTTP/REST"| AI
    EmailService -->|"SMTP"| EmailProv

    Program -->|"Configures DI & Middleware"| Middleware
    Program -->|"Registers Services"| ChatService
    Program -->|"Registers Services"| EmailService
    Program -->|"Registers Repositories"| ReposImpl

    %% Click Events
    click Static "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/wwwroot"
    click GC "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Controllers/HomeController.cs"
    click GC "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Controllers/UsersController.cs"
    click AdminC "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Admin/Controllers/"
    click TeacherC "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Teacher/Controllers/"
    click StudentC "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Student/Controllers/"
    click SharedV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Views/Shared"
    click SharedV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Views/Home"
    click SharedV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Views/Users"
    click AdminV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Admin/Views"
    click TeacherV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Teacher/Views"
    click StudentV "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Areas/Student/Views"
    click VM "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/ViewModel"
    click Entities "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Models"
    click DbCtx "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Data/AppDBContext.cs"
    click Migrations "https://github.com/dinhnhat2504/doanwebthitracnghiem/tree/master/DoAnWebThiTracNghiem/Migrations"
    click ReposI "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Repositories/I*Repository.cs"
    click ReposImpl "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Repositories/EF*Repository.cs"
    click ChatService "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Services/ChatbotService.cs"
    click EmailService "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Services/EmailService.cs"
    click Program "https://github.com/dinhnhat2504/doanwebthitracnghiem/blob/master/DoAnWebThiTracNghiem/Program.cs"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#4da3ff,color:#000;
    classDef services fill:#d4edda,stroke:#34a853,color:#000;
    classDef data fill:#ffe5b4,stroke:#fbbc04,color:#000;
    classDef external fill:#e8daef,stroke:#a569bd,color:#000;
```
