# hossam-hosny/restaurantssystem architecture

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

- Interactive diagram: https://gitdiagram.com/hossam-hosny/restaurantssystem
- Repository: https://github.com/hossam-hosny/restaurantssystem

## Overview

##### Project Type & Purpose
- Full-stack backend Web API built with ASP.NET Core 8, following Clean Architecture.
- Exposes CRUD operations for Restaurants and Dishes, secured with JWT-based ASP.NET Identity.
- Uses CQRS via MediatR, EF Core for persistence, Serilog for logging, FluentValidation for input validation, and Swagger for documentation.
- Deployed to Azure App Service with Azure SQL, CI/CD via GitHub Actions.

##### High-Level Architectural Layers
- Presentation/API Layer (“RestaurantSystem” project)
- Application Layer (src/Restaurants.Application)
- Domain Layer (src/Restaurants.Domain)
- Infrastructure Layer (src/Restaurants.Infrastructure)
- External Systems (Azure SQL, Azure App Service, GitHub Actions, Postman/Swagger UI)

##### Main Components & Their Responsibilities
a. API Layer
- Controllers (RestaurantsController, DishesController, IdentityController)
- Custom Middleware (ErrorHandlingMiddleware, RequestTimeLoggingMiddleware)
- JWT Authentication & Authorization Policies
- Serilog configuration (in Program.cs & extensions)
b. Application Layer
- CQRS Commands & Queries (Create/Update/Delete/Read handlers)
- DTOs & AutoMapper Profiles
- Validators (FluentValidation)
- IUserContext for current user info
c. Domain Layer
- Entities (Restaurant, Dish, User, Address)
- Domain Exceptions & Constants
- Repository Interfaces & Authorization Service Interface
d. Infrastructure Layer
- EF Core DbContext & Migrations
- Repository Implementations (IDishRepository, IRestaurantRepository)
- ASP.NET Identity Stores & Claims Principal Factory
- Seeders for initial data (roles, restaurants)
- ServiceCollectionExtensions for DI registration
e. Testing
- Unit Tests for Application & Infrastructure logic
- Integration Tests for Controllers & Middleware
(These are separate test projects and can be shown as “Offline QA”)

##### Component Interactions & Data Flow
1. Client (Swagger/UI/Postman) → HTTP Request → API Controller
2. Controller → MediatR.Send(Command/Query)
3. MediatR → Application Handler
4. Handler → Domain Entities & Validation → Repository Interface
5. Repository Implementation (Infrastructure) → EF Core → Azure SQL
6. Results flow back up: Infrastructure → Handler → Controller → Client
7. Middleware logs request timing & handles exceptions via Serilog
8. Authentication: JWT token issued by IdentityController, validated by ASP.NET Identity services

##### Architectural Patterns & Principles
- Clean Architecture: strict layer separations, no direct DB calls in API
- CQRS: separate read (Queries) & write (Commands) flows
- Dependency Inversion: API & Application depend on Domain interfaces
- Single Responsibility: each handler, controller, middleware has one purpose
- Cross-cutting Concerns: Logging, Exception Handling, Validation are centralized in middleware or pipelines

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Swagger/Postman UI)"]:::external
    Swagger["Swagger UI"]:::external

    subgraph "API Layer"
        RC["RestaurantsController"]:::api
        DC["DishesController"]:::api
        IC["IdentityController"]:::api
        EHM["ErrorHandlingMiddleware"]:::api
        RTLM["RequestTimeLoggingMiddleware"]:::api
        SerCfg["Serilog Config"]:::api
    end

    subgraph "Application Layer"
        subgraph Commands
            CRC["CreateRestaurantCommandHandler"]:::app
            URC["UpdateRestaurantCommandHandler"]:::app
            DRC["DeleteRestaurantCommandHandler"]:::app
            CDC["CreateDishCommandHandler"]:::app
            DDCRC["DeleteDishesForRestaurantCommandHandler"]:::app
        end
        subgraph Queries
            GARQ["GetAllRestaurantQueryHandler"]:::app
            GBIRQ["GetByIdQueryHandler"]:::app
            GDFRQ["GetDishesForRestaurantQueryHandler"]:::app
            GDBIRQ["GetDishByIdForRestaurantQueryHandler"]:::app
        end
        DTOs["DTOs & AutoMapper Profiles"]:::app
        Validators["Validators (FluentValidation)"]:::app
        IUserCtx["IUserContext & UserContext"]:::app
        CurrUser["CurrentUser Accessor"]:::app
    end

    subgraph "Domain Layer"
        Entities["Entities (Restaurant, Dish, User, Address)"]:::domain
        Exceptions["Domain Exceptions"]:::domain
        Constants["Domain Constants"]:::domain
        Interfaces["Repository & Auth Service Interfaces"]:::domain
    end

    subgraph "Infrastructure Layer"
        DbCtx["AppDbContext"]:::infra
        Migrations["EF Core Migrations"]:::infra
        Repos["Repository Implementations"]:::infra
        IdentityStore["Identity Stores & ClaimsPrincipalFactory"]:::infra
        AuthSrv["Authorization Services"]:::infra
        Seeders["Seeders"]:::infra
        InfraDI["DI Registration Extensions"]:::infra
    end

    subgraph "External Systems"
        AzureSQL["Azure SQL"]:::external
        AzureApp["Azure App Service"]:::external
        GitHubActions["GitHub Actions (CI/CD)"]:::external
    end

    subgraph "Offline QA (Tests)"
        APITests["API Integration Tests"]:::test
        AppTests["Application Unit Tests"]:::test
        InfraTests["Infrastructure Unit Tests"]:::test
    end

    Client --> EHM
    EHM --> RTLM
    RTLM --> RC
    RTLM --> DC
    RTLM --> IC
    Swagger --> RC

    RC --> CRC
    RC --> URC
    RC --> DRC
    RC --> GARQ
    RC --> GBIRQ

    DC --> CDC
    DC --> DDCRC
    DC --> GDFRQ
    DC --> GDBIRQ

    IC --> IdentityStore
    IC --> AuthSrv

    CRC --> Interfaces
    URC --> Interfaces
    DRC --> Interfaces
    CDC --> Interfaces
    DDCRC --> Interfaces
    GARQ --> Interfaces
    GBIRQ --> Interfaces
    GDFRQ --> Interfaces
    GDBIRQ --> Interfaces

    Interfaces --> Repos
    Repos --> DbCtx
    DbCtx --> AzureSQL
    Migrations --> DbCtx

    SerCfg --> RC
    SerCfg --> DC
    SerCfg --> IC

    GitHubActions --> AzureApp

    APITests --> RC
    APITests --> EHM
    AppTests --> CRC
    AppTests --> Validators
    InfraTests --> Repos
    InfraTests --> DbCtx

    classDef api fill:#c6dbf7,stroke:#3182bd,color:#000
    classDef app fill:#b2df8a,stroke:#31a354,color:#000
    classDef domain fill:#fed976,stroke:#e6550d,color:#000
    classDef infra fill:#fd8d3c,stroke:#d94801,color:#000
    classDef external fill:#fdae6b,stroke:#e34a33,color:#000
    classDef test fill:#d9d9d9,stroke:#636363,color:#000

    click RC "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Controllers/RestaurantsController.cs"
    click DC "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Controllers/DishesController.cs"
    click IC "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Controllers/IdentityController.cs"
    click EHM "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Middlewares/ErrorHandlingMiddleware.cs"
    click RTLM "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Middlewares/RequestTimeLoggingMiddleware.cs"
    click SerCfg "https://github.com/hossam-hosny/restaurantssystem/blob/master/RestaurantSystem/Program.cs"
    click CRC "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/Commands/CreateRestaurant/"
    click URC "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/Commands/UpdateRestaurant/"
    click DRC "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/Commands/DeleteRestaurant/"
    click CDC "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Dishes/Commands/CreateDish/"
    click DDCRC "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Dishes/Commands/DeleteDishes/"
    click GARQ "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/Queries/GetAllRestaurants/"
    click GBIRQ "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/Queries/GetById/"
    click GDFRQ "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Dishes/Queries/GetAllDishes/"
    click GDBIRQ "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Dishes/Queries/GetDishById/"
    click DTOs "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Application/Restaurants/DTOs/"
    click Validators "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Application/Extensions/ServiceCollectionExtensions.cs"
    click IUserCtx "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Application/Users/IUserContext.cs"
    click CurrUser "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Application/Users/CurrentUser.cs"
    click Entities "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Domain/Entities/"
    click Exceptions "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Domain/Exceptions/"
    click Constants "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Domain/Constants/"
    click Interfaces "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Domain"
    click DbCtx "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Infrastructure/Context/AppDbContext.cs"
    click Migrations "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Infrastructure/Migrations/"
    click Repos "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Infrastructure/Repositories/"
    click IdentityStore "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Infrastructure/Authorization/RestaurantsUserClaimsPrincipalFactory.cs"
    click AuthSrv "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Infrastructure/Authorization/Services/restaurantAuthorizationService.cs"
    click Seeders "https://github.com/hossam-hosny/restaurantssystem/tree/master/src/Restaurants.Infrastructure/Seeders/"
    click InfraDI "https://github.com/hossam-hosny/restaurantssystem/blob/master/src/Restaurants.Infrastructure/Extensions/ServiceCollectionExtensions.cs"
    click APITests "https://github.com/hossam-hosny/restaurantssystem/tree/master/test/Restaurant.APITests/"
    click AppTests "https://github.com/hossam-hosny/restaurantssystem/tree/master/test/Restaurants.ApplicationTests/"
    click InfraTests "https://github.com/hossam-hosny/restaurantssystem/tree/master/test/Restaurants.InfrastructureTests/"
```
