# phanthethanh0209/projectwebapi_flightdocssystem architecture

> Architecture diagram of the GitHub repository phanthethanh0209/projectwebapi_flightdocssystem, 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/phanthethanh0209/projectwebapi_flightdocssystem
- Repository: https://github.com/phanthethanh0209/projectwebapi_flightdocssystem

## Overview

- API Layer (Controllers): Represented by the Controllers folder (e.g., AuthController, FlightController, DocumentController, etc.). This is the entry point for client requests.
- Business/Service Layer: Captured in the Services folder. This layer encapsulates business logic such as managing flights, documents, users, and permissions.
- Data Access Layer: Comprised of the Repository folder (with GenericRepository and UnitOfWork implementations) along with the Data folder housing the DbContext (MyDBContext) and models.
- Domain Models and DTOs: The Data and DTO folders hold the domain models and data transfer objects respectively. These are critical for transferring data between the layers.
- Mapping Layer: The Mapper folder includes AutoMapper configuration which bridges the gap between DTOs and domain models.
- Authorization & Validation: Separate folders for Authorization (custom attributes and permission handlers) and Validation (using Fluent Validation) ensure security and integrity in data processing.
- Database: Highlight the use of Microsoft SQL Server as indicated in the appsettings.json and the Migrations folder (EF Core migrations).
- Configuration and Startup: The Program.cs file serves as the app’s bootstrap for configuration and dependency injection.

- Client Request → API Layer (Controllers): Mark how API controllers receive RESTful calls.
- Services → Repository: Illustrate the dependency whereby services use the repository pattern to fetch or persist data.
- Repository ↔ Database: Indicate the communication channel between repositories and the SQL Server database.
- AutoMapper/Mapping: Show how the mapping layer converts between DTOs and domain models on both incoming requests and outgoing responses.

##### Important Architectural Patterns and Principles
- Layered Architecture: Clearly separate presentation, business, and data access layers.
- Repository & Unit of Work: Emphasize the pattern used to abstract data operations.
- DTOs & AutoMapper: Show that data transformations are systematically handled by AutoMapper based mappers.
- JWT-Based Authentication: Indicate the use of JWT for securing endpoints.
- Code-First Entity Framework Core: Note that EF Core migrations are used to manage database versioning.
- File Upload Management: Represent the Upload folder which is used to store flight document files.

##### Technologies and Frameworks
- Microsoft SQL Server as the primary data storage.
- Use of Entity Framework Core for ORM, AutoMapper for object mapping, and Swagger for API documentation.
- Middleware (like JWT validation) used in the API pipeline.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client"
        Client["Client (Swagger/Postman)"]:::client
    end

    %% API Layer
    subgraph "API Layer (Controllers)"
        APICtrls["API Controllers"]:::api
    end

    %% Business/Service Layer
    subgraph "Business/Service Layer"
        Services["Services"]:::service
    end

    %% Mapping, Authorization & Validation Layer
    subgraph "Mapping & Security"
        Mapper["Mapping (AutoMapper)"]:::mapping
        Auth["Authorization & JWT"]:::auth
        Validation["Validation (Fluent)"]:::validation
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Repository["Repository (UnitOfWork)"]:::data
        DataModels["Data (DbContext & Domain Models)"]:::model
        DTO["DTOs"]:::dto
    end

    %% Database Layer
    subgraph "Database Layer"
        SQL["SQL Server Database"]:::database
    end

    %% File Upload Management
    subgraph "File Upload Management"
        Upload["Upload Folder"]:::upload
    end

    %% Configuration and Startup
    subgraph "Configuration"
        Config["Program.cs & AppSettings"]:::config
    end

    %% Connections
    Client -->|"RESTfulCall"| APICtrls
    APICtrls -->|"Delegates"| Services
    APICtrls -->|"Enforces"| Auth
    APICtrls -->|"Validates"| Validation
    Services -->|"Maps Data"| Mapper
    Services -->|"Invokes"| Repository
    Services -->|"Uses"| DTO
    Repository -->|"Accesses"| DataModels
    DataModels -->|"Persists"| SQL
    APICtrls -.->|"HandlesUploads"| Upload
    Config -->|"Bootstraps"| APICtrls
    Config -->|"Bootstraps"| Services
    Config -->|"Bootstraps"| Repository
    Config -->|"Bootstraps"| Auth
    Config -->|"Bootstraps"| Validation

    %% Click Events
    click APICtrls "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Controllers/"
    click Services "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Services/"
    click Repository "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Repository/"
    click DataModels "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Data/"
    click DTO "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/DTO/"
    click Mapper "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Mapper/"
    click Auth "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Authorization/"
    click Validation "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Validation/"
    click SQL "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/blob/main/appsettings.json"
    click Config "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/blob/main/Program.cs"
    click Upload "https://github.com/phanthethanh0209/projectwebapi_flightdocssystem/tree/main/Upload/"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:1px;
    classDef api fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef service fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef mapping fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef auth fill:#ffab91,stroke:#bf360c,stroke-width:2px;
    classDef validation fill:#ffccbc,stroke:#d84315,stroke-width:2px;
    classDef data fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef model fill:#ffecb3,stroke:#ff6f00,stroke-width:2px;
    classDef dto fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px;
    classDef database fill:#cfd8dc,stroke:#37474f,stroke-width:2px;
    classDef upload fill:#d7ccc8,stroke:#5d4037,stroke-width:2px;
    classDef config fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
```
