# aboodmagdy1/sofra architecture

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

- Interactive diagram: https://gitdiagram.com/aboodmagdy1/sofra
- Repository: https://github.com/aboodmagdy1/sofra

## Overview

##### Project Overview
- This is a backend solution for a multi-restaurant mobile application. It handles orders, client and restaurant management, reviews, meals, offers, commissions, and notifications.
- It exposes comprehensive RESTful APIs (for clients and restaurants), while also providing an admin dashboard for internal management.
- Technologies include Laravel v11 (PHP), MySQL, Eloquent ORM, Sanctum for authentication, Spatie for role/permission management, and external services like FCM for notifications and Paypal for payments.

##### Main Components
- API Layer:
- Controllers under app/Http/Controllers/Api (for both "Client" and "Restaurant").
- Authentication endpoints, order creation, meal management, offer management, and other CRUD operations.
- Admin Dashboard:
- Controllers within app/Http/Controllers/Admin, handling admin login, dashboard functions, user/role management, etc.
- Business Logic Layer:
- Services such as those in app/Services/(Admin, Client, Restaurant, OrderService, Payments, and more). These encapsulate domain and business logic.
- Use of repositories (app/Repositories and its Interfaces) following the Repository design pattern for data access abstraction.
- Domain & Data Layer:
- Models in app/Models representing entities (User, Client, Restaurant, Order, Meal, etc.).
- Migrations and seeders for the MySQL database structure.
- Auxiliary Components:
- Middleware (e.g., for permission checking – AutoCheckPermissionMiddleware).
- Helpers, Enums, Traits used across the project.
- Notification handling (using Laravel-notification-channels for FCM) and mail services.
- Payment integration service (e.g., PaypalGetwayService, exposing a GetwayInterface).

##### Architectural Patterns & Design Principles
- MVC Pattern: Controllers are handling HTTP requests and delegating to Services.
- Repository Pattern: Consistent abstraction for data access with Interfaces and Eloquent repositories.
- Service-Oriented: Clear separation of business logic into various service classes.
- Multi-Authentication: Different authentication flows for Admin, Client, and Restaurant users.

##### Detailed Elements
- Presentation Layer:
- Mobile App / Customer Interface.
- Admin Dashboard UI.
- API Layer:
- Client API Controllers (e.g., AuthController, MainClientController, OrderController).
- Restaurant API Controllers (e.g., AuthController, MealController, OfferController, RestaurantController).
- Separate routes defined in routes/api.php, routes/client-api.php, and routes/restaurant-api.php.
- Admin Layer:
- Admin Controllers (like AuthController, CategoryController, etc.) tied with Web routes (routes/admin.php).
- Business Logic Layer:
- Service classes (Admin services, ClientService, OrderService, etc.)
- Data Layer:
- Repository interfaces and Eloquent implementations.
- Database with migrations and models.
- External Integration:
- Payment Services (Paypal gateway).
- Notification Service (via FCM).
- Mail Service implementation (Mailtrap usage for emails).
- Configuration & Environment:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        MA["Mobile App / Customer Interface"]:::presentation
        AD["Admin Dashboard (Browser)"]:::presentation
    end

    %% API Layer
    subgraph "API Layer"
        CAC["Client API Controllers"]:::controllers
        RAC["Restaurant API Controllers"]:::controllers
        CAR["Client API Routes"]:::routes
        RAR["Restaurant API Routes"]:::routes
    end

    %% Admin Layer
    subgraph "Admin Layer"
        AC["Admin Controllers"]:::controllers
        AR["Admin Routes"]:::routes
    end

    %% Business Logic / Service Layer
    subgraph "Business Logic / Service Layer"
        AS["Admin Services"]:::services
        CLS["Client Services"]:::services
        RLS["Restaurant Services"]:::services
        OS["Order Service"]:::services
        PS["Payment Services"]:::services
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        MDLS["Models"]:::data
        REPO["Repositories & Interfaces"]:::data
        MIG["Database Migrations"]:::data
        DB["MySQL Database"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        PG["Payment Gateway Integration"]:::external
        NS["Notification Service (FCM)"]:::external
        MS["Mail Service"]:::external
    end

    %% Middleware & Auxiliary
    subgraph "Middleware & Auxiliary"
        PM["Permission Middleware"]:::middleware
        HP["Helpers"]:::middleware
        EN["Enums"]:::middleware
        TR["Traits"]:::middleware
    end

    %% Connections from Presentation to API/Admin Layers
    MA -->|"calls"| CAR
    CAR -->|"routes to"| CAC
    MA -->|"calls"| RAR
    RAR -->|"routes to"| RAC

    AD -->|"accesses"| AR
    AR -->|"routes to"| AC

    %% Controller to Service Layer
    CAC -->|"delegates"| CLS
    RAC -->|"delegates"| RLS
    AC  -->|"delegates"| AS

    %% Service interactions
    CLS -->|"invokes"| OS
    RLS -->|"invokes"| OS
    AS  -->|"queries"| REPO
    OS  -->|"uses"| REPO

    %% Repository & Data Layer interactions
    REPO -->|"manipulates"| MDLS
    MDLS -->|"defined by"| MIG
    MIG  -->|"applied on"| DB

    %% Service to External Integrations
    PS  -->|"integrates with"| PG
    OS  -->|"notifies"| NS
    AS  -->|"triggers"| MS

    %% Middleware Securing Controllers
    CAC ---|"securedBy"| PM
    RAC ---|"securedBy"| PM
    AC  ---|"securedBy"| PM

    %% Click Events for API Layer
    click CAC "https://github.com/aboodmagdy1/sofra/tree/master/app/Http/Controllers/Api/Client" " "
    click RAC "https://github.com/aboodmagdy1/sofra/tree/master/app/Http/Controllers/Api/Restaurant" " "
    click CAR "https://github.com/aboodmagdy1/sofra/blob/master/routes/client-api.php" " "
    click RAR "https://github.com/aboodmagdy1/sofra/blob/master/routes/restaurant-api.php" " "

    %% Click Events for Admin Layer
    click AC "https://github.com/aboodmagdy1/sofra/tree/master/app/Http/Controllers/Admin" " "
    click AR "https://github.com/aboodmagdy1/sofra/blob/master/routes/admin.php" " "

    %% Click Events for Business Logic / Service Layer
    click AS "https://github.com/aboodmagdy1/sofra/tree/master/app/Services/Admin" " "
    click CLS "https://github.com/aboodmagdy1/sofra/tree/master/app/Services/Client" " "
    click RLS "https://github.com/aboodmagdy1/sofra/tree/master/app/Services/Restaurant" " "
    click OS "https://github.com/aboodmagdy1/sofra/blob/master/app/Services/OrderService.php" " "
    click PS "https://github.com/aboodmagdy1/sofra/tree/master/app/Services/Payments" " "

    %% Click Events for Data Access Layer
    click MDLS "https://github.com/aboodmagdy1/sofra/tree/master/app/Models" " "
    click REPO "https://github.com/aboodmagdy1/sofra/tree/master/app/Repositories" " "
    click MIG "https://github.com/aboodmagdy1/sofra/tree/master/database/migrations" " "

    %% Click Events for External Integrations
    click PG "https://github.com/aboodmagdy1/sofra/blob/master/app/Services/Payments/PaypalGetwayService.php" " "
    click NS "https://github.com/aboodmagdy1/sofra/tree/master/app/Notifications" " "
    click MS "https://github.com/aboodmagdy1/sofra/tree/master/app/Mail" " "

    %% Click Events for Middleware & Auxiliary
    click PM "https://github.com/aboodmagdy1/sofra/blob/master/app/Http/Middleware/AutoCheckPermissionMiddleware.php" " "
    click HP "https://github.com/aboodmagdy1/sofra/blob/master/app/Helpers/helpers.php" " "
    click EN "https://github.com/aboodmagdy1/sofra/tree/master/app/Enums" " "
    click TR "https://github.com/aboodmagdy1/sofra/tree/master/app/Traits" " "

    %% Styling
    classDef presentation fill:#FFF2CC,stroke:#000,stroke-width:1px,color:#000;
    classDef controllers fill:#ADD8E6,stroke:#000,stroke-width:1px,color:#000;
    classDef routes fill:#BFD8B8,stroke:#000,stroke-width:1px,color:#000;
    classDef services fill:#90EE90,stroke:#000,stroke-width:1px,color:#000;
    classDef data fill:#FFDAB9,stroke:#000,stroke-width:1px,color:#000;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:1px,color:#000;
    classDef external fill:#E6E6FA,stroke:#000,stroke-width:1px,color:#000;
    classDef middleware fill:#FFB6C1,stroke:#000,stroke-width:1px,color:#000;
```
