# pedroventura235/basicwebapi architecture

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

- Interactive diagram: https://gitdiagram.com/pedroventura235/basicwebapi
- Repository: https://github.com/pedroventura235/basicwebapi

## Overview

##### Main Components
- Presentation Layer: Represented by the BasicWebApi folder where the API project resides. This layer handles HTTP requests (endpoints like Products, Users, Roles, and Personal) and configuration (in the Configurations directory such as database, logging, CORS, etc.).
- Application Layer: Found in the Application directory. It contains business logic, features (like Products commands and queries), caching, common interfaces, exception definitions, identity schemes (e.g., authentication and role management), and shared response structures.
- Domain Layer: Contained in the Domain directory. This includes the core business entities, base classes (for audit and soft deletion), and domain interfaces needed by the rest of the system.
- Infrastructure Layer: Located in the Infrastructure directory. It implements authentication (with integrations like KeyCloak), caching, logging, database persistence (repositories, context, migrations), and common startup/configuration utilities. It is used by both the Application and Presentation layers for concerns that interact with external systems or require concrete implementation.
- Additional Components: Utility and template configuration files (such as the .template.config directory), solution management files (.sln, docker-compose.yml), and build/deployment scripts.

##### Understand Relationships and Interactions
- The Presentation Layer (API) communicates directly with the Application layer which orchestrates business logic.
- The Application Layer coordinates with the Domain layer to enforce business rules and uses abstractions (interfaces) to interact with the Infrastructure layer.
- The Infrastructure layer encapsulates cross-cutting concerns such as database access (through repositories and DBContext), authentication/authorization (via Keycloak services), caching, and logging.
- Exception handling is centralized (in both Application exceptions and Infrastructure’s GlobalExceptionHandler) to ensure consistent error responses.
- The configuration files (in BasicWebApi/Configurations) provide the settings required by different layers (e.g., logger.json, security.json).

##### Architectural Patterns and Design Principles
- Clean Architecture / Onion Architecture: Separation of concerns is evident with distinct layers (Domain, Application, Infrastructure, Presentation) and dependency inversion—higher level modules (Application, Domain) do not depend on lower level implementation details.
- Repository Pattern: Used for data persistence, abstracting database interactions.
- Middleware and Pipeline Configurations: API requests go through configured middleware for logging, exception handling, and authentication.
- Code Generation: The project supports boilerplate generation for commands, queries, and DTOs to speed up development.
- Dependency Injection: Likely used throughout the layers to promote loose coupling between components.

##### Relevant Technologies, Frameworks, and Libraries
- .NET Core (ASP.NET Core API project in BasicWebApi)
- Keycloak for authentication and role management
- Serilog for logging (with specific configurations in Infrastructure/Logging)
- Entity Framework (for the Persistence layer, as indicated by migrations and ApplicationDbContext)
- Caching mechanisms integrated into the Infrastructure and Application layers
- Excel utilities for data import (Application and Infrastructure/ExcelHelper)

##### Elements
- Additional notation for external integrations such as Keycloak for authentication or external database connections.
- Configuration management and deployment artifacts like Docker Compose setups from the SlnFiles directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A1["API Endpoints"]:::presentation
        A2["API Configurations"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        B1["Features"]:::application
        B2["Exceptions"]:::application
        B3["Identity"]:::application
        B4["Common Interfaces"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        C1["Entities"]:::domain
        C2["Base Classes"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        D1["Keycloak Auth"]:::infrastructure
        D2["Global Exception Handler"]:::infrastructure
        D3["Logging Service"]:::infrastructure
        D4["Database Access"]:::infrastructure
        D5["Caching Service"]:::infrastructure
        D6["Excel Import Service"]:::infrastructure
    end

    %% Utility & Deployment
    subgraph "Utility & Deployment"
        E1["Template Configurations"]:::utility
        E2["Docker Compose & Scripts"]:::utility
    end

    %% Relationships
    A1 -->|"HTTP_Request"| B1
    B1 -->|"BusinessLogic"| C1
    B1 -->|"DataPersistence"| D4
    B1 -->|"CacheLookup"| D5
    B1 -->|"ExcelImport"| D6
    B3 -->|"Authenticate"| D1
    B2 -->|"HandleErrors"| D2
    B4 -->|"ExcelInterface"| D6
    A2 -->|"LoggerConfig"| D3
    C2 -.->|"supports"| C1

    %% Click Events
    click A1 "https://github.com/pedroventura235/basicwebapi/tree/master/BasicWebApi/Endpoints"
    click A2 "https://github.com/pedroventura235/basicwebapi/tree/master/BasicWebApi/Configurations"
    click B1 "https://github.com/pedroventura235/basicwebapi/tree/master/Application/Features"
    click B2 "https://github.com/pedroventura235/basicwebapi/tree/master/Application/Exceptions"
    click B3 "https://github.com/pedroventura235/basicwebapi/tree/master/Application/Identity"
    click B4 "https://github.com/pedroventura235/basicwebapi/tree/master/Application/Common/Interfaces"
    click C1 "https://github.com/pedroventura235/basicwebapi/tree/master/Domain/Entities"
    click C2 "https://github.com/pedroventura235/basicwebapi/tree/master/Domain/Base"
    click D1 "https://github.com/pedroventura235/basicwebapi/tree/master/Infrastructure/Identity/KeyCloak"
    click D2 "https://github.com/pedroventura235/basicwebapi/blob/master/Infrastructure/Exceptions/GlobalExceptionHandler.cs"
    click D3 "https://github.com/pedroventura235/basicwebapi/tree/master/Infrastructure/Logging"
    click D4 "https://github.com/pedroventura235/basicwebapi/tree/master/Infrastructure/Persistence"
    click D5 "https://github.com/pedroventura235/basicwebapi/tree/master/Infrastructure/Caching"
    click D6 "https://github.com/pedroventura235/basicwebapi/blob/master/Infrastructure/Common/ExcelHelper.cs"
    click E1 "https://github.com/pedroventura235/basicwebapi/blob/master/.template.config"
    click E2 "https://github.com/pedroventura235/basicwebapi/tree/master/SlnFiles"

    %% Styles
    classDef presentation fill:#FFCCCC,stroke:#CC0000,stroke-width:2px;
    classDef application fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef infrastructure fill:#FFFF99,stroke:#B8860B,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
