# stphnwlsh/cleanminimalapi architecture

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

- Interactive diagram: https://gitdiagram.com/stphnwlsh/cleanminimalapi
- Repository: https://github.com/stphnwlsh/cleanminimalapi

## Overview

##### Main Components
- Presentation Layer: This is the entry point of the application. It includes the Minimal API endpoint definitions (e.g., AuthorsEndpoints.cs, MoviesEndpoints.cs, ReviewsEndpoints.cs, VersionEndpoints.cs), configuration files (appsettings.json variants), filters (ValidationFilter, ValidationAttribute), and extension methods that set up the WebApplication. Represent this component as “Presentation” or “API Endpoints”.
- Application Layer: This component encapsulates the business logic and the domain. It contains domain entities (like Author, Movie, Review, Version), CQRS-based commands and queries (such as GetAuthorsQuery/GetAuthorsHandler, CreateReviewCommand/CreateReviewHandler, etc.), interfaces representing domain repositories (IAuthorsRepository, IMoviesRepository, IReviewsRepository), and layers for dependency injection. Represent this component as “Application” with submodules for domain entities, queries/commands, and business logic.
- Infrastructure Layer: This is responsible for data persistence and interacting with the database. It includes Entity Framework’s DbContext (MovieReviewsDbContext), repository implementations (EntityFrameworkMovieReviewsRepository), entity configurations and mappings (e.g., AuthorConfiguration, MovieMappingProfile), and supporting extensions. Represent it as “Infrastructure – Data Access”.

##### Relationships and Data Flow
- Client/External Consumer → Presentation Layer: Indicate that incoming HTTP requests hit the Minimal API endpoints.
- Application → Infrastructure: The business logic accesses persistence by calling repository interfaces, with actual implementations provided in the Infrastructure layer.
- Optional Feedback Loop: The response flows backward from Infrastructure (if data is retrieved) to Application (to process it) and then back to Presentation for delivery to the client.

##### Architectural Patterns/Design Principles
- Clean Architecture: Stress the separation of concerns by having distinct layers that only interact through well-defined contracts and dependency injection.
- CQRS Influence: Although not strictly enforced for all operations, the separation between commands (writes) and queries (reads) exists in the Application layer.
- Dependency Injection: Note that even though the Presentation layer references Infrastructure (primarily for dependency resolution), the key domain logic remains isolated.
- Repository Pattern and Entity Mapping: Used in the Infrastructure layer to abstract the data access, typically using EF Core with AutoMapper for object mapping.

##### Relevant Technologies and Frameworks
- .NET 8 SDK (building the application)
- Minimal APIs in ASP.NET Core (Presentation layer)
- Mediator Pattern using Mediatr (in Application layer)
- FluentValidation (for validation in the Application and Presentation)
- Entity Framework (data persistence in Infrastructure)
- Serilog for logging and Swashbuckle for OpenAPI specification generation

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["External_Client/Consumer"]:::external

    subgraph "Presentation Layer"
        PE["API Endpoints"]:::presentationCenter
        P1["AuthorsEndpoints"]:::apiEndpoint
        P2["MoviesEndpoints"]:::apiEndpoint
        P3["ReviewsEndpoints"]:::apiEndpoint
        P4["VersionEndpoints"]:::apiEndpoint
        PF["ValidationFilter"]:::apiEndpoint
        PC["Configuration (appsettings.json)"]:::apiEndpoint
        PE --> P1
        PE --> P2
        PE --> P3
        PE --> P4
        PE --> PF
        PE --> PC
    end

    subgraph "Application Layer"
        AL["Business Logic & Domain"]:::application
        A1["Author_Entity"]:::entity
        A2["Movie_Entity"]:::entity
        A3["Review_Entity"]:::entity
        A4["Version_Entity"]:::entity
        CQRS["CQRS_Commands/Queries/Handlers"]:::handlers
        DI["Dependency_Injection"]:::handlers
        AL --> A1
        AL --> A2
        AL --> A3
        AL --> A4
        AL --> CQRS
        AL --> DI
    end

    subgraph "Infrastructure – Data Access"
        ID["Data_Access_Layer"]:::infra
        DBContext["MovieReviewsDbContext"]:::db
        Repo["EntityFrameworkMovieReviewsRepository"]:::repository
        MP["Mapping_Profiles"]:::repository
        ID --> Repo
        ID --> DBContext
        ID --> MP
    end

    Database["MoviesReviews_Database"]:::database

    subgraph "Test Suites"
        T1["Application.Tests.Unit"]:::tests
        T2["Infrastructure.Tests.Integration"]:::tests
        T3["Presentation.Tests.Integration"]:::tests
    end

    Client -->|"HTTP_Request"| PE
    PE -->|"delegates"| CQRS
    CQRS -->|"calls_repository"| Repo
    Repo -->|"uses_DbContext"| DBContext
    DBContext -->|"persists_to"| Database

    T1 ---|"tests_AL"| AL
    T2 ---|"tests_Infra"| Repo
    T3 ---|"tests_Presentation"| PE

    click P1 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/Endpoints/AuthorsEndpoints.cs"
    click P2 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/Endpoints/MoviesEndpoints.cs"
    click P3 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/Endpoints/ReviewsEndpoints.cs"
    click P4 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/Endpoints/VersionEndpoints.cs"
    click PF "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/Filters/ValidationFilter.cs"
    click PC "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Presentation/appsettings.json"

    click A1 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Application/Authors/Entities/Author.cs"
    click A2 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Application/Movies/Entities/Movie.cs"
    click A3 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Application/Reviews/Entities/Review.cs"
    click A4 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Application/Versions/Entities/Version.cs"

    click DBContext "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Infrastructure/Databases/MoviesReviews/MovieReviewsDbContext.cs"
    click Repo "https://github.com/stphnwlsh/cleanminimalapi/blob/main/src/Infrastructure/Databases/MoviesReviews/EntityFrameworkMovieReviewsRepository.cs"
    click MP "https://github.com/stphnwlsh/cleanminimalapi/tree/main/src/Infrastructure/Databases/MoviesReviews/Mapping"

    click T1 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/tests/Application.Tests.Unit"
    click T2 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/tests/Infrastructure.Tests.Integration"
    click T3 "https://github.com/stphnwlsh/cleanminimalapi/blob/main/tests/Presentation.Tests.Integration"

    classDef external fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef presentationCenter fill:#d6eaf8,stroke:#2874a6,stroke-width:2px;
    classDef apiEndpoint fill:#fae5d3,stroke:#d35400,stroke-width:2px;
    classDef application fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef entity fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef handlers fill:#d5f5e3,stroke:#239b56,stroke-width:2px;
    classDef infra fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef db fill:#d1f2eb,stroke:#16a085,stroke-width:2px;
    classDef repository fill:#f5cba7,stroke:#e67e22,stroke-width:2px;
    classDef tests fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
    classDef database fill:#d6dbdf,stroke:#7f8c8d,stroke-width:2px;
```
