# phuocleoceo/plc-base-asp architecture

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

- Interactive diagram: https://gitdiagram.com/phuocleoceo/plc-base-asp
- Repository: https://github.com/phuocleoceo/plc-base-asp

## Overview

##### Main Components
- Client/External Requestor – Represents API consumers (e.g., web/mobile clients) that send HTTP requests.
- Nginx Reverse Proxy – The configuration in the “.nginx” directory and the presence of a Dockerfile and docker-compose.yml suggest that Nginx is used for request routing.
- ASP.NET Core Application – This is the core – it is organized into:
– Base Layer (src/Base): contains common controllers, DTOs, error handling, filtering, and repositories.
– Features (src/Features): multiple feature modules such as Auth, AccessControl, Address, Event, Issue, Project, Payment, etc. Each represents a domain module with its own set of Controllers, DTOs, Entities, Repositories, and Services.
– Common & Shared Libraries (src/Common and src/Shared): these include EF Core DataContext, configurations, migrations, mapping utilities, logging, helpers (like JWT, Redis, AWS S3, etc.), and extensions to build the pipelines and service collections.
- Data Layer:
– EF Core DataContext (inside src/Common/Data): Manage database connections and migrations.
– Database (SQL Server or another relational DB – typically external or containerized as part of docker-compose).
- External Services/Infrastructures:
– Certificate handling module from src/Certificate.
– AWS S3, Redis, and other external integrations found in src/Shared/Helpers.
– Message queue/service bus (if applicable, as referenced by MessageQueueExtension in service collections).

##### Component Relationships and Data Flow
- Requests from the Client (browser/mobile) first hit the Nginx reverse proxy.
- Nginx forwards requests to the ASP.NET Core container hosting the API.
- Incoming requests travel through middleware (ErrorHandler, JWT authentication, SuccessHandler, etc.) that are defined in src/Middlewares and further configured by the pipeline extensions (found in src/Extensions/Pipelines).
- Requests are then routed by the proper controller within the appropriate Feature module.
- Each controller calls its corresponding service, which then uses repositories to perform CRUD operations via the EF Core DataContext.
- Data flows from the Data Layer (database) back through the repository to the service and finally out through the controller’s response.
- External services (e.g., sending mail, generating JWT tokens, or interacting with AWS S3) are invoked from the shared helpers or service extensions.

##### Architectural Patterns and Design Principles
- Modular Feature-based Architecture – Each domain concern (Auth, Address, Issue, etc.) is isolated in its own folder.
- Repository & Unit of Work Patterns – Abstract data access logic.
- Dependency Injection – Utilized in the service collections and pipeline configurations (see src/Extensions/ServiceCollections).
- Middleware Pipeline – Custom middleware for error handling, authentication, health checks, and swagger are configured.
- Dockerized Production Environment – The Dockerfile, docker-compose, and Nginx configuration illustrate containerization and effective request routing.
- EF Core Code-First Approach and Migrations – Database schema evolution is managed via EF Core migrations (src/Common/Data/Migrations).

##### Technologies & Frameworks
- ASP.NET Core (.NET 5/6/7 – based on your solution file and project files)
- EF Core (for ORM and migrations)
- Docker & Docker Compose (for containerization and environment setup)
- Nginx (as reverse proxy)
- Cshapier (for formatting) and Husky (for Git hooks)
- External libraries/plugins for JWT, AWS (S3, etc.), Redis, and external mail services

##### What
- Clear and descriptive labels for every component.
- Client → Nginx → ASP.NET Core (middleware) → Controllers → Services → Repositories → DataContext → Database.
- Annotations to note key technologies (e.g., “EF Core Code-First”, “Middleware Pipelines”, “Dependency Injection”) alongside each component.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Entities
    Client["Client/External Requestor"]:::client
    Nginx["Nginx Reverse Proxy"]:::nginx
    Client -->|"HTTPRequest"| Nginx

    %% Container hosting the ASP.NET Core Application
    Container["PLC BASE ASP Container"]:::container
    Nginx -->|"Forwards"| Container

    %% ASP.NET Core Application Subgraph
    subgraph "ASP.NET Core Application"
        MW["Middleware Pipeline"]:::middleware
        Base["Base Layer"]:::controller
        Features["Features Modules"]:::controller

        MW -->|"RoutesTo"| Base
        MW -->|"RoutesTo"| Features

        %% Controllers delegate to DI Extensions (represents Service/Repository Layer)
        Base -->|"Invokes"| DI[("DI Extensions")]:::serviceGroup
        Features -->|"Invokes"| DI

        %% DI Extensions comprises Service Collections & Pipeline Extensions
        subgraph "DI Extensions"
            SC["Service Collections"]:::service
            PE["Pipeline Extensions"]:::service
            SC --- PE
        end

        %% DI Extensions accesses Certificate Handling (auxiliary module)
        DI -->|"Integrates"| Cert["Certificate Handling"]:::cert

        %% Common & Shared Libraries used by controllers
        Common["Common & Shared Libraries"]:::common
        Base ---|"Uses"| Common
        Features ---|"Uses"| Common
    end
    Container -->|"Hosts"| MW

    %% Data Layer Subgraph
    subgraph "Data Layer"
        DataContext["EF Core DataContext"]:::data
        DB["Database (SQL Server)"]:::db
        DataContext -->|"CRUD"| DB
    end
    DI -->|"Accesses"| DataContext

    %% External Services Subgraph
    subgraph "External Services"
        S3["AWS S3 Helpers"]:::external
        Redis["Redis Helpers"]:::external
        Mail["Mail Helpers"]:::external
    end
    Common -->|"Calls"| S3
    Common -->|"Calls"| Redis
    Common -->|"Calls"| Mail

    %% Click Events
    click Nginx "https://github.com/phuocleoceo/plc-base-asp/blob/main/.nginx"
    click Container "https://github.com/phuocleoceo/plc-base-asp/tree/main/Dockerfile"
    click Container "https://github.com/phuocleoceo/plc-base-asp/blob/main/docker-compose.yml"
    click Base "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Base"
    click Features "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Features"
    click Common "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Common"
    click Common "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Shared"
    click MW "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Middlewares"
    click SC "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Extensions/ServiceCollections"
    click PE "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Extensions/Pipelines"
    click Cert "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Certificate"
    click DataContext "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Common/Data"
    click S3 "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Shared/Helpers/Amazon/S3"
    click Redis "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Shared/Helpers/Redis"
    click Mail "https://github.com/phuocleoceo/plc-base-asp/tree/main/src/Shared/Helpers/SendMail"

    %% Styles
    classDef client fill:#ffeb3b,stroke:#000,stroke-width:2px;
    classDef nginx fill:#03a9f4,stroke:#000,stroke-width:2px;
    classDef container fill:#cddc39,stroke:#000,stroke-width:2px;
    classDef middleware fill:#ff9800,stroke:#000,stroke-width:2px;
    classDef controller fill:#8bc34a,stroke:#000,stroke-width:2px;
    classDef service fill:#ffc107,stroke:#000,stroke-width:2px;
    classDef serviceGroup fill:#ffb300,stroke:#000,stroke-width:2px;
    classDef data fill:#9c27b0,stroke:#000,stroke-width:2px;
    classDef db fill:#e91e63,stroke:#000,stroke-width:2px;
    classDef common fill:#607d8b,stroke:#000,stroke-width:2px;
    classDef cert fill:#795548,stroke:#000,stroke-width:2px;
    classDef external fill:#673ab7,stroke:#000,stroke-width:2px;
```
