# leyen1403/shopchain architecture

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

- Interactive diagram: https://gitdiagram.com/leyen1403/shopchain
- Repository: https://github.com/leyen1403/shopchain

## Overview

##### Project type and purpose
- This is a layered ASP.NET Core 8.0 Web API called “ShopChain” for managing store, province, district, ward and user-client data.
- It applies CQRS (Commands/Queries) inside an Application layer, Domain entities and interfaces in Core, EF Core in Infrastructure, and exposes REST endpoints via the Api project.

##### File structure
- Top-level projects:
- ShopChain.Api – Web API controllers, HTTP launch settings, Swagger, Program.cs
- ShopChain.Application – Commands, Queries, DTOs, mapping profiles, DI setup
- ShopChain.Core – Domain entities, interfaces, common base classes, DI setup
- ShopChain.Infrastructure – EF Core DbContext, Migrations, Repositories, external VnAddress API integration
- ShopChain.UnitTest – MSTest unit tests for domain logic

##### README for additional insights
- Dependencies: .NET 8 SDK, SQL Server
- Run command: dotnet run –project ShopChain.Api
- Swagger is enabled in dev mode
- Vietnamese guides in docs/CauTrucDuAn.md and docs/HuongDanNguoiMoi.md

##### Elements
- From Client → API → Application → Core Interfaces → Infrastructure → Database
- From Application → Infrastructure → External VnAddress API → back to Application
- Blue for API layer
- Green for Application
- Yellow for Core
- Orange for Infrastructure
- Gray for Database & External services
- Rectangles for modules/projects

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    subgraph "Client / API Consumer"
        Client["Client\n(Web UI, Mobile App)"]:::external
    end

    %% API Layer
    subgraph "ShopChain.Api (API Layer)"
        direction TB
        AuthC["AuthController"]:::api
        ProvC["ProvincesController"]:::api
        StoreC["StoresController"]:::api
        BaseApiC["BaseApiController"]:::api
        Program["Program.cs"]:::api
        DI_API["DependencyInjection.cs"]:::api
    end

    %% Application Layer
    subgraph "ShopChain.Application (Application Layer)"
        direction TB
        Commands["Commands\n(CreateNewProvince,AddStore,UpdateStore,DeleteStore,SyncLocations)"]:::application
        Queries["Queries\n(GetAllProvinces,GetStoreById,GetToken,...)"]:::application
        DTOs["DTOs & Mappings\n(ProvinceDto,DistrictDto,WardDto,StoreDto,LoginRequest,StoreProfile)"]:::application
        DI_App["DependencyInjection.cs"]:::application
    end

    %% Core Layer
    subgraph "ShopChain.Core (Domain/Core Layer)"
        direction TB
        Entities["Entities\n(Province,District,Ward,Store,UserClient)"]:::core
        Interfaces["Interfaces\n(IProvinceRepository,ILocationRepository,IStoreRepository,IUserClientRepository,IVnAddressApiService)"]:::core
        Commons["Commons & Models\n(AuditableEntity,Provinces)"]:::core
        DI_Core["DependencyInjection.cs"]:::core
    end

    %% Infrastructure Layer
    subgraph "ShopChain.Infrastructure (Infrastructure Layer)"
        direction TB
        DbContext["AppDbContext.cs"]:::infrastructure
        Migrations["Migrations\n(EF Core)"]:::infrastructure
        Repos["Repositories\n(ProvinceRepository,StoreRepository,UserClientRepository,LocationRepository,DepartmentRepository)"]:::infrastructure
        VnService["VnAddressApiService & DTOs"]:::infrastructure
        DI_Infra["DependencyInjection.cs"]:::infrastructure
    end

    %% External & Database
    subgraph "External & Database"
        direction TB
        SQLServer["SQL Server\n(Database)"]:::database
        VnExternal["External VnAddress API"]:::external
    end

    %% Unit Tests
    subgraph "ShopChain.UnitTest"
        direction TB
        ProdTests["ProductTests.cs"]:::test
        MSTestCfg["MSTestSettings.cs"]:::test
    end

    %% Relationships
    Client -->|"HTTP Request"| AuthC
    Client --> ProvC
    Client --> StoreC

    AuthC -->|"calls Application"| Commands
    ProvC -->|"calls Application"| Queries
    StoreC -->|"calls Application"| Commands

    Commands -->|"invoke Domain Interfaces"| Interfaces
    Queries -->|"invoke Domain Interfaces"| Interfaces

    Interfaces -->|"implemented by"| Repos
    Repos -->|"CRUD operations"| SQLServer

    Commands -->|"calls IVnAddressApiService"| VnService
    VnService -->|"HTTP Client"| VnExternal
    VnExternal -->|"response data"| VnService
    VnService -->|"returns DTOs"| Commands

    DI_API --> AuthC
    DI_API --> ProvC
    DI_API --> StoreC
    DI_App --> Commands
    DI_App --> Queries
    DI_Core --> Interfaces
    DI_Infra --> DbContext
    DI_Infra --> Repos
    DI_Infra --> VnService

    ProdTests --> Commands
    ProdTests --> Entities

    %% Click Events
    click AuthC "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/Controllers/AuthController.cs"
    click ProvC "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/Controllers/ProvincesController.cs"
    click StoreC "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/Controllers/StoresController.cs"
    click BaseApiC "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/Controllers/BaseApiController.cs"
    click Program "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/Program.cs"
    click DI_API "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Api/DependencyInjection.cs"

    click DI_App "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Application/DependencyInjection.cs"

    click DI_Core "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Core/DependencyInjection.cs"

    click DbContext "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Infrastructure/Data/AppDbContext.cs"
    click Migrations "https://github.com/leyen1403/shopchain/tree/main/ShopChain.Infrastructure/Migrations/"
    click VnService "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Infrastructure/ExternalServices/VnAddressServices/VnAddressApiService.cs"
    click DI_Infra "https://github.com/leyen1403/shopchain/blob/main/ShopChain.Infrastructure/DependencyInjection.cs"

    click ProdTests "https://github.com/leyen1403/shopchain/blob/main/ShopChain.UnitTest/Entities/ProductTests.cs"
    click MSTestCfg "https://github.com/leyen1403/shopchain/blob/main/ShopChain.UnitTest/MSTestSettings.cs"

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,color:#004085
    classDef application fill:#d4edda,stroke:#155724,color:#155724
    classDef core fill:#fff3cd,stroke:#856404,color:#856404
    classDef infrastructure fill:#ffe5b4,stroke:#cc7000,color:#cc7000
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef external fill:#f8f9fa,stroke:#6c757d,color:#6c757d
    classDef test fill:#f5c6cb,stroke:#721c24,color:#721c24
```
