# datnp1810/gocerystore_dacn architecture

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

## Overview

##### Main Components
- Front-End Client: Represent the separately cloned Font-End project which interacts with the back-end via APIs.
- API Layer: Controllers (like HoaDonController, MonAnController, UserController, etc.) that expose endpoints for managing food products, orders, menus, and nutrition-related details.
- Business Logic Layer: Services (e.g., HoaDonService, EmailService, MonAnService, etc.) that encapsulate the core business rules, including supporting the GA algorithm for menu suggestions, email functionalities, and token management.
- Data Access Layer: Repositories (with their interfaces such as IMonAnRepository, IHoaDonRepository, etc.) that abstract away database interactions. Also include DTOs for data transfer between layers.
- Database Layer: SQL Server (with data and migration scripts, CSV seed files, and Entity definitions housed in the Entities folder).
- Supporting Components: Middleware for Authentication and Authorization (CustomAuthenticationMiddleware, CustomAuthorizationMiddleware) and other helpers (e.g., ApplicationAutoMapper, ApplicationRoles, EmailTemplateHelper).
- External Services: Indicate external integrations such as Email Services, Cloud-based image/file management (Cloudinary as evidenced by settings in Models), and any other external APIs or libraries (Swagger for API testing).

##### Relationships and Interactions
- Services interact with Repositories for database operations and use Entity Framework’s DbContext (ApplicationDbContext) to translate requests to SQL Server.
- Middleware intercepts incoming requests to enforce security (authenticated access via JWT) and applies authorization checks before the request reaches the Controllers.
- The GA Algorithm for menu suggestion should be highlighted as part of the business logic, possibly noted beside the ThucDonTuanService and related services.

##### Architectural Patterns
- Layered Architecture: Distinguish between Presentation (Controllers), Business Logic (Services), and Data Access (Repositories/Entities).
- Clean Separation of Concerns: Each layer/component should have clearly defined responsibilities—Controllers handling HTTP requests, Services processing business logic, and Repositories working with data persistence.
- Use of Middleware for cross-cutting concerns (authentication and authorization).

##### Technologies and Frameworks
- .NET Core and ASP.NET Core for building API services.
- Entity Framework Core for ORM and SQL Server for the database.
- Swagger for API documentation and testing.
- Threading and Memory Cache mechanisms for optimizing the GA algorithm and performance.
- External libraries for email management and cloud uploads (Cloudinary).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    FE["Front-End Client"]:::frontend

    %% Middleware Layer
    subgraph "Middleware Layer"
        AMW["Authentication Middleware"]:::middleware
        AuthZ["Authorization Middleware"]:::middleware
    end

    %% API Layer
    subgraph "API Layer"
        Controllers["API Controllers"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Services["Business Services"]:::service
        GA["GA_Algorithm_(Menu_Suggestion)"]:::service
    end

    %% Supporting Components
    subgraph "Supporting Components"
        Helpers["Helpers"]:::helper
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Repositories["Repositories"]:::repository
        DTOs["DTOs"]:::repository
        Entities["Entities"]:::repository
    end

    %% Database Layer
    subgraph "Database Layer"
        DbContext["ApplicationDbContext"]:::database
        Seed["Seed_&_Migrations"]:::database
    end

    %% External Services
    subgraph "External Services"
        Email["Email Service"]:::external
        Upload["Upload Service"]:::external
    end

    %% Connections (Vertical Layout)
    FE --> AMW
    AMW --> AuthZ
    AuthZ --> Controllers
    Controllers --> Services
    Services --> GA
    Services --> Helpers
    Services --> Repositories
    Services --> DTOs
    Services --> Entities
    Repositories --> DbContext
    DTOs --> DbContext
    Entities --> DbContext
    DbContext --> Seed
    Services --> Email
    Services --> Upload

    %% Click Events
    click Controllers "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Controllers"
    click Services "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Services"
    click Repositories "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Repositories"
    click DTOs "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/DTOs"
    click Entities "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Entities"
    click DbContext "https://github.com/datnp1810/gocerystore_dacn/blob/master/GoceryStore_DACN/Data/ApplicationDbContext.cs"
    click Seed "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Data_SQL"
    click AMW "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Middlewares"
    click AuthZ "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Middlewares"
    click Helpers "https://github.com/datnp1810/gocerystore_dacn/tree/master/GoceryStore_DACN/Helpers"
    click Email "https://github.com/datnp1810/gocerystore_dacn/blob/master/GoceryStore_DACN/Services/EmailService.cs"
    click Upload "https://github.com/datnp1810/gocerystore_dacn/blob/master/GoceryStore_DACN/Services/UploadService.cs"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef middleware fill:#e6f2ff,stroke:#3399ff,stroke-width:2px;
    classDef api fill:#e6ffe6,stroke:#006600,stroke-width:2px;
    classDef service fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef helper fill:#f9f2ec,stroke:#cc9966,stroke-width:2px;
    classDef repository fill:#ffe6e6,stroke:#990000,stroke-width:2px;
    classDef database fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef external fill:#f2e6ff,stroke:#9933ff,stroke-width:2px;
```
