# haji-suleman/food-delivery architecture

> Architecture diagram of the GitHub repository haji-suleman/food-delivery, 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/haji-suleman/food-delivery
- Repository: https://github.com/haji-suleman/food-delivery

## Overview

##### Main Components
- Frontend: This is under the "frontend" directory. It is built using HTML, CSS, and JavaScript (React with Vite) and handles user interactions such as browsing food items, managing the cart, and placing orders.
- Admin Panel: Found in the "admin" directory, this React-based dashboard enables administrators to manage food items, orders, and user accounts.
- Backend/API Server: The "backend" folder contains an Express.js application with clearly defined directories for routes, controllers, models, middleware, and configuration files. This server handles authentication (using JWT), order processing, communication with the database (MongoDB), and facilitates payment integration.
- External Services: These include payment gateways (e.g., Stripe or PayPal) and mailing systems (NodeMailer as seen under backend/Mail), which interact with the backend.

##### Relationships and Interactions
- Both the frontend and the admin panel communicate with the backend by making HTTP requests (e.g., REST API calls).
- The backend routes client requests through controllers and middleware (including authentication and mailing) to the respective business logic.
- The backend interacts with the MongoDB database for persisting and retrieving data.
- Payment processing services and mailing services should be shown as external systems that the backend communicates with through specific modules or services.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separate the presentation layer (frontend and admin) from the business logic layer (backend).
- Security: Include a representation of the authentication flow (JWT) and any validation middlewares.

##### Technologies and Frameworks
- Frontend and Admin: React (using Vite), HTML, CSS, JavaScript.
- Backend: Node.js, Express.js.
- Database: MongoDB.
- Authentication: JWT.
- External Payment Service: Stripe/PayPal (as per README).
- Mailing: NodeMailer (under backend/Mail).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client Layer"
        FE["Frontend (User Interface)"]:::frontend
        AD["Admin Dashboard"]:::admin
    end

    %% Backend Layer
    subgraph "Backend API Server"
        ROUTES["API Routes"]:::backend
        MW["Middlewares (Auth/JWT)"]:::backend
        CTLR["Controllers"]:::backend
        MDLS["Models"]:::backend
        DB_CONN["DB Connection Module"]:::backend
        MAIL["Mail Service Module"]:::backend
    end

    %% External Services Layer
    subgraph "External Services"
        DB["MongoDB Database"]:::external
        PAYMENT["Payment Gateway"]:::external
    end

    %% Connections from Clients to Backend
    FE -->|"RESTAPICall"| ROUTES
    AD -->|"RESTAPICall"| ROUTES

    %% Internal Backend Flow
    ROUTES -->|"uses"| MW
    MW -->|"validates"| CTLR
    CTLR -->|"operatesOn"| MDLS
    CTLR -->|"processPayment"| PAYMENT
    CTLR -->|"triggers"| MAIL

    %% Database Connection
    DB_CONN -->|"connectsTo"| DB
    %% Connect DB Connection and Mail Service within backend
    MW --- DB_CONN
    MW --- MAIL

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0275d8,stroke-width:2px;
    classDef admin fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef backend fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/haji-suleman/food-delivery/tree/main/frontend/"
    click AD "https://github.com/haji-suleman/food-delivery/tree/main/admin/"
    click ROUTES "https://github.com/haji-suleman/food-delivery/tree/main/backend/"
    click DB_CONN "https://github.com/haji-suleman/food-delivery/blob/main/backend/config/db.js"
    click MAIL "https://github.com/haji-suleman/food-delivery/blob/main/backend/Mail/Nodemail.js"
```
