# hoangthien1101/cuoi_ki_be architecture

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

- Interactive diagram: https://gitdiagram.com/hoangthien1101/cuoi_ki_be
- Repository: https://github.com/hoangthien1101/cuoi_ki_be

## Overview

##### Project’s Main Components
- Presentation Layer: This is represented by the TNN/Controllers folder. It contains various controllers (e.g., LoginController, GioHangController, HoaDonController, etc.) which handle HTTP requests and responses. Although a specific Views folder is not explicitly seen, the usage of ViewModels (in TNN/ViewModel) implies that there is a front-end (likely Razor pages) for rendering UI.
- Business Logic Layer: This layer is embodied by the TNN/Service folder (with interfaces for repositories and services such as ILoginService, ITokenServices, etc.) and includes utility classes in TNN/Helpers. The ViewModels in TNN/ViewModel also bridge the domain and presentation layers.
- Data Access Layer: This is split into two parts:
- TNN/Data: This folder contains Entity Framework models and the DbContext (CuaHangDienLanhContext) for interacting with the database.
- TNN/DataReader: Contains components like DataBase.cs, DataDapper.cs, and CustomParameter.cs which likely handle lower-level database access (possibly using Dapper). This suggests that the project might be using a hybrid approach by mixing EF with direct data access via Dapper.
- Static Resources and Configuration: The TNN/wwwroot folder houses public assets (such as images and other static files), and the appsettings.json files provide configuration parameters (including connection strings, environment settings, etc.). The TNN/UpLoad folder indicates file upload capabilities.

##### Relationships and Interactions
- Client requests hit the Controllers in the Presentation Layer, which are responsible for coordinating user interactions.
- Controllers then invoke methods in the Services (business layer) to process requests, perform validation, or manage business logic.
- The Services interface with the Data Access Layer (via data repositories in both TNN/Data and TNN/DataReader) to perform CRUD operations or complex queries.
- Security concerns (such as user authentication and password hashing) are handled by dedicated classes (e.g., in TNN/Helpers/PasswordHasher.cs and CreateSHA256.cs) and by services such as ITokenServices.
- External interactions include handling file uploads (TNN/UpLoad/HinhAnh and IUpLoadHinhAnhRepo) and possibly sending emails (ISendMailService).

##### Important Architectural Patterns and Design Principles
- MVC Pattern: Notice how Controllers and ViewModels are clearly present. This separation ensures that presentation and business logic remain decoupled.
- Repository/Service Pattern: The presence of interfaces like IHangRepo, IUserRepo, and various service interfaces indicates a separation between business logic and data access.
- Separation of Concerns: By dividing the application into Controllers, Services, Data Access, and Helpers, each component focuses on a specific responsibility.
- Use of Configuration Files: The appsettings.json and launchSettings.json files are crucial for environment-specific configuration management.
- Hybrid Data Access: Combining Entity Framework (via the DbContext) with a utility-based Dapper approach provides both high-level model management and fine-tuned SQL execution.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Node
    Client["Client Requests"]:::client

    %% Presentation Layer
    subgraph "Presentation Layer"
        A["Controllers"]:::presentation
        B["ViewModels"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        C["Services"]:::business
        D["Helpers"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        E["EF Models & DbContext"]:::data
        F["Data Reader"]:::data
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        G["Static Resources"]:::static
        H["File Upload"]:::static
        I["appsettings.json"]:::config
        J["appsettings.Development.json"]:::config
        K["launchSettings.json"]:::config
    end

    %% Connections
    Client -->|"HTTP_Request"| A
    A -->|"Invoke"| C
    A -->|"Render_View"| B
    C -->|"CRUD_Operations"| E
    C -->|"Direct_Query"| F
    C -->|"Utilize"| D
    A -->|"Upload_Action"| H
    G -->|"Serve_Files"| A
    I -->|"Configures"| C
    J -->|"Configures"| C
    K -->|"Configures"| A

    %% Click Events
    click A "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/Controllers"
    click B "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/ViewModel"
    click C "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/Service"
    click D "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/Helpers"
    click E "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/Data"
    click F "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/DataReader"
    click G "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/wwwroot"
    click H "https://github.com/hoangthien1101/cuoi_ki_be/tree/main/TNN/UpLoad"
    click I "https://github.com/hoangthien1101/cuoi_ki_be/blob/main/TNN/appsettings.json"
    click J "https://github.com/hoangthien1101/cuoi_ki_be/blob/main/TNN/appsettings.Development.json"
    click K "https://github.com/hoangthien1101/cuoi_ki_be/blob/main/TNN/Properties/launchSettings.json"

    %% Styles
    classDef client fill:#ffffff,stroke:#000000,stroke-width:2px;
    classDef presentation fill:#f9d6ac,stroke:#e86b2d,stroke-width:2px;
    classDef business fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef data fill:#cfe2f3,stroke:#3c78d8,stroke-width:2px;
    classDef static fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef config fill:#ead1dc,stroke:#b45082,stroke-width:2px;
```
