# luongxuannhat/vietnamhistory_be architecture

> Architecture diagram of the GitHub repository luongxuannhat/vietnamhistory_be, 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/luongxuannhat/vietnamhistory_be
- Repository: https://github.com/luongxuannhat/vietnamhistory_be

## Overview

##### Project Type and Purpose
- This project is a full-stack web application (back-end API) developed in .NET. It is built around managing and presenting historical content and related functionalities (such as users, forum discussions, exam histories, posts, notifications, and quizzes) which appear to be centered on Vietnamese history.
- The README provides links to additional materials and a YouTube description, confirming that the project is in development and likely intended for educational or informational purposes.

##### Analyzing the File Structure for Architectural Clues
- The project is organized into several key layers:
- VNH.Domain: Contains the core domain entities (e.g., User, Post, Document, Quiz, Notification, etc.) and enums/exceptions. This indicates a domain-driven design approach where business logic resides in the domain model.
- VNH.Application: Serves as the application (or service) layer. It holds a large set of DTOs, interfaces, mappers, and dependency injection configuration. This layer is responsible for application business rules and orchestrating service operations.
- VNH.Infrastructure: Contains implementations of the interfaces defined in the application layer. It manages the actual data access (EF Core migrations and DbContext), integration with external services (email via SendMailService, SignalR for chat), and common implementations such as file, image, and storage services.
- VNH.WebAPi: Acts as the presentation layer, exposing various controllers that interface with the outside world (HTTP requests/responses) and serve as the entry point for API operations.
- VNH.UnitTest: Contains unit tests for the application and infrastructure components.
- Other supportive components include build and deployment workflows under .github, configuration files (e.g., appsettings.json), and a solution file (VietNamHistory.sln) that aggregates all projects.

a. Main Components:
- Presentation Layer:
- VNH.WebAPi: Controllers (e.g., AccountController, DocumentController, NotificationController, etc.), ViewModels, static assets (wwwroot).
- Application Layer:
- VNH.Application: DTOs for each functional area (Catalog for Users, Posts, Forum, MultipleChoice, etc.), service interfaces, mappers, and dependency injection setup.
- Domain Layer:
- VNH.Domain: Core business entities (User, Document, ExamHistory, etc.), enums, business rules, and custom exceptions.
- Infrastructure Layer:
- VNH.Infrastructure: Service implementations (e.g., AccountService, DocumentService, NotificationService, etc.), Entity Framework migrations and DbContext, presenters (SignalR, Email), and integration with external resources.
- Testing:
- VNH.UnitTest: Unit test cases to validate business logic and service implementations.
- CI/CD:
- .github/workflows indicating CI workflows for build and testing.

b. Relationships and Interactions:
- The Web API layer receives HTTP requests via its various controllers. Each controller calls on the corresponding service methods provided by the Application layer.
- The Application layer handles data transformations using DTOs and relies on interfaces to invoke functionality (services) that are concretely implemented in the Infrastructure layer.
- The Infrastructure layer performs the actual business logic related to data management, integration (like emailing, notifications), and persistence (via the DbContext).
- The Domain layer is referenced across the application as the core model for business entities and rules.

c. Architectural Patterns and Design Principles:
- Layered (or hexagonal/Clean) architecture: Separation between Presentation, Application, Domain, and Infrastructure.
- Dependency Injection: Notably configured in VNH.Application/DependencyInjectionApp.cs and VNH.Infrastructure/DependencyInjectionInfrastructure.cs, enabling decoupled module communication.
- Domain-Driven Design (DDD): Evidenced by a distinct Domain layer with well-defined entities and business logic.

d. Relevant Technologies, Frameworks, and Libraries:
- .NET ecosystem (ASP.NET Core for Web API, Entity Framework Core for data access, and dependency injection patterns).
- SignalR for real-time communication (in VNH.Infrastructure/Presenters).
- Likely a relational database managed via EF Core migrations.
- Configuration using appsettings.json files.
- GitHub workflows for CI/CD.
- Testing frameworks (implied within VNH.UnitTest).

##### Specific Elements
- Components:
- A separate area for CI/CD which includes references to GitHub workflows.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["API Client"]:::client

    subgraph "Presentation Layer"
        A["VNH.WebAPi"]:::presentation
        A1["Controllers"]:::presentationSub
        A2["ViewModels"]:::presentationSub
        A3["wwwroot"]:::presentationSub
    end

    subgraph "Application Layer"
        B["VNH.Application"]:::application
        B1["DTOs, Interfaces, Mappers"]:::applicationSub
        B2["DependencyInjectionApp.cs"]:::applicationSub
    end

    subgraph "Infrastructure Layer"
        C["VNH.Infrastructure"]:::infrastructure
        C1["Service Implementations"]:::infrastructureSub
        C2["DbContext & Migrations"]:::infrastructureSub
        C3["Presenters (Email & SignalR)"]:::infrastructureSub
        C4["DependencyInjectionInfrastructure.cs"]:::infrastructureSub
    end

    subgraph "Domain Layer"
        D["VNH.Domain"]:::domain
        D1["Entities, Enums, Exceptions"]:::domainSub
    end

    subgraph "Testing"
        E["VNH.UnitTest"]:::testing
    end

    subgraph "CI/CD"
        F[".github/workflows"]:::cicd
    end

    Client -- "HTTP_request" --> A
    A -- "calls_services" --> B
    B -- "invokes_implementation" --> C
    C -- "executes_business_logic" --> D

    E -- "verifies" --- A
    E -- "verifies" --- B
    E -- "verifies" --- C
    E -- "verifies" --- D

    F -- "automated_build_test" --> A
    F -- "automated_build_test" --> B
    F -- "automated_build_test" --> C
    F -- "automated_build_test" --> D

    A --> A1
    A --> A2
    A --> A3

    B --> B1
    B --> B2

    C --> C1
    C --> C2
    C --> C3
    C --> C4

    D --> D1

    classDef presentation fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef presentationSub fill:#bfefff,stroke:#000,stroke-width:1px;
    classDef application fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef applicationSub fill:#98fb98,stroke:#000,stroke-width:1px;
    classDef infrastructure fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef infrastructureSub fill:#ffffe0,stroke:#000,stroke-width:1px;
    classDef domain fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef domainSub fill:#ffcc80,stroke:#000,stroke-width:1px;
    classDef testing fill:#ffb6c1,stroke:#000,stroke-width:1px;
    classDef cicd fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef client fill:#87cefa,stroke:#000,stroke-width:1px;

    click A "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.WebAPi"
    click A1 "https://github.com/luongxuannhat/vietnamhistory_be/tree/16.ChatAI/VNH.WebAPi/Controllers"
    click A2 "https://github.com/luongxuannhat/vietnamhistory_be/tree/16.ChatAI/VNH.WebAPi/ViewModels"
    click A3 "https://github.com/luongxuannhat/vietnamhistory_be/tree/16.ChatAI/VNH.WebAPi/wwwroot"

    click B "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.Application"
    click B2 "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.Application/DependencyInjectionApp.cs"

    click C "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.Infrastructure"
    click C4 "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.Infrastructure/DependencyInjectionInfrastructure.cs"

    click D "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.Domain"

    click E "https://github.com/luongxuannhat/vietnamhistory_be/blob/16.ChatAI/VNH.UnitTest"

    click F "https://github.com/luongxuannhat/vietnamhistory_be/tree/16.ChatAI/.github/workflows"
```
