# 42webok/online-food-ordering architecture

> Architecture diagram of the GitHub repository 42webok/online-food-ordering, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/42webok/online-food-ordering
- Repository: https://github.com/42webok/online-food-ordering

## Overview

##### Project type and purpose
- This is a full-stack, PHP-based web application (“Online Food Ordering System”) with two main user interfaces (public/front-end and admin panel) and a set of REST-style API endpoints under development. Users browse menu items, manage a cart, place orders; administrators manage banners, categories, dishes, coupons, delivery boys, and view contact messages.

##### File structure
- Top-level directories
– /front_html & root PHP files: public-facing HTML/PHP views (menus, cart, checkout, contact, login/register).
– /admin: admin dashboard UI and PHP controllers (login, CRUD scripts, utility includes).
– /api: PHP scripts grouped by resource (banner, category, coupen_code, delivery_boy, dish, contact_data, users) plus authentication.
– /assets & /admin/assets & /front_html/assets: static assets (CSS, JS, fonts, images) for each UI.
– /vendor & composer.json: third-party PHP dependencies (via Composer).
– Shared includes (function_inc.php, database.inc.php) for business logic and DB connectivity.
- Architectural clues
– MVC-style separation (views in HTML/PHP, controllers in PHP scripts, data access in includes).
– API layer sits alongside UI—enables mobile or JS-powered clients.
– Shared database backend (MySQL) accessed via config and include files.

##### README insights
- Tech stack: Frontend (HTML5, CSS3, JS, Bootstrap, jQuery), Backend (Core PHP), Database (MySQL).
- API planned: JSON-based endpoints for products, cart, orders, contact.
- Emphasis on modular API structure under /api.

##### Main components & interactions
a. Components
- User Devices (Web browser on desktop/mobile)
- Public-Facing Frontend UI
- Admin Backend UI
- API Layer
- Business Logic (PHP controllers and functions)
- Data Access Layer (database.inc.php, function_inc.php)
- MySQL Database
- Static Asset Store (CSS, JS, images served by web server)
- External Services (e.g., email verification service, optional SMS/API)
b. Relationships & Data Flow
1. Browser → Frontend UI → PHP controllers → Data Access → MySQL
2. Browser → /api endpoints → JSON responses ← PHP business logic ← MySQL
3. Admin UI → Admin PHP controllers → MySQL (CRUD)
4. Shared static assets served directly by web server or via CDN
5. PHP mail() or SMTP calls for password reset & contact form
c. Architectural patterns & principles
– Layered architecture: Presentation (views), Controller (business logic), Data Access.
– Resource-based API endpoints organized into modules (REST style).
– Reusable includes for config, DB connection, common functions.
d. Key technologies
– Apache/Nginx + PHP7+
– MySQL
– Bootstrap, jQuery, Font Awesome for UI
– Composer for dependency management (vendor)
– JSON for API payloads

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["User Browser"]:::external
        subgraph "Public-Facing Frontend UI" 
            direction TB
            PublicUI["front_html/"]:::frontend
            RootViews["Root PHP Views"]:::frontend
        end
        subgraph "Admin Backend UI"
            direction TB
            AdminUI["admin/"]:::frontend
            AdminViews["Admin PHP Controllers"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        APICore["Core API Scripts"]:::api
        subgraph "Resource Modules"
            direction TB
            BannerAPI["api/banner/"]:::api
            CategoryAPI["api/category/"]:::api
            CoupenAPI["api/coupen_code/"]:::api
            DishAPI["api/dish/"]:::api
            DeliveryAPI["api/delivery_boy/"]:::api
            ContactAPI["api/contact_data/"]:::api
            UsersAPI["api/users/"]:::api
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic / Common Functions"
        direction TB
        GlobalFuncs["function_inc.php"]:::logic
        AdminFuncs["admin/function.inc.php"]:::logic
        APIFuncs["api/function.inc.php"]:::logic
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        AdminDB["admin/database.inc.php"]:::data
        APIConfig["api/config.php"]:::data
        MySQLDB["MySQL Database"]:::database
    end

    %% Static Assets
    subgraph "Static Asset Store"
        direction TB
        PublicAssets["assets/"]:::assets
        FrontAssets["front_html/assets/"]:::assets
        AdminAssets["admin/assets/"]:::assets
    end

    %% Third-Party Dependencies
    Vendor["vendor/"]:::third
    Composer["composer.json"]:::third

    %% External Services
    subgraph "External Services"
        direction TB
        EmailService["Email/SMS Service"]:::external
        VerifyEmail["verify_email.php"]:::external
        ContactSave["contact_data_save.php"]:::external
    end

    %% Connections
    Browser -->|"HTTP/HTTPS"| PublicUI
    PublicUI -->|"includes"| GlobalFuncs
    PublicUI -->|"serves assets"| FrontAssets
    RootViews -->|"includes"| GlobalFuncs
    AdminUI -->|"HTTP/HTTPS"| AdminViews
    AdminViews -->|"uses"| AdminFuncs
    AdminViews -->|"serves assets"| AdminAssets
    AdminViews -->|"DB access"| AdminDB
    APICore -->|"includes"| APIFuncs
    APICore -->|"DB config"| APIConfig
    APICore -->|"provides endpoints"| BannerAPI
    APICore -->|"provides endpoints"| CategoryAPI
    APICore -->|"provides endpoints"| CoupenAPI
    APICore -->|"provides endpoints"| DishAPI
    APICore -->|"provides endpoints"| DeliveryAPI
    APICore -->|"provides endpoints"| ContactAPI
    APICore -->|"provides endpoints"| UsersAPI
    Browser -->|"AJAX/JSON"| APICore
    AdminViews -->|"AJAX/JSON"| APICore
    GlobalFuncs -->|"SQL queries"| MySQLDB
    AdminFuncs -->|"SQL queries"| MySQLDB
    APIFuncs -->|"SQL queries"| MySQLDB
    APIConfig -->|"connects to"| MySQLDB
    PublicAssets -->|"cached via CDN"| Browser
    AdminAssets -->|"cached via CDN"| AdminViews
    FrontAssets -->|"cached via CDN"| PublicUI
    Vendor -->|"libraries"| GlobalFuncs
    Vendor -->|"libraries"| APIFuncs
    Composer -->|"manifest"| Vendor
    EmailService -->|"SMTP/REST"| VerifyEmail
    EmailService -->|"SMTP/REST"| ContactSave
    RootViews -->|"triggers"| VerifyEmail
    RootViews -->|"triggers"| ContactSave

    %% Click Events
    click PublicUI "https://github.com/42webok/online-food-ordering/tree/main/front_html/"
    click AdminUI "https://github.com/42webok/online-food-ordering/tree/main/admin/"
    click APICore "https://github.com/42webok/online-food-ordering/tree/main/api/"
    click BannerAPI "https://github.com/42webok/online-food-ordering/tree/main/api/banner/"
    click CategoryAPI "https://github.com/42webok/online-food-ordering/tree/main/api/category/"
    click CoupenAPI "https://github.com/42webok/online-food-ordering/tree/main/api/coupen_code/"
    click DishAPI "https://github.com/42webok/online-food-ordering/tree/main/api/dish/"
    click DeliveryAPI "https://github.com/42webok/online-food-ordering/tree/main/api/delivery_boy/"
    click ContactAPI "https://github.com/42webok/online-food-ordering/tree/main/api/contact_data/"
    click UsersAPI "https://github.com/42webok/online-food-ordering/tree/main/api/users/"
    click GlobalFuncs "https://github.com/42webok/online-food-ordering/blob/main/function_inc.php"
    click AdminFuncs "https://github.com/42webok/online-food-ordering/blob/main/admin/function.inc.php"
    click APIFuncs "https://github.com/42webok/online-food-ordering/blob/main/api/function.inc.php"
    click AdminDB "https://github.com/42webok/online-food-ordering/blob/main/admin/database.inc.php"
    click APIConfig "https://github.com/42webok/online-food-ordering/blob/main/api/config.php"
    click PublicAssets "https://github.com/42webok/online-food-ordering/tree/main/assets/"
    click FrontAssets "https://github.com/42webok/online-food-ordering/tree/main/front_html/assets/"
    click AdminAssets "https://github.com/42webok/online-food-ordering/tree/main/admin/assets/"
    click Vendor "https://github.com/42webok/online-food-ordering/tree/main/vendor/"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#005CAF,color:#000;
    classDef api fill:#DFFFE0,stroke:#2E7D32,color:#000;
    classDef logic fill:#E0F7FA,stroke:#006064,color:#000;
    classDef data fill:#FFF3E0,stroke:#E65100,color:#000;
    classDef database fill:#FFE0B2,stroke:#FF6F00,color:#000;
    classDef assets fill:#F3E5F5,stroke:#6A1B9A,color:#000;
    classDef third fill:#ECEFF1,stroke:#37474F,color:#000;
    classDef external fill:#FBE9E7,stroke:#BF360C,color:#000;
```
