# neozhu/cleanaspire architecture

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

- Interactive diagram: https://gitdiagram.com/neozhu/cleanaspire
- Repository: https://github.com/neozhu/cleanaspire

## Overview

##### Project Type and Purpose
- CleanAspire is a **.NET 9 Minimal API + Blazor WebAssembly PWA template** built on Clean Architecture principles.
- It provides a ready-to-use **full-stack** solution:
- A **Blazor WebAssembly** client (ClientApp/WebApp) with PWA support (offline caching, service workers).
- A **Minimal API** backend (CleanAspire.Api) hosting business logic via an Application layer.
- A layered architecture (AppHost, Application, Domain, Infrastructure, Migrators, ServiceDefaults).
- Integration with external services (Webpushr for push notifications, Minio for file storage, SendGrid for email, external OAuth providers).

##### File Structure
- Top-level solution (.sln) containing:
- **src/CleanAspire.Api** – Minimal API endpoints, OpenAPI, exception handlers, identity/email, Webpushr config.
- **src/CleanAspire.AppHost** – Host setup (Aspire), configuration (appsettings, logging).
- **src/CleanAspire.Application** – Business logic (commands/queries/event handlers), DTOs, validators, pipeline behaviors (caching, validation).
- **src/CleanAspire.Domain** – Core entities, value objects, domain events, interfaces.
- **src/CleanAspire.Infrastructure** – EF Core DbContext, persistence configurations, interceptors, file-upload services, DI registrations.
- **src/CleanAspire.ClientApp** – Blazor WASM PWA client, Kiota-generated HTTP client proxies, components, pages, services (offline, caching, navigation, push).
- **src/CleanAspire.WebApp** – Blazor Server–hosted version for SEO/SSR fallback.
- **src/Migrators** – Database migrations for MSSQL, PostgreSQL, SQLite.
- **tests/CleanAspire.Tests** – Endpoint/unit tests.
- **deploy/docker-compose.yml** – Docker setup for API, WebApp, Standalone.

##### README for Additional Insights
- Outlines Clean Architecture layering.
- Mentions: Minimal APIs, Scalar for OpenAPI documentation, Aspire for hosting, Kiota for client generation, PWA/offline (IndexedDB, Service Worker), Webpushr notifications, CI/CD workflows.

##### Detail
- Essential components (AppHost, Endpoints, Pipeline Behaviors, EF Interceptors).
- **Kiota** code-generation process from the API’s OpenAPI to the ClientApp.
- Offline flow: Client fallback to IndexedDB when offline.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (WASM PWA)" 
        direction TB
        BWA["Blazor WebAssembly Client"]:::frontend
        SW["Service Worker"]:::frontend
        IDB["IndexedDB (Offline Cache)"]:::frontend
        KIOTA["Kiota HTTP Client"]:::frontend
    end

    %% Server Layer
    subgraph "Server (Minimal API)"
        direction TB
        Host["AppHost (Aspire)"]:::backend
        API["Minimal API Endpoints"]:::backend

        subgraph "Application Layer"
            direction TB
            APP["Application"]:::backend
            PIPE["Pipeline Behaviors"]:::backend
            FEAT["Features (Commands/Queries)"]:::backend
        end

        subgraph "Domain Layer"
            direction TB
            DOM["Domain Entities & Events"]:::backend
        end

        subgraph "Infrastructure Layer"
            direction TB
            INF["Infrastructure"]:::infra
            PERS["Persistence (DbContext, Configs)"]:::infra
            SVC["Services (Minio, File, DateTime)"]:::infra
            DB["Database"]:::db
            MIG["Migrators"]:::db
            subgraph "External Integrations"
                direction TB
                WEBP["Webpushr Service"]:::infra
                SEND["SendGrid Email"]:::infra
                OAUTH["OAuth Providers"]:::infra
                MINIO["Minio Storage"]:::infra
            end
        end
    end

    %% CI/CD
    subgraph "CI/CD & Deployment"
        direction TB
        GH1["GitHub Actions: docker.yml"]:::ci
        GH2["GitHub Actions: dotnet.yml"]:::ci
        DC["Docker Compose"]:::ci
    end

    %% Flows
    BWA -->|HTTP/JSON| API
    API -->|MediatR| APP
    APP -->|uses| DOM
    APP -->|EF Core| PERS
    PERS -->|SQL| DB
    PERS -->|Migrations| MIG
    SVC -->|stores files| MINIO
    SVC -->|push| WEBP
    SVC -->|emails| SEND
    API -->|OAuth| OAUTH

    SW --> IDB
    BWA -->|Kiota from OpenAPI| KIOTA
    KIOTA --> API

    GH1 --> DC
    GH2 --> DC
    DC --> API
    DC --> WEBP
    DC --> MINIO
    DC --> SEND

    Host --> API

    %% Click Events
    click BWA "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.ClientApp"
    click KIOTA "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.ClientApp"
    click WEBP "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Api/Webpushr/WebpushrOptions.cs"
    click SEND "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Api/Identity/EmailSender.cs"
    click OAUTH "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Api/Identity/IdentityApiAdditionalEndpointsExtensions.cs"
    click MINIO "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Infrastructure/Configurations/MinioOptions.cs"
    click Host "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.AppHost"
    click API "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Api"
    click APP "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Application"
    click PIPE "https://github.com/neozhu/cleanaspire/tree/main/src/CleanAspire.Application/Pipeline"
    click FEAT "https://github.com/neozhu/cleanaspire/tree/main/src/CleanAspire.Application/Features"
    click DOM "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Domain"
    click INF "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.Infrastructure"
    click PERS "https://github.com/neozhu/cleanaspire/tree/main/src/CleanAspire.Infrastructure/Persistence"
    click SVC "https://github.com/neozhu/cleanaspire/tree/main/src/CleanAspire.Infrastructure/Services"
    click MIG "https://github.com/neozhu/cleanaspire/tree/main/src/Migrators"
    click GH1 "https://github.com/neozhu/cleanaspire/blob/main/.github/workflows/docker.yml"
    click GH2 "https://github.com/neozhu/cleanaspire/blob/main/.github/workflows/dotnet.yml"
    click DC "https://github.com/neozhu/cleanaspire/blob/main/deploy/docker-compose.yml"
    click SW "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.ClientApp"
    click IDB "https://github.com/neozhu/cleanaspire/blob/main/src/CleanAspire.ClientApp"

    %% Styles
    classDef frontend fill:#DCEEFB,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#D0F0C0,stroke:#228B22,stroke-width:1px
    classDef infra fill:#FFE5B4,stroke:#FF8C00,stroke-width:1px
    classDef db fill:#E0E0E0,stroke:#696969,stroke-width:1px
    classDef ci fill:#F0D9FF,stroke:#800080,stroke-width:1px
```
