# nguyentanphatka/cleanarchitecture architecture

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

- Interactive diagram: https://gitdiagram.com/nguyentanphatka/cleanarchitecture
- Repository: https://github.com/nguyentanphatka/cleanarchitecture

## Overview

##### Main Project Type and Purpose
- Recognize that this is a full-stack, clean architecture solution template. It includes a Blazor WebAssembly client (the presentation layer), an ASP.NET Core Server (hosting the API and additional web services), and a strongly layered backend that is broken up into Application, Domain, and Infrastructure projects.
- Its purpose is to provide an enterprise-grade boilerplate that implements patterns like CQRS (commands/queries), repository/unit-of-work, mapping profiles, validators, and rich localization resources.

##### File Structure to Identify the Key Architectural Components
- The top-level “src” folder contains multiple projects including:
- Application: Houses business logic, use-case implementations (commands and queries), configurations, validators, mappings, requests/responses, and service interfaces.
- Domain: Contains the core domain entities, contracts, and enums.
- Infrastructure & Infrastructure.Shared: Contains data-access concerns, EF Core contexts, repository implementations, services (e.g., Audit, Mail, etc.), and database migrations.
- Client and Client.Infrastructure: Contains the Blazor WebAssembly front-end including UI pages, shared components, resource files for localization and state management. The “Client.Infrastructure” project covers concerns like authentication, HTTP interceptors, routing, and managers to communicate with the API.
- Server: Contains ASP.NET Core controllers (grouped by feature such as Identity, Catalog, Utilities), middleware, signalR hubs, Dockerfile and startup configuration.
- Shared: Contains common utilities, helpers, constants, and wrappers (for handling responses, pagination, etc.)
- Notice also the presence of docker-compose files and related Docker configuration files, indicating that this solution is container-friendly.

##### Major Components and Layers
- Presentation Layer:
- Client (Blazor WebAssembly with MudBlazor Components)
- Client.Infrastructure (Communication managers, Authentication handlers)
- Server/API Layer:
- ASP.NET Core “Server” project with Controllers organized by feature areas (Identity, Catalog, Communication, Utilities, etc.)
- SignalR Hub for real-time communication
- API Endpoints for Blazor client calls
- Application Layer:
- “src/Application”: Implements business rules using CQRS (commands, queries) and validations.
- Service Interfaces and mapping profiles (AutoMapper configuration)
- Domain Layer:
- “src/Domain”: Contains business entities, contracts (interfaces like IEntity, IAuditableEntity), and enums defining core domain types.
- Infrastructure/Data Access Layer:
- “src/Infrastructure” & “src/Infrastructure.Shared”: Implements repository patterns, EF Core contexts (e.g., BlazorHeroContext), migrations, and configuration classes.
- Services to support external integrations like SMTP/SendGrid for mail, storage providers, and other utilities.
- Shared/Common Layer:
- “src/Shared”: Provides common constants, models, wrappers, and settings which are used across the solution.

##### Relationships and Data Flow
- The Blazor client interacts with the ASP.NET Core API (Server) via RESTful endpoints and real-time communication via SignalR.
- The Server controllers then use the Application layer to process requests (via commands and queries) and enforce business rules.
- The Application layer, in turn, calls into the Infrastructure layer (through repository interfaces and unit-of-work implementations) to manipulate data or fetch domain objects.
- The Domain layer represents the core business model and is used by both the Application and Infrastructure layers.
- Shared components provide utilities like error wrapping, pagination, and localizations across multiple layers.
- Docker and deployment configurations form the outer layer, ensuring that the entire solution can be containerized and deployed consistently.

##### Architectural Patterns and Design Principles to Highlight
- Clean (Layered) Architecture: With separation of concerns among Presentation, Application, Domain, and Infrastructure.
- CQRS Pattern: Visible in the Application layer with directories for Commands and Queries.
- Repository and Unit-of-Work Patterns in the Infrastructure layer.
- Dependency Injection: Usage throughout the solution, especially in controllers and services.
- Mapping Profiles and Validators: For translating between DTOs and domain entities, as well as ensuring data integrity.
- Localization/Resource Management: There is extensive use of resource files for multiple languages within Client and Server projects.
- Docker and Containerization: Noting docker-compose and Dockerfile configuration.

##### Summary of Essential Elements to Capture
- The separation of the solution into Presentation (Blazor Client), API/Server, Application (Business Logic via CQRS), Domain (Core Entities and Contracts), Infrastructure (Data Access & External Service Integrations), and Shared/Common utilities.
- How these layers interact with each other using defined interfaces and dependency inversion.
- Docker/Deployment boundaries and external dependencies where applicable.
- Annotations for key patterns like CQRS, Repository/Unit-of-Work, and Dependency Injection.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        PC["Blazor WebAssembly Client (MudBlazor UI)"]:::presentation
        CI["Client Communication & HTTP Interceptors"]:::presentation
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        S["ASP.NET Core Server (Controllers, SignalR, Middleware, Docker)"]:::server
    end

    %% Application Layer
    subgraph "Application Layer"
        A["Business Logic (CQRS, Commands/Queries, Mappings, Validators)"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D["Core Domain Entities & Contracts"]:::domain
    end

    %% Infrastructure/Data Access Layer
    subgraph "Infrastructure/Data Access Layer"
        I1["Primary Infrastructure (EF Core, Repositories, Unit-of-Work)"]:::infrastructure
        I2["Shared Infrastructure (Mail, Date/Time, etc.)"]:::infrastructure
    end

    %% Shared/Common Layer
    subgraph "Shared/Common Layer"
        SH["Common Utilities, Constants, Models, Wrappers"]:::shared
    end

    %% Docker/Deployment Configuration
    subgraph "Docker/Deployment Configuration"
        DC1["docker-compose.yml"]:::docker
        DC2["docker-compose.dcproj"]:::docker
        DC3["Dockerfile"]:::docker
    end

    %% Connections between layers
    PC -->|"REST&SignalR"| S
    CI -->|"HTTP/APIcalls"| S
    S -->|"Invokes"| A
    A -->|"OperatesOn"| D
    A -->|"UsesRepo"| I1
    A -->|"IntegratesWith"| I2
    A -->|"Utilizes"| SH
    I1 -->|"PersistsTo"| D

    %% Docker config connections to Server
    DC1 -->|"ComposeConfig"| S
    DC2 -->|"ComposeConfig"| S
    DC3 -->|"BuildConfig"| S

    %% Click Events
    click PC "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Client"
    click CI "https://github.com/nguyentanphatka/cleanarchitecture/blob/master/src/Client.Infrastructure"
    click S "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Server"
    click A "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Application"
    click D "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Domain"
    click I1 "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Infrastructure"
    click I2 "https://github.com/nguyentanphatka/cleanarchitecture/blob/master/src/Infrastructure.Shared"
    click SH "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Shared"
    click DC1 "https://github.com/nguyentanphatka/cleanarchitecture/blob/master/docker-compose.yml"
    click DC2 "https://github.com/nguyentanphatka/cleanarchitecture/blob/master/docker-compose.dcproj"
    click DC3 "https://github.com/nguyentanphatka/cleanarchitecture/tree/master/src/Server/Dockerfile"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef server fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef application fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef domain fill:#F5CBA7,stroke:#7D6608,stroke-width:2px;
    classDef infrastructure fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef shared fill:#FAD7A0,stroke:#9C640C,stroke-width:2px;
    classDef docker fill:#F5B7B1,stroke:#943126,stroke-width:2px;
```
