# marcosnasc/aspnet-webapi architecture

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

- Interactive diagram: https://gitdiagram.com/marcosnasc/aspnet-webapi
- Repository: https://github.com/marcosnasc/aspnet-webapi

## Overview

##### Main Components
- API Layer (Ecommerce.API)
- Includes controllers (e.g., MainController, AuthController, ProductsController, SuppliersController, etc.), configuration files, middleware, DTOs, and versioned API subfolders (V1, V2).
- Essential configurations (e.g., dependency injection, Swagger configurations, DbContext, Identity) which suggest a RESTful interface and use of middleware and auto-mapping.
- Business Logic Layer (Ecommerce.BLL)
- Contains entities (Product, Supplier, Address), validations, notifications, and service implementations.
- Interfaces outlining repository and service contracts.
- Data Access Layer (Ecommerce.DAL)
- Focuses on the database context (EcommerceDBContext), repository implementations, mappings (e.g., Entity to DTO mapping for Product, Address, Supplier), and migrations for schema updates.
- External Dependencies and Services
- Although not explicitly shown beyond migrations and configurations, the DAL likely interacts with an underlying database. Also, Swagger configurations in the API suggest documentation and testing via Sentinel tools.

##### Relationships and Interactions
- The API layer receives HTTP requests (incoming through controllers) that then call into the BLL.
- The BLL performs business rules, validations, and orchestrates the core logic by invoking the necessary services.
- The services in the BLL access the DAL for data persistence and retrieval through repository interfaces.
- Configurations (dependency injection, database context setups, middleware for handling exceptions, security, etc.) are shared between the layers to enforce consistency.
- Versioning (V1 vs. V2) in controllers indicates a strategy for evolving the API endpoints while maintaining backward compatibility.

##### Architectural Patterns and Design Principles
- Layered (n-tier) architecture separating API, business logic, and data access, promoting separation of concerns.
- Dependency Injection (as indicated by DependencyInjectionConfig) ensuring loose coupling between components.
- Use of Data Transfer Objects (DTOs) for handling input/output in the API.
- Validation pattern integrated at the business logic layer to ensure data consistency before being passed to the data layer.
- Database migrations and mapping files for evolving the database schema in a controlled manner.
- Versioned endpoints for managing API evolution.

##### Final Reminders
- Avoid oversimplification – ensure that each major folder/component (e.g., the separation between API configurations, controllers, business logic, and data access) is well represented.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "API Layer"
        API_Main("Controllers"):::api
        API_V1("V1 Controllers"):::api
        API_V2("V2 Controllers"):::api
        API_Config("Configurations & Middleware"):::api
        API_DTO("DTOs"):::api
    end

    subgraph "Business Logic Layer"
        BLL_Entities("Entities"):::bll
        BLL_Interfaces("Interfaces"):::bll
        BLL_Notifications("Notifications"):::bll
        BLL_Validations("Validations"):::bll
        BLL_Services("Services"):::bll
    end

    subgraph "Data Access Layer"
        DAL_Context("Database Context"):::dal
        DAL_Mappings("Mappings"):::dal
        DAL_Repository("Repository Implementations"):::dal
        DAL_Migrations("Migrations"):::dal
    end

    DB(("Database")):::external

    %% Data Flow
    API_Main -->|"calls"| BLL_Services
    API_V1 -->|"calls"| BLL_Services
    API_V2 -->|"calls"| BLL_Services

    BLL_Services -->|"queries"| DAL_Repository
    DAL_Repository -->|"uses"| DAL_Context
    DAL_Context -->|"connects"| DB

    %% Response Flow
    DB -->|"responds"| DAL_Context
    DAL_Context -->|"returns"| DAL_Repository
    DAL_Repository -->|"sendsData"| BLL_Services
    BLL_Services -->|"responds"| API_Main
    BLL_Services -->|"responds"| API_V1
    BLL_Services -->|"responds"| API_V2

    %% Click Events
    click API_Main "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.API/Controllers"
    click API_V1 "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.API/V1/Controllers"
    click API_V2 "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.API/V2/Controllers"
    click API_Config "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.API/Configurations"
    click API_DTO "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.API/DTOs"
    click BLL_Entities "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.BLL/Entities"
    click BLL_Interfaces "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.BLL/Interfaces"
    click BLL_Notifications "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.BLL/Notifications"
    click BLL_Validations "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.BLL/Validations"
    click BLL_Services "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.BLL/Services"
    click DAL_Context "https://github.com/marcosnasc/aspnet-webapi/blob/master/src/Ecommerce.DAL/Context/EcommerceDBContext.cs"
    click DAL_Mappings "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.DAL/Mappings"
    click DAL_Repository "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.DAL/Repository"
    click DAL_Migrations "https://github.com/marcosnasc/aspnet-webapi/tree/master/src/Ecommerce.DAL/Migrations"

    %% Styles
    classDef api fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef bll fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef dal fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
```
