# abdessamadberahhou/courierapi architecture

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

- Interactive diagram: https://gitdiagram.com/abdessamadberahhou/courierapi
- Repository: https://github.com/abdessamadberahhou/courierapi

## Overview

##### Project Type and Purpose
- This is a standalone ASP.NET Core Web API (“CourierAPI”) built on .NET 5.0.
- It exposes endpoints for user authentication, courier management, file uploads, and user administration.

##### File Structure
- Top-level folders:
- Controllers – HTTP entry points (AuthenticationController, CourierController, UserController, WeatherForecastController)
- Services – business-logic and helper services (authentication, token generation/validation, repositories, password hashing)
- Models – domain entities, EF Core DbContexts, request/response DTOs
- Migrations – EF Core schema migrations and snapshots
- wwwroot/Upload – static file host for uploaded files
- Startup.cs & Program.cs – host configuration and DI setup
- appsettings*.json – configuration for connection strings, auth settings, environments
- Patterns: layered architecture (Controller → Service → Repository → EF Core DbContext → Database), repository pattern, service layer, DI container

##### README
- Minimal, but name “CourierAPI” confirms it’s a RESTful backend for courier operations.

##### Details to Capture
- Startup/Program bootstrap → registers middleware and services
- Controllers wired into services via DI
- Each service’s dependency on one or more repositories or helpers (token generator, validator, hasher)
- EF Core migrations managing database schema
- appsettings configuration feeding into AuthConfiguartion and DbContext options

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Client["Web/Mobile Client"]:::external

    %% Hosting Environment
    subgraph "Hosting Environment"
        direction TB
        WebHost["ASP.NET Core Web Host (Kestrel/IIS)"]:::infra
        Program["Program.cs"]:::infra
        Startup["Startup.cs"]:::infra
    end

    %% Controllers Layer
    subgraph "Presentation Layer (Controllers)" 
        direction TB
        AuthCtrl["AuthenticationController"]:::presentation
        CourCtrl["CourierController"]:::presentation
        UserCtrl["UserController"]:::presentation
        WeatherCtrl["WeatherForecastController"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Layer (Services)"
        direction TB
        Authenticator["Authenticator"]:::business
        AccessTokenGen["AccessTokenGenerator"]:::business
        RefreshTokenGen["RefreshTokenGenerator"]:::business
        TokenGenInterface["TokenGenerator (interface)"]:::business
        RefreshTokenValidator["RefreshTokenValidator"]:::business
        PasswordHasherIF["IPasswordHasher"]:::business
        PasswordHasherImp["PasswordHashImp"]:::business
        UserRepoIF["IUserRepository"]:::business
        UserSaver["UserSaver"]:::business
        CourierRepoIF["ICourierRepository"]:::business
        CourierSaver["CourierSaver"]:::business
        RefreshTokenRepoIF["IRefreshTokenRepository"]:::business
        MemoryRefreshRepo["MemoryRefreshTokenRepository"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        UsersContext["UsersContext"]:::data
        CouriersContext["CouriersContext"]:::data
        FileContext["FileContext"]:::data
        RefreshTokenContext["RefreshTokenContext"]:::data
    end

    %% Persistence
    subgraph "Persistence"
        direction TB
        SQLDB["SQL Server Database"]:::persistence
        FileStorage["Static File Storage (wwwroot/Upload)"]:::persistence
        Migrations["EF Core Migrations"]:::persistence
        AppSettings["appsettings.json / env"]:::config
    end

    %% Connections
    Client -->|"HTTP(S) Request"| WebHost
    WebHost --> Startup
    Startup --> Controllers
    Controllers -->|uses DI| BusinessLayer
    AuthCtrl --> Authenticator
    AuthCtrl --> RefreshTokenValidator
    CourCtrl --> CourierSaver
    UserCtrl --> UserSaver
    WeatherCtrl --> UsersContext

    Authenticator -->|implements| TokenGenInterface
    TokenGenInterface --> AccessTokenGen
    TokenGenInterface --> RefreshTokenGen
    RefreshTokenGen --> MemoryRefreshRepo
    RefreshTokenValidator --> MemoryRefreshRepo
    Authenticator --> PasswordHasherIF
    PasswordHasherIF --> PasswordHasherImp

    UserSaver --> UsersContext
    CourierSaver --> CouriersContext
    MemoryRefreshRepo --> RefreshTokenContext
    FileUploadFlow["File Upload Flow"]:::note
    FileUploadFlow --> FileContext
    FileContext --> FileStorage

    UsersContext --> SQLDB
    CouriersContext --> SQLDB
    RefreshTokenContext --> SQLDB

    AppSettings --> Startup
    Migrations --> SQLDB

    %% Click Events
    click Program "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Program.cs"
    click Startup "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Startup.cs"
    click AuthCtrl "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Controllers/AuthenticationContorller.cs"
    click CourCtrl "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Controllers/CourierController.cs"
    click UserCtrl "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Controllers/UserController.cs"
    click WeatherCtrl "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Controllers/WeatherForecastController.cs"
    click Authenticator "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/Authenticator/Authenticator.cs"
    click AccessTokenGen "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/TokensGenerators/AccessTokenGenerator.cs"
    click RefreshTokenGen "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/TokensGenerators/RefreshTokenGenerator.cs"
    click TokenGenInterface "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/TokensGenerators/TokenGenerator.cs"
    click RefreshTokenValidator "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/TokenValidators/RefreshTokenValidator.cs"
    click PasswordHasherIF "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/PasswordHash/IPasswordHasher.cs"
    click PasswordHasherImp "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/PasswordHash/PasswordHashImp.cs"
    click UserRepoIF "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/UserRepository/IUserRepository.cs"
    click UserSaver "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/UserRepository/UserSaver.cs"
    click CourierRepoIF "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/CourierRepository/ICourierRepository.cs"
    click CourierSaver "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/CourierRepository/CourierSaver.cs"
    click RefreshTokenRepoIF "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/RefreshTokenRepository/IRefreshTokenRepository.cs"
    click MemoryRefreshRepo "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Services/RefreshTokenRepository/MemoryRefreshTokenRepository.cs"
    click UsersContext "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Models/Users/UsersContext.cs"
    click CouriersContext "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Models/courier/CouriersContext.cs"
    click FileContext "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Models/file/FileContext.cs"
    click RefreshTokenContext "https://github.com/abdessamadberahhou/courierapi/blob/abdessamad/Models/RefreshToken/RefreshTokenContext.cs"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef infra fill:#ddeeff,stroke:#333,stroke-width:1px
    classDef presentation fill:#add8e6,stroke:#333,stroke-width:1px
    classDef business fill:#90ee90,stroke:#333,stroke-width:1px
    classDef data fill:#ffa500,stroke:#333,stroke-width:1px
    classDef persistence fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef config fill:#e6e6fa,stroke:#333,stroke-width:1px
    classDef note fill:#ffffcc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
