# quocdatend/restapirestaurant architecture

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

- Interactive diagram: https://gitdiagram.com/quocdatend/restapirestaurant
- Repository: https://github.com/quocdatend/restapirestaurant

## Overview

Based on your file tree and README, this is clearly a PHP-based REST API project designed for managing restaurant operations. The project handles orders, products (menu items), reviews, users, and admin functions. It leverages a typical layered architecture and follows a structured approach with separate directories for controllers, objects (models), routes, middlewares, utilities, services, and configuration.

##### Main Components
- Public Entry Point: Represented by public/index.php – the central “front controller” that boots up the application.
- Routing Layer: Located in the API’s routes directory. This layer maps incoming HTTP requests to the corresponding controllers.
- Middleware Layer: Found in the middlewares/ directory (auth_middleware.php and validate_middleware.php). This component is responsible for authentication, authorization, and input validation.
- Controllers: In api/controllers – they contain the business logic for handling orders, reviews, menu items, users, and admin actions.
- Models/Objects: Contained within api/objects. These represent the data structures like Orders, OrderItem, Review, user, admin, etc.
- Database/Configuration: Configuration files (config/database.php and config/core.php) supply necessary settings for database connections and core constants.
- Utilities and Services:
- “Utils” provide helper functions (jwt.php, validator.php, response.php, helpers.php) to support tasks like token verification, input validation, and formatting API responses.
- “Services” (such as email_service.php) handle specific external functionalities.
- External Libraries: The vendor directory holds external dependencies installed via Composer.

##### Relationships and Interactions
- Client/HTTP Request: The client sends a request (e.g., to create an order or add a review).
- Public Entry: The request hits public/index.php, which acts as the initial receiver.
- Router: The index.php hands off the request to the Router component, which then delegates to specific API route files (like order_route.php, review_routes.php, etc.).
- Middlewares: Before finally reaching a Controller, the request passes through middleware for authentication and validation.
- Controllers: Each controller processes the request, accesses Models (from the objects folder) for data manipulation, and applies business logic.
- Database: Models interact with the database as configured in config/database.php for CRUD operations.
- Response: The output is standardized by utilities like response.php, then sent back to the Client.

##### Architectural Patterns/Design Principles
- Layered Architecture: Emphasizes separation between routing, middleware, controllers, models, and utilities.
- MVC-like Approach: Although not a full MVC framework, controllers and objects mimic the Controller and Model layers.
- RESTful Design: The endpoints (documented in README) follow REST principles, with clear separation for GET, POST, PUT, and DELETE operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client"):::external

    subgraph "Public Layer"
        PublicEntry("Public Entry (index.php)"):::entry
    end

    subgraph "Routing Layer"
        Router("API Routes (api/routes)"):::entry
    end

    subgraph "Middleware Layer"
        Middlewares("Middlewares (middlewares)"):::middleware
    end

    subgraph "Controller Layer"
        OrderController("Order Controller (Order_Controller.php)"):::controller
        ReviewController("Review Controller (Review_Controller.php)"):::controller
        AdminController("Admin Controller (admin_controller.php)"):::controller
        MenuController("Menu Controller (menu_controller.php)"):::controller
        UserController("User Controller (user_controller.php)"):::controller
    end

    subgraph "Model Layer"
        Models("Models (api/objects)"):::model
    end

    subgraph "Database/Configuration"
        DatabaseConfig("Database Config (database.php)"):::database
        CoreConfig("Core Config (core.php)"):::database
    end

    subgraph "Utilities & Services"
        Utilities("Utilities (utils)"):::utility
        EmailService("Email Service (email_service.php)"):::service
    end

    subgraph "External Dependencies"
        Vendor("External Libraries (vendor)"):::external
    end

    %% Flow Connections
    Client -->|"sends request"| PublicEntry
    PublicEntry -->|"hands off request"| Router
    Router -->|"routes request"| Middlewares
    Middlewares -->|"filters request"| OrderController
    Middlewares -->|"filters request"| ReviewController
    Middlewares -->|"filters request"| AdminController
    Middlewares -->|"filters request"| MenuController
    Middlewares -->|"filters request"| UserController

    OrderController -->|"interacts with"| Models
    ReviewController -->|"interacts with"| Models
    AdminController -->|"interacts with"| Models
    MenuController -->|"interacts with"| Models
    UserController -->|"interacts with"| Models

    Models -->|"performs CRUD"| DatabaseConfig
    Models -->|"uses settings"| CoreConfig

    OrderController -->|"formats response"| Utilities
    ReviewController -->|"formats response"| Utilities
    AdminController -->|"formats response"| Utilities
    MenuController -->|"formats response"| Utilities
    UserController -->|"formats response"| Utilities

    OrderController -->|"invokes"| EmailService
    ReviewController -->|"invokes"| EmailService
    AdminController -->|"invokes"| EmailService
    MenuController -->|"invokes"| EmailService
    UserController -->|"invokes"| EmailService

    Utilities -->|"may use"| Vendor

    %% Click Events
    click PublicEntry "https://github.com/quocdatend/restapirestaurant/blob/main/public/index.php"
    click Router "https://github.com/quocdatend/restapirestaurant/tree/main/api/routes"
    click Middlewares "https://github.com/quocdatend/restapirestaurant/tree/main/middlewares"
    click OrderController "https://github.com/quocdatend/restapirestaurant/blob/main/api/controllers/Order_Controller.php"
    click ReviewController "https://github.com/quocdatend/restapirestaurant/blob/main/api/controllers/Review_Controller.php"
    click AdminController "https://github.com/quocdatend/restapirestaurant/blob/main/api/controllers/admin_controller.php"
    click MenuController "https://github.com/quocdatend/restapirestaurant/blob/main/api/controllers/menu_controller.php"
    click UserController "https://github.com/quocdatend/restapirestaurant/blob/main/api/controllers/user_controller.php"
    click Models "https://github.com/quocdatend/restapirestaurant/tree/main/api/objects"
    click DatabaseConfig "https://github.com/quocdatend/restapirestaurant/blob/main/config/database.php"
    click CoreConfig "https://github.com/quocdatend/restapirestaurant/blob/main/config/core.php"
    click Utilities "https://github.com/quocdatend/restapirestaurant/tree/main/utils"
    click EmailService "https://github.com/quocdatend/restapirestaurant/blob/main/services/email_service.php"
    click Vendor "https://github.com/quocdatend/restapirestaurant/tree/main/vendor"

    %% Styles
    classDef entry fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef middleware fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef controller fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef model fill:#F5CBA7,stroke:#B9770E,stroke-width:2px;
    classDef database fill:#EC7063,stroke:#78281F,stroke-width:2px;
    classDef utility fill:#BB8FCE,stroke:#5B2C6F,stroke-width:2px;
    classDef service fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#1D8348,stroke-width:2px;
```
