# imaanmzr/todoapp architecture

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

- Interactive diagram: https://gitdiagram.com/imaanmzr/todoapp
- Repository: https://github.com/imaanmzr/todoapp

## Overview

##### Main Components
- Frontend (ToDoApp.BlazorUI): The Blazor-based user interface for interacting with the ToDo application.
- API Layer (ToDoApp.Api): A .NET Web API that acts as the entry point for client requests. It contains controllers (e.g., AuthController, CategoriesController, UserTasksController) and middleware (ExceptionMiddleware).
- Application Layer (ToDoApp.Application): Implements business logic using the CQRS pattern. This includes commands, queries, validators, and mapping profiles. It also registers application services.
- Domain/Core (ToDoApp.Core): Contains domain entities, common models, and contracts for repositories and other operations.
- Identity (ToDoApp.Identity): Manages user authentication/authorization. It includes DbContext configuration, identity models (like ApplicationUser), and services related to authentication.
- Infrastructure (ToDoApp.Infrastructure): Provides auxiliary services such as email (EmailSender) and logging (LoggerAdapter). This also handles the registration of these services.
- Persistence (ToDoApp.Persistence): Uses EF Core for database access. It includes database context (ToDoDbContext), configurations for entities (Category, UserTask), migrations, and repository implementations.

##### Relationships and Interactions
- The Blazor UI communicates with the API layer via HTTP (via NSwag-generated clients or custom HTTP service clients) and relies on service contracts (see Contracts in BlazorUI).
- The API layer serves as a façade that invokes the Application layer using the CQRS pattern (for instance, calling command/query handlers through Mediator).
- The Application layer encapsulates business logic, mapping incoming requests into commands/queries and delegating data access to repositories (abstracted in the Core, implemented in Persistence).
- The Identity component is responsible for authentication/authorization; it interacts with the API layer (auth controllers) and Application layer (via service interfaces) to validate user credentials.
- The Infrastructure layer is used by the Application and API layers to send emails and provide logging functionality.
- The Persistence layer hosts the repositories that actually interact with the database using EF Core.

##### Architectural Patterns & Design Principles
- Clean Architecture: Separates concerns into different layers ensuring dependency inversion (e.g., the Application does not directly depend on Persistence or Infrastructure).
- CQRS Pattern: Commands and queries for both UserTask and Category management are organized into dedicated folders with command/query handlers and validators.
- Domain-Driven Design (DDD) aspects: With the Core project holding domain entities, including shared logic in BaseEntity classes.
- Use of MediatR: Implied for orchestrating command and query handling.
- AutoMapper: For mapping between domain entities and DTOs in both the API and Blazor UI layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["ToDoApp.BlazorUI<br/>(Blazor UI)"]:::ui
        API["ToDoApp.Api<br/>(Controllers & Middleware)"]:::api
    end

    subgraph "Business Logic Layer"
        APP["ToDoApp.Application<br/>(CQRS Command/Query Handlers,<br/>Mapping Profiles)"]:::app
    end

    subgraph "Domain & Identity"
        CORE["ToDoApp.Core<br/>(Domain Entities, Contracts)"]:::core
        ID["ToDoApp.Identity<br/>(Authentication Services, DbContext)"]:::id
    end

    subgraph "Infrastructure & Data Access"
        INF["ToDoApp.Infrastructure<br/>(Email, Logging)"]:::inf
        PERS["ToDoApp.Persistence<br/>(EF Core Database, Repositories)"]:::pers
    end

    UI -->|"HTTP_requests(NSwag)"| API
    API -->|"Invokes_Mediatr_Handlers"| APP
    APP -->|"RepositoryCalls"| PERS
    APP -->|"AuthOperations"| ID
    APP -->|"Uses_DomainLogic"| CORE
    API -->|"CallsFor_Logging_Email"| INF
    APP -->|"CrossCutting"| INF
    ID -->|"UtilizesContracts"| CORE

    click UI "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.BlazorUI"
    click API "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Api"
    click APP "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Application"
    click CORE "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Core"
    click ID "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Identity"
    click INF "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Infrastructure"
    click PERS "https://github.com/imaanmzr/todoapp/blob/master/ToDoApp.Persistence"

    classDef ui fill:#a8e6cf,stroke:#333,stroke-width:2px;
    classDef api fill:#dcedc1,stroke:#333,stroke-width:2px;
    classDef app fill:#ffd3b6,stroke:#333,stroke-width:2px;
    classDef core fill:#ffaaa5,stroke:#333,stroke-width:2px;
    classDef id fill:#ff8b94,stroke:#333,stroke-width:2px;
    classDef inf fill:#d4a5a5,stroke:#333,stroke-width:2px;
    classDef pers fill:#b5e6f0,stroke:#333,stroke-width:2px;
```
