# kevindockx/aspnetcore6webapifundamentals architecture

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

- Interactive diagram: https://gitdiagram.com/kevindockx/aspnetcore6webapifundamentals
- Repository: https://github.com/kevindockx/aspnetcore6webapifundamentals

## Overview

##### Main Components
- API Layer (Controllers): Contains all controllers such as AuthenticationController, CitiesController, FilesController, and PointsOfInterestController. This layer exposes API endpoints.
- Service Layer: Houses service classes (e.g., CityInfoRepository, CloudMailService, LocalMailService) that encapsulate business logic and interact with the data repository.
- Data Access Layer: Contains the DbContext (CityInfoContext) and Entities (City, PointOfInterest) that represent the database schema.
- Data Transfer Objects (DTOs) & Profiles: Models for transferring data (e.g., CityDto, PointOfInterestDto, etc.) and AutoMapper profiles (CityProfile, PointOfInterestProfile) that map between entities and DTOs.
- Migrations & Configuration: Database migrations and configuration files (appsettings.json with various environment settings) that help manage and configure persistence.

##### Relationships and Interactions
- The Controllers interact with the Service Layer to handle API requests. For example, when a request is received to fetch city information, a controller calls into the CityInfoRepository via its interface (ICityInfoRepository).
- The Service Layer uses the DbContext (via EF Core) to perform CRUD operations on the underlying database and may also trigger mail notifications using the MailService abstractions.
- Data returned by the DbContext is mapped to DTOs with AutoMapper (using defined profiles) before being sent back as responses.
- Authentication is managed by specific controllers (e.g., AuthenticationController) where necessary, though the focus here remains on the API CRUD functionality.
- The separation via “Models”, “Entities”, and “Profiles” highlights the distinct responsibilities – data representation vs. business entities vs. mapping logic.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Controllers, Services, and Data Access layers are clearly maintained in separate directories.
- Repository Pattern: The interface ICityInfoRepository and its implementation abstract data access.
- Dependency Injection: ASP.NET Core’s DI container is leveraged (services like CloudMailService/LocalMailService are registered) to inject dependencies.
- DTO Pattern with AutoMapper: Distinguishes between the objects used to transfer data to clients and the internal domain entities persisted in the database.
- Environment-based Configuration: Multiple appsettings files (e.g., Development and Production) indicate environment-specific configurations.

##### Relevant Technologies, Frameworks, and Libraries
- ASP.NET Core 6 – The main framework for creating the Web API.
- Entity Framework Core – Used for data access and migrations.
- AutoMapper – For mapping between entities and DTOs.
- SQL Database – Represented by CityInfo.db and migrations, though the specific DBMS isn’t explicitly mentioned.
- API Documentation/Versioning Tools – Likely integrated as part of the course fundamentals (even though not detailed here, it’s a common practice).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client Request"]:::client

    subgraph "API Layer (Controllers)"
        ctrlAuth["AuthenticationController"]:::controllers
        ctrlCities["CitiesController"]:::controllers
        ctrlFiles["FilesController"]:::controllers
        ctrlPOI["PointsOfInterestController"]:::controllers
    end

    subgraph "Service Layer"
        SRepo["CityInfoRepository"]:::services
        SCloud["CloudMailService"]:::services
        SLocal["LocalMailService"]:::services
        SICity["ICityInfoRepository"]:::services
        SIMail["IMailService"]:::services
        SPagination["PaginationMetadata"]:::services
    end

    subgraph "Data Access Layer"
        DAContext["CityInfoContext"]:::dataAccess
        DACity["City"]:::dataAccess
        DAPOI["PointOfInterest"]:::dataAccess
    end

    subgraph "DTO & AutoMapper"
        M_CityDto["CityDto"]:::dto
        M_CityWOPOI["CityWithoutPointsOfInterestDto"]:::dto
        M_POI["PointOfInterestDto"]:::dto
        M_POICreate["PointOfInterestForCreationDto"]:::dto
        M_POIUpdate["PointOfInterestForUpdateDto"]:::dto
        MA_CityProfile["CityProfile"]:::automapper
        MA_POIProfile["PointOfInterestProfile"]:::automapper
    end

    subgraph "Migrations & Configuration"
        MIG["Migrations"]:::config
        APP["appsettings.json"]:::config
        APPDev["appsettings.Development.json"]:::config
        APPProd["appsettings.Production.json"]:::config
    end

    %% Flow: Client to Controller
    A -->|"HTTP_Request"| ctrlCities

    %% Controllers call Service Layer (representative flow)
    ctrlCities -->|"calls"| SRepo

    %% Service Layer interactions
    SRepo -->|"CRUD_operations"| DAContext
    SRepo ---|"uses"| SCloud
    SRepo ---|"uses"| SLocal

    %% Data Access to AutoMapper Mapping Flow
    DAContext -->|"returns_data"| MA_CityProfile
    MA_CityProfile -->|"maps_to"| M_CityDto
    M_CityDto -->|"response"| ctrlCities

    %% Configuration and Migrations impacting Data Access
    APP ---|"configures"| DAContext
    APPDev ---|"configures"| DAContext
    APPProd ---|"configures"| DAContext
    MIG ---|"migration"| DAContext

    %% Styles
    classDef client fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px;
    classDef controllers fill:#BBDEFB,stroke:#64B5F6,stroke-width:2px;
    classDef services fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef dataAccess fill:#FFCDD2,stroke:#E57373,stroke-width:2px;
    classDef dto fill:#F0F4C3,stroke:#9E9D24,stroke-width:2px;
    classDef automapper fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px;
    classDef config fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;

    %% Click Events for Controllers
    click ctrlAuth "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Controllers/AuthenticationController.cs"
    click ctrlCities "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Controllers/CitiesController.cs"
    click ctrlFiles "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Controllers/FilesController.cs"
    click ctrlPOI "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Controllers/PointsOfInterestController.cs"

    %% Click Events for Service Layer
    click SRepo "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/CityInfoRepository.cs"
    click SCloud "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/CloudMailService.cs"
    click SLocal "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/LocalMailService.cs"
    click SICity "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/ICityInfoRepository.cs"
    click SIMail "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/IMailService.cs"
    click SPagination "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Services/PaginationMetadata.cs"

    %% Click Events for Data Access Layer
    click DAContext "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/DbContexts/CityInfoContext.cs"
    click DACity "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Entities/City.cs"
    click DAPOI "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Entities/PointOfInterest.cs"

    %% Click Events for DTOs
    click M_CityDto "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Models/CityDto.cs"
    click M_CityWOPOI "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Models/CityWithoutPointsOfInterestDto.cs"
    click M_POI "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Models/PointOfInterestDto.cs"
    click M_POICreate "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Models/PointOfInterestForCreationDto.cs"
    click M_POIUpdate "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Models/PointOfInterestForUpdateDto.cs"

    %% Click Events for AutoMapper Profiles
    click MA_CityProfile "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Profiles/CityProfile.cs"
    click MA_POIProfile "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/Profiles/PointOfInterestProfile.cs"

    %% Click Events for Migrations & Configuration
    click MIG "https://github.com/kevindockx/aspnetcore6webapifundamentals/tree/main/CityInfo.API/Migrations"
    click APP "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/appsettings.json"
    click APPDev "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/appsettings.Development.json"
    click APPProd "https://github.com/kevindockx/aspnetcore6webapifundamentals/blob/main/CityInfo.API/appSettings.Production.json"
```
