# alondevcreator/clean-architecture architecture

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

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

## Overview

##### Project Type and Purpose
- This is a .NET “clean-architecture” template for a backend web API that implements a simple reminder/subscription service.
- It’s a layered monolithic application: presentation (API), application (use-case/business logic), domain (entities/events), infrastructure (persistence, background services, security), and contracts (DTOs).

##### File Structure Highlights
- **src/CleanArchitecture.Api** – HTTP entry-point, Controllers, Program.cs, DependencyInjection.
- **src/CleanArchitecture.Application** – Use-case layer: Commands, Queries, Handlers, Behaviors (validation/authorization), Interfaces.
- **src/CleanArchitecture.Domain** – Core entities, value objects, domain events, invariants.
- **src/CleanArchitecture.Infrastructure** – EF Core DbContext, Repositories, Middleware for eventual consistency, background email service, JWT token generator/validator, policy enforcer.
- **tests/** – Unit tests (domain, application), subcutaneous tests (application+domain), integration tests (API+database).

##### Detail-Level Recommendations
- How DI wires up each layer (e.g., “Api → calls Application via MediatR”)
- How Domain Events are queued and processed after HTTP response
- “User Secrets / appsettings.json” configuration pointing to EmailSettings and JwtSettings

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client["REST Client / Postman"]:::external

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Middleware["ASP.NET Core Middleware & Routing"]:::frontend
        RemindersController["RemindersController"]:::frontend
        SubscriptionsController["SubscriptionsController"]:::frontend
        TokensController["TokensController"]:::frontend
        Program["Program.cs"]:::frontend
        DI["DependencyInjection.cs"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Mediator["MediatR"]:::application
        ValidationBehavior["ValidationBehavior"]:::application
        AuthorizationBehavior["AuthorizationBehavior"]:::application
        Handlers["Command/Query Handlers"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Entities["Entities (User, Subscription, Reminder)"]:::domain
        DomainEvents["Domain Events & EventQueue"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        AppDbContext["AppDbContext"]:::infra
        Repositories["Repositories"]:::infra
        ECMiddleware["EventualConsistencyMiddleware"]:::infra
        BackgroundService["ReminderEmailBackgroundService"]:::infra
        JwtTokenGenerator["JwtTokenGenerator"]:::infra
        PolicyEnforcer["PolicyEnforcer"]:::infra
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        Database[(Relational Database: SQLite)]:::external
        SMTP[(SMTP Email Server)]:::external
    end

    %% Connections
    Client -->|HTTP Request| Middleware
    Middleware --> RemindersController
    Middleware --> SubscriptionsController
    Middleware --> TokensController
    RemindersController -->|calls| Mediator
    SubscriptionsController -->|calls| Mediator
    TokensController -->|calls| Mediator

    Mediator --> ValidationBehavior
    ValidationBehavior --> AuthorizationBehavior
    AuthorizationBehavior --> Handlers

    Handlers --> Entities
    Handlers --> Repositories
    Repositories --> AppDbContext
    AppDbContext -->|SaveChanges intercept| DomainEvents
    DomainEvents --> ECMiddleware
    ECMiddleware -->|dispatch events| Handlers

    BackgroundService -->|queries| Database
    BackgroundService -->|sends email via FluentEmail| SMTP

    Handlers -->|uses| JwtTokenGenerator
    Handlers -->|uses| PolicyEnforcer

    Repositories --> Database

    %% Click Events
    click RemindersController "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Api/Controllers/RemindersController.cs"
    click SubscriptionsController "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Api/Controllers/SubscriptionsController.cs"
    click TokensController "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Api/Controllers/TokensController.cs"
    click Program "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Api/Program.cs"
    click DI "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Api/DependencyInjection.cs"
    click ValidationBehavior "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Application/Common/Behaviors/ValidationBehavior.cs"
    click AuthorizationBehavior "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Application/Common/Behaviors/AuthorizationBehavior.cs"
    click AppDbContext "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Infrastructure/Common/Persistence/AppDbContext.cs"
    click ECMiddleware "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Infrastructure/Common/Middleware/EventualConsistencyMiddleware.cs"
    click BackgroundService "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Infrastructure/Reminders/BackgroundServices/ReminderEmailBackgroundService.cs"
    click JwtTokenGenerator "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Infrastructure/Security/TokenGenerator/JwtTokenGenerator.cs"
    click PolicyEnforcer "https://github.com/alondevcreator/clean-architecture/blob/main/src/CleanArchitecture.Infrastructure/Security/PolicyEnforcer/PolicyEnforcer.cs"

    %% Styles
    classDef frontend fill:#cfe2f3,stroke:#6fa8dc,stroke-width:1px
    classDef application fill:#d9ead3,stroke:#93c47d,stroke-width:1px
    classDef domain fill:#fff2cc,stroke:#f1c232,stroke-width:1px
    classDef infra fill:#f9cb9c,stroke:#e69138,stroke-width:1px
    classDef external fill:#cccccc,stroke:#808080,stroke-width:1px
```
