# robhutton/blazor-clean-architecture architecture

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

- Interactive diagram: https://gitdiagram.com/robhutton/blazor-clean-architecture
- Repository: https://github.com/robhutton/blazor-clean-architecture

## Overview

##### Main Components
- UI/Presentation Layer:
- BlazingBlog.WebUI.Client: Contains Blazor client-side features and Razor components.
- BlazingBlog.WebUI.Server: Contains server-side Razor components, controllers, layouts, and routing (e.g., server routes, Blazor Server Pages). This layer handles both SSR and real-time updates (using SignalR) based on Blazor hosting model.
- Application Layer:
- BlazingBlog.Application: Contains business use cases organized by feature (such as Articles and Users). Each feature folder (for example, Articles, Authentication, Users) is structured as a vertical slice with its own set of commands, queries, handlers, and DTOs.
- CQRS Pattern is implemented here with interfaces for ICommand, IQuery and their respective Handlers, meaning commands (e.g., CreateArticleCommand) and queries (e.g., GetArticleByIdQuery) are dispatched via a Mediator.
- Domain Layer:
- BlazingBlog.Domain: Encompasses core business entities (such as Article and User) along with base abstractions (like Entity, Result) and repository interfaces (e.g., IArticleRepository, IUserRepository).
- Infrastructure Layer:
- BlazingBlog.Infrastructure: Implements actual functionality like ApplicationDbContext, repository implementations, authentication services, user services, and migration files. This layer bridges the Application/Domain with external systems (databases, identity providers).

##### Understand the Relationships and Data Flow
- UI/Presentation interacts with the Application Layer—typically through API endpoints (or direct Mediator calls in the case of Blazor Server) and Razor components that dispatch commands and queries.
- The Application layer uses the Domain entities (for business logic) while sending commands and queries through MediatR. Handlers here call the Infrastructure layer for persistence and external service interactions.
- The Infrastructure layer implements the repository interfaces and other external integrations (e.g., Authentication, Database Migrations) that the Application layer depends upon.

##### Architectural Patterns & Important Details
- Clean Architecture Layers: Explicitly show the flow from Presentation → Application → Domain → Infrastructure.
- Technologies: Include .NET 8, Blazor (both Server and Client/WebAssembly), MediatR, and possibly Mapster for object mapping; denote Entity Framework (or another ORM) for database interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI/Presentation Layer"
        A1["Blazor WebUI.Client"]
        A2["Blazor WebUI.Server"]
    end

    subgraph "Application Layer"
        B1["MediatR"]
        subgraph "Features"
            C1["Articles Feature"]
            C2["Authentication Feature"]
            C3["Users Feature"]
        end
    end

    subgraph "Domain Layer"
        D1["Article Domain"]
        D2["User Domain"]
    end

    subgraph "Infrastructure Layer"
        E1["Repositories"]
        E2["Database Context & Migrations"]
        E3["External Authentication"]
    end

    %% UI/Presentation -> Application (CQRS Dispatch)
    A1 -->|"DispatchCQRS"| B1
    A2 -->|"DispatchCQRS"| B1

    %% Application: MediatR routes commands/queries to features (vertical slices)
    B1 -->|"RouteCommands"| C1
    B1 -->|"RouteCommands"| C2
    B1 -->|"RouteCommands"| C3

    %% Application to Domain (Business Logic)
    C1 -->|"ApplyLogic"| D1
    C3 -->|"ApplyLogic"| D2

    %% Application to Infrastructure (Persistence & External Services)
    C1 -->|"PersistData"| E1
    C3 -->|"PersistData"| E1
    C2 -->|"AuthIntegration"| E3

    %% Infrastructure internal dependency
    E1 -->|"DBOperations"| E2

    %% Click Events
    click A1 "https://github.com/robhutton/blazor-clean-architecture/blob/master/BlazingBlog.WebUI.Client"
    click A2 "https://github.com/robhutton/blazor-clean-architecture/blob/master/BlazingBlog.WebUI.Server"
    click C1 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Application/Articles"
    click C2 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Application/Authentication"
    click C3 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Application/Users"
    click D1 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Domain/Articles"
    click D2 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Domain/Users"
    click E1 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Infrastructure/Repositories"
    click E2 "https://github.com/robhutton/blazor-clean-architecture/blob/master/BlazingBlog.Infrastructure"
    click E3 "https://github.com/robhutton/blazor-clean-architecture/tree/master/BlazingBlog.Infrastructure/Authentication"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef application fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef domain fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#FFB6C1,stroke:#000,stroke-width:2px;

    class A1,A2 presentation;
    class B1,C1,C2,C3 application;
    class D1,D2 domain;
    class E1,E2,E3 infrastructure;
```
