# huuquangg/clean_architecture-case_study architecture

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

- Interactive diagram: https://gitdiagram.com/huuquangg/clean_architecture-case_study
- Repository: https://github.com/huuquangg/clean_architecture-case_study

## Overview

##### Project Type and Purpose
- The project is a web API application built around managing parking slots. It is structured as a layered (or clean) architecture where you have clearly separated components: APIs (presentation layer), Entities (domain models), Usecase (business logic) and Infrastructure (data access, repositories, and database management).

##### File Structure
- The top-level solution file (ParkingSlot.sln) and the separate projects indicate a modular approach.
- Key directories are:
- ParkingSlot.APIs: Contains controllers (SlotController.cs), the main Program.cs file, and configuration files (appsettings.json). It acts as the presentation layer exposing endpoints.
- ParkingSlot.Entities: Holds the core domain model (Slot.cs) representing the fundamental data structure.
- ParkingSlot.Usecase: Includes business logic (SlotManager.cs) and interface definitions (ISlotRepository.cs) that drive the application's operations.
- ParkingSlot.Infrastructure: Contains the implementations supporting the domain – such as the database context (Models/DatabaseContext.cs), an in-memory repository (InMemISlotRepository.cs), the database file (Database/parkingslot.db) and database migration scripts (Version/1_0_0/up.sql and down.sql). This layer is responsible for data persistence and integration with external storage.
- This structure clearly follows a separation of concerns, ensuring that each layer has distinct responsibilities.

##### README for Additional Insights
- Although the README content provided is empty, the naming and structure indicate this is a modular application where each project supports a different layer of the overall system. Therefore, focus on representing interactions between these layers.

a. Main Components:
- Presentation Layer: ParkingSlot.APIs (with SlotController handling HTTP requests).
- Business Logic/Usecase Layer: ParkingSlot.Usecase (SlotManager, ISlotRepository interface).
- Domain Layer: ParkingSlot.Entities (Slot.cs, the domain model).
- Data Access/Infrastructure Layer: ParkingSlot.Infrastructure (DatabaseContext, InMemISlotRepository, migration scripts, and the actual database file).
b. Relationships and Interactions:
- The API layer receives client requests and directs them to controllers (e.g., SlotController).
- Controllers invoke the Usecase layer (via SlotManager) to apply business rules.
- The Usecase layer interacts with the Repository interface (ISlotRepository) that is implemented in the Infrastructure layer.
- The Infrastructure layer handles data persistence using the in-memory repository or database (parkingslot.db) along with migration support managed through versioning.
- Data flows from the Presentation layer to the Business layer, then to the Infrastructure layer and back, ensuring separation of responsibilities.
c. Important Architectural Patterns:
- Layered (or Clean) Architecture: Clear separation between presentation, business logic, domain, and infrastructure.
- Dependency Inversion: The domain and business logic depend on abstractions (like ISlotRepository) rather than concrete implementations.
- Data Migration and Versioning are managed in a dedicated subdirectory, ensuring controlled database evolution.
d. Technologies, Frameworks, or Libraries:
- ASP.NET Core is likely used for the API (Controller, Program.cs, appsettings.json).
- Entity Framework or an alternative ORM might be suspected given the database context, although the presence of an in-memory repository file implies a potential for testing or alternative storage strategies.
- SQLite could be inferred from the database file (parkingslot.db).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        E("Client Request"):::presentation
        A("Main Program"):::presentation
        B("SlotController"):::presentation
        C("Appsettings.json"):::presentation
        D("Appsettings.Development.json"):::presentation
    end

    %% Usecase / Business Logic Layer
    subgraph "Usecase Layer"
        F("SlotManager"):::usecase
        G("ISlotRepository"):::usecase
    end

    %% Domain Layer
    subgraph "Domain Layer"
        H("Slot Domain Model"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        I("InMemISlotRepository"):::infrastructure
        J("DatabaseContext"):::infrastructure
        K("parkingslot.db"):::database
        L("Migration Up"):::infrastructure
        M("Migration Down"):::infrastructure
    end

    %% Connections for Presentation Layer
    E -->|"initiates"| A
    A -->|"loads"| C
    A -->|"loads"| D
    A -->|"starts"| B

    %% Connections from Presentation to Usecase
    B -->|"calls"| F

    %% Connections within Usecase and Domain
    F -->|"executes business rules on"| H
    F -->|"depends on"| G

    %% Repository Implementation Relation
    G -.->|"implemented by"| I

    %% Infrastructure Data Access Flow
    I -->|"uses"| J
    J -->|"connects to"| K
    J -->|"applies"| L
    J -->|"applies"| M

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef usecase fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef domain fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef database fill:#FFD700,stroke:#333,stroke-width:2px;

    %% Click Events for Presentation Layer
    click B "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.APIs/Controller/SlotController.cs"
    click A "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.APIs/Program.cs"
    click C "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.APIs/appsettings.json"
    click D "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.APIs/appsettings.Development.json"

    %% Click Events for Domain Layer
    click H "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Entities/Slot.cs"

    %% Click Events for Usecase Layer
    click F "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Usecase/SlotManager.cs"
    click G "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Usecase/ISlotRepository.cs"

    %% Click Events for Infrastructure Layer
    click I "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Infrastructure/InMemISlotRepository.cs"
    click J "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Infrastructure/Models/DatabaseContext.cs"
    click K "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Infrastructure/Database/parkingslot.db"
    click L "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Infrastructure/Version/1_0_0/up.sql"
    click M "https://github.com/huuquangg/clean_architecture-case_study/blob/main/ParkingSlot.Infrastructure/Version/1_0_0/down.sql"
```
