# rymucong/onlinepollapp architecture

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

- Interactive diagram: https://gitdiagram.com/rymucong/onlinepollapp
- Repository: https://github.com/rymucong/onlinepollapp

## Overview

##### Main Components
- Presentation Layer: Represented by the Web API project (Presentations/T3H.Poll.WebApi). Its controllers, configuration options, models, and program startup code provide the interface (Swagger endpoints and API debugging) for client interactions.
- Application Layer: Implemented in the Core directory (Core/T3H.Poll.Application). It contains Commands, Queries, DTOs, Dispatchers, and Services (such as CrudService, UserService, etc.) that implement the application’s business logic. This layer uses patterns like CQRS (commands and queries) and the Mediator pattern through handlers.
- Domain Layer: Found in Core/T3H.Poll.Domain. It houses domain entities (like Poll, User, Roles, etc.), domain events, and constants. This area encapsulates the core business rules, invariants, and specifications.
- Infrastructure Layer: This layer is diverse. It includes:
- Persistence: Under Infrastructure/T3H.Poll.Persistence, with database context (CrmDbContext), repositories (for users, roles, and common settings), mapping configurations, and locking mechanisms (distributed locks).
- Identity: Infrastructure/T3H.Poll.Infrastructure/Identity which includes stores, password validation, and token providers.
- Interceptors, Logging, Swagger, HealthChecks, and additional cross-cutting functions are also part of Infrastructure.
- Additionally, the Infrastructure/libs directory includes external libraries used by the project.
- Cross-Cutting Concerns: Organized under CrossCuttingConcerns, providing Circuit Breaker implementations, exception handling, date/time providers, extension methods, and locking utilities.
- Data and Migration: The Data folder (simple JSON files like banks.json) and Presentations/T3H.Poll.Migration supply migration scripts and database initialization (seeding) required to set up the database.

##### Architectural Patterns and Notable Components
- CQRS Pattern: Emphasize how commands (like AddUpdatePollCommand, DeleteUserCommand) and queries (GetUserQuery, BaseSearchQuery) are dispatched through central dispatchers and handled by specific command/query handlers.
- Domain-Driven Design Elements: Separate Domain Entities and value objects encapsulate business rules; domain events (like EntityCreatedEvent) propagate state changes.
- Repository and Unit of Work Patterns: Illustrate how repository interfaces (IUserRepository, IRoleRepository) and the Unit of Work (IUnitOfWork) in the Persistence layer abstract database operations.
- Cross-Cutting Concerns: Incorporate shared components such as CircuitBreaker, Exception Handling, Logging (using interceptors, ActivityEnricher), and Notifications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        P1["Web API - FDS.CRM.WebApi"]:::presentation
    end

    subgraph "Application Layer"
        A1["Business Logic (CQRS)"]:::application
    end

    subgraph "Domain Layer"
        D1["Domain Entities & Events"]:::domain
    end

    subgraph "Infrastructure Layer"
        I1["Persistence"]:::infrastructure
        I2["Identity & Security"]:::infrastructure
        I3["Interceptors"]:::infrastructure
        I4["Logging"]:::infrastructure
    end

    subgraph "Cross-Cutting Concerns"
        CC1["Shared Utilities"]:::crosscutting
    end

    subgraph "Data and Migration"
        M2["Data Files"]:::infrastructure
        M1["Migration Project - Data Seeding"]:::infrastructure
    end

    subgraph "External Systems"
        DB1["Database / SQL Server"]:::database
    end

    %% Connections between layers
    P1 -->|"API_calls"| A1
    A1 -->|"Dispatches"| D1
    A1 -->|"Repository_calls"| I1
    A1 -->|"Auth_Token"| I2
    A1 -->|"Uses"| I3
    A1 -->|"Uses"| I4
    I1 -->|"DbContext_ops"| DB1
    M1 -->|"Migration"| DB1
    M2 -->|"Seeds_data"| M1

    %% Cross-Cutting Concerns interaction with all layers (dotted lines)
    CC1 --- P1
    CC1 --- A1
    CC1 --- D1
    CC1 --- I1
    CC1 --- I2
    CC1 --- I3
    CC1 --- I4

    %% Click Events
    click P1 "https://github.com/rymucong/onlinepollapp/blob/main/Presentations/T3H.Poll/T3H.Poll.WebApi"
    click A1 "https://github.com/rymucong/onlinepollapp/blob/main/Core/T3H.Poll.Application"
    click D1 "https://github.com/rymucong/onlinepollapp/blob/main/Core/T3H.Poll.Domain"
    click I1 "https://github.com/rymucong/onlinepollapp/blob/main/Infrastructure/T3H.Poll.Persistence"
    click I2 "https://github.com/rymucong/onlinepollapp/tree/main/Infrastructure/T3H.Poll.Infrastructure/Identity"
    click I3 "https://github.com/rymucong/onlinepollapp/tree/main/Infrastructure/T3H.Poll.Infrastructure/Interceptors"
    click I4 "https://github.com/rymucong/onlinepollapp/tree/main/Infrastructure/T3H.Poll.Infrastructure/Logging"
    click CC1 "https://github.com/rymucong/onlinepollapp/blob/main/CrossCuttingConcerns/T3H.Poll.CrossCuttingConcerns"
    click M1 "https://github.com/rymucong/onlinepollapp/blob/main/Presentations/T3H.Poll.Migration"
    click M2 "https://github.com/rymucong/onlinepollapp/blob/main/Data/banks.json"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef application fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef domain fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef infrastructure fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef crosscutting fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef database fill:#e2e3e5,stroke:#d6d8db,stroke-width:2px;
```
