# amitpnk/clean-architecture-asp.net-core architecture

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

- Interactive diagram: https://gitdiagram.com/amitpnk/clean-architecture-asp.net-core
- Repository: https://github.com/amitpnk/clean-architecture-asp.net-core

## Overview

##### And Illustrate the Main Components
- Presentation Layer:
- CleanArch.Api: Contains the Web API with controllers (e.g., AccountController, CategoryController, EventsController) and middleware (e.g., exception handling, API versioning, Swagger).
- CleanArch.App: A Blazor-based UI (containing Pages, Shared components, CSS, etc.).
- Application Layer:
- CleanArch.Application: Holds the core business logic, CQRS implementation with Commands, Queries, Validators, and Handlers.
- Contains the service registration (e.g., ApplicationServiceRegistration) and exception definitions.
- Domain Layer:
- CleanArch.Domain: Contains the core business entities, value objects, enums, and domain services that represent the business rules.
- Infrastructure Layer:
- CleanArch.Infrastructure: Provides implementations for cross-cutting services such as Email service (MailKit), CSV file export, identity management, and utility functionalities.
- CleanArch.CrossCuttingConcerns: Contains shared middleware, identity interfaces, OS services, and other utilities.
- Persistence Layer:
- CleanArch.Persistence: Implements Entity Framework Core Code First details including DbContexts (ApplicationDbContext, AuditableContext, IdentityContext), migrations, seeding, and repositories that adhere to repository and unit-of-work patterns.
- Testing:
- Multiple test projects (Unit tests, Integration tests) cover Application features, Persistence interactions, and common mocks.

##### Establish Relationships and Data Flow
- The Presentation Layer (both API and UI) calls into the Application Layer.
- The Application Layer triggers business logic and communicates with the Domain for core business rules.
- The Application Layer then interacts with the Persistence Layer (via repositories) and Infrastructure (for services like email and file export).
- Cross-cutting concerns, such as authentication (JWT), logging (Serilog), exception handling, and middleware, interact with multiple layers.
- How testing projects relate to the corresponding layers to ensure quality and integration.

##### Architectural Patterns & Design Principles
- Clean Architecture: Emphasize the concentric layers with Domain at the core and Infrastructure as an outer layer.
- CQRS & Mediator: Indicate the separation of commands and queries within the Application layer.
- Repository and Unit of Work: Note how data access abstraction is implemented in Persistence.
- Optionally, represent cross-cutting utilities (e.g., Automapper, Fluent validation, and logging) as supporting blocks that interface with multiple components.

##### Relevant Technologies and Frameworks
- .NET Core, ASP.NET Core for backend RESTful API.
- Blazor for the UI.
- Entity Framework Core for database interactions.
- Azure for deployment (as indicated in the deploy scripts and CI/CD files).
- Testing frameworks such as NUnit.
- Continuous integration elements by referencing the CI/CD pipeline configuration files (CircleCI, GitHub workflows).

##### Detail and Clarity
- Every layer and its role are captured as per the clean architecture principles.
- Incorporate deployment guides where necessary (for Azure deployments) or CI/CD configurations to show how the software transitions from code commit to production.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        API["CleanArch.Api – Web API"]:::presentation
        UI["CleanArch.App – Blazor UI"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        APP["CleanArch.Application – CQRS Handlers, Validators, Service Registration"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DOM["CleanArch.Domain – Core Business Entities, Value Objects, Domain Services"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        INF1["CleanArch.Infrastructure – Email, CSV, Identity, OS Services"]:::infrastructure
        INF2["CleanArch.CrossCuttingConcerns – Middleware, Identity Interfaces, OS Services"]:::infrastructure
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        PER["CleanArch.Persistence – DbContexts, Migrations, Repositories (EF Core)"]:::persistence
    end

    %% Testing Projects
    subgraph "Testing"
        TEST["Test Projects – Unit & Integration Tests"]:::testing
    end

    %% Inter-layer Relationships
    UI -->|"callsAPI"| API
    API -->|"invokes"| APP
    APP -->|"executesCQRS"| DOM
    APP -->|"accesses"| PER
    APP -->|"leverages"| INF1
    APP -->|"leverages"| INF2
    API -->|"integratesMiddleware"| INF2

    %% Testing Relationships
    TEST -->|"validates"| APP
    TEST -->|"validates"| PER
    TEST -->|"validates"| INF1
    TEST -->|"validates"| DOM

    %% Click Events
    click API "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.Api"
    click UI "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.App"
    click APP "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.Application"
    click DOM "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.Domain"
    click INF1 "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.Infrastructure"
    click INF2 "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.CrossCuttingConcerns"
    click PER "https://github.com/amitpnk/clean-architecture-asp.net-core/blob/develop/src/CleanArch.Persistence"
    click TEST "https://github.com/amitpnk/clean-architecture-asp.net-core/tree/develop/test"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef application fill:#D4E6F1,stroke:#1F618D,stroke-width:2px;
    classDef domain fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef infrastructure fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef persistence fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef testing fill:#FDEDEC,stroke:#922B21,stroke-width:2px;
```
