# tariq5mo/foodify architecture

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

- Interactive diagram: https://gitdiagram.com/tariq5mo/foodify
- Repository: https://github.com/tariq5mo/foodify

## Overview

##### Project Type and Purpose
- Foodify is a full-stack web application built on Python/Flask with a MySQL backend and a vanilla-JS/CSS/HTML frontend.
- It provides user authentication, restaurant browsing, menu ordering, real-time order tracking, and location services (TomTom API).

##### File Structure
- **Entry Points**
- `app.py` – launches the Flask web server and registers Blueprints.
- `console.py` – a CLI tool for data‐model CRUD via the same ORM layer.
- **Backend**
- `routes/` – Blueprint modules (`login.py`, `signup.py`, `order.py`, etc.) implement HTTP handlers.
- `models/` – SQLAlchemy ORM models (`Client`, `Restaurant`, `MenuItem`, `Order`, `OrderItem`, `Review`) and the `engine/db_storage.py` data‐access implementation.
- **Frontend**
- `templates/` – Jinja2 HTML templates for pages (landing, login, order, payment, delivery, contact, user settings).
- `static/` – CSS, JS, and image assets; layout and interactive scripts (`script.js`, `search.js`, `delivery.js`, etc.).
- **Database**
- MySQL schema (backup in `database/foodify_backup.sql`).
- **External Services & Config**
- TomTom API (geocoding, maps) via HTTP requests.
- Environment variables (`.env`), Flask-Login/Session, Flask-Bcrypt, WTForms (CSRF).

##### README for Additional Insights
- Confirms use of SQLAlchemy ORM, Flask Blueprints, Jinja2, TomTom Maps SDK, MySQL.
- Notes secure forms, session‐based authentication, and planned JWT migration.

##### Main Components and Their Interactions
a. **Client (Browser/Mobile)**
- Sends HTTP(S) requests for pages and JSON endpoints.
- Renders HTML (templates) and executes JS for cart management, search, map integration.
b. **Web Server (Flask Application)**
- Receives requests in `app.py`.
- Routes requests to appropriate Blueprint in `routes/`.
- Coordinates business logic, form handling (Flask-WTF), authentication (`Flask-Login`), session (`Flask-Session`).
c. **Business Logic & Models**
- Route handlers import ORM models (`models/*.py`) to query/update data.
- `models/engine/db_storage.py` abstracts MySQL connections via SQLAlchemy/MySQL-Connector.
d. **Database (MySQL)**
- Stores persistent state: users, restaurants, menu items, orders, order items, reviews.
- Schema and indices defined in SQL dump.
e. **External Services**
- **TomTom API** – geocoding, address autocomplete, maps in the delivery module.
- Potential future payment gateway or third-party integration.
f. **Administrative CLI**
- `console.py` uses the same models/engine to manage data via command prompt.

##### Architectural Patterns and Design Principles
- **Layered Architecture** – Presentation (templates, static), Routing/Controllers (`routes/`), Domain Models, Persistence.
- **Blueprints** for modular routing.
- **ORM Abstraction** – SQLAlchemy engine hidden behind `db_storage` for easy swap.
- **Separation of Concerns** – UI logic in JS/CSS, business logic in Python, DB access in engine module.
- **External-Service Isolation** – TomTom calls wrapped in `routes/delivery.py`.

##### Diagramming Recommendations
- Use **rectangles** for components:
- *Light blue* for frontend (templates, JS modules).
- *Green* for backend modules (Flask app, Blueprints).
- *Orange* for database.
- *Purple* for external services (TomTom).
- “HTTP GET/POST” between Client ↔ Web Server.
- “ORM queries” between Routes ↔ DB Storage.
- “SQL” between Storage ↔ MySQL.
- “REST API calls” between Server ↔ TomTom.
- **Clear labels** on each component (e.g., “routes/order.py”, “models/order_item.py”).

##### Detailed Component Breakdown
- **Client Browser**
- UI pages: welcome, login/signup, restaurant list, menu items, cart, payment, delivery, reviews.
- JS modules: `script.js` (cart), `search.js`, `delivery.js` (maps), `payment.js`, `login_signup.js`, etc.
- **Flask Server**
- `app.py` – application bootstrap & Blueprint registration.
- Blueprints in `routes/`: login, signup, contact, restaurant, order, payment, delivery, user_setting, welcome.
- Config in `routes/config.py`.
- Form handling & CSRF (Flask-WTF).
- Authentication (Flask-Login, Flask-Bcrypt).
- **Data Layer**
- Models: Client, Restaurant, MenuItem, Order, OrderItem, Review (`models/*.py`).
- DB Engine: `models/engine/db_storage.py` (MySQL + SQLAlchemy).
- Data persistency (MySQL database server).
- **External Service**
- TomTom Maps SDK & REST API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Templates["HTML Templates"]:::frontend
        subgraph "JS Modules"
            direction TB
            Script["script.js"]:::frontend
            Search["search.js"]:::frontend
            DeliveryJS["delivery.js"]:::frontend
            PaymentJS["payment.js"]:::frontend
            LoginSignupJS["login_signup.js"]:::frontend
            OrderJS["order.js"]:::frontend
            ContactJS["contact.js"]:::frontend
            UserSettingJS["user_setting.js"]:::frontend
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        App["app.py"]:::backend
        Console["console.py"]:::backend
        Config["routes/config.py"]:::backend

        subgraph "Blueprints"
            direction TB
            LoginBP["routes/login.py"]:::backend
            SignupBP["routes/signup.py"]:::backend
            ContactBP["routes/contact.py"]:::backend
            RestaurantBP["routes/restaurant.py"]:::backend
            OrderBP["routes/order.py"]:::backend
            PaymentBP["routes/payment.py"]:::backend
            DeliveryBP["routes/delivery.py"]:::backend
            UserSettingBP["routes/user_setting.py"]:::backend
            WelcomeBP["routes/welcome.py"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        subgraph "Models"
            direction TB
            BaseModel["models/base_model.py"]:::backend
            ClientModel["models/client.py"]:::backend
            RestaurantModel["models/restaurant.py"]:::backend
            MenuItemModel["models/menu_item.py"]:::backend
            OrderModel["models/order.py"]:::backend
            OrderItemModel["models/order_item.py"]:::backend
            ReviewModel["models/review.py"]:::backend
        end
        DBStorage["models/engine/db_storage.py"]:::backend
        MySQLDB["MySQL Database"]:::database
        TomTom["TomTom API"]:::external
    end

    %% Interactions
    Templates -->|renders| ClientLayer["Client Layer"]
    Script -->|executes| ClientLayer
    Search -->|executes| ClientLayer
    DeliveryJS -->|executes| ClientLayer
    PaymentJS -->|executes| ClientLayer
    LoginSignupJS -->|executes| ClientLayer
    OrderJS -->|executes| ClientLayer
    ContactJS -->|executes| ClientLayer
    UserSettingJS -->|executes| ClientLayer

    ClientLayer -->|HTTP GET/POST| App
    App -->|registers| Config
    App -->|registers| LoginBP
    App -->|registers| SignupBP
    App -->|registers| ContactBP
    App -->|registers| RestaurantBP
    App -->|registers| OrderBP
    App -->|registers| PaymentBP
    App -->|registers| DeliveryBP
    App -->|registers| UserSettingBP
    App -->|registers| WelcomeBP

    Console -->|uses models| BaseModel
    Console --> DBStorage

    LoginBP -->|uses ORM queries| ClientModel
    SignupBP -->|uses ORM queries| ClientModel
    ContactBP -->|uses ORM queries| ReviewModel
    RestaurantBP -->|uses ORM queries| RestaurantModel
    OrderBP -->|uses ORM queries| OrderModel
    OrderBP -->|uses ORM queries| OrderItemModel
    PaymentBP -->|uses ORM queries| OrderModel
    DeliveryBP -->|uses ORM queries| OrderModel
    DeliveryBP --> DBStorage
    UserSettingBP -->|uses ORM queries| ClientModel
    WelcomeBP -->|uses ORM queries| RestaurantModel

    ClientModel --> DBStorage
    RestaurantModel --> DBStorage
    MenuItemModel --> DBStorage
    OrderModel --> DBStorage
    OrderItemModel --> DBStorage
    ReviewModel --> DBStorage

    DBStorage -->|SQL| MySQLDB
    DeliveryBP -->|REST API calls| TomTom

    %% Click Events
    click App "https://github.com/tariq5mo/foodify/blob/master/app.py"
    click Console "https://github.com/tariq5mo/foodify/blob/master/console.py"
    click Config "https://github.com/tariq5mo/foodify/blob/master/routes/config.py"
    click LoginBP "https://github.com/tariq5mo/foodify/blob/master/routes/login.py"
    click SignupBP "https://github.com/tariq5mo/foodify/blob/master/routes/signup.py"
    click ContactBP "https://github.com/tariq5mo/foodify/blob/master/routes/contact.py"
    click RestaurantBP "https://github.com/tariq5mo/foodify/blob/master/routes/restaurant.py"
    click OrderBP "https://github.com/tariq5mo/foodify/blob/master/routes/order.py"
    click PaymentBP "https://github.com/tariq5mo/foodify/blob/master/routes/payment.py"
    click DeliveryBP "https://github.com/tariq5mo/foodify/blob/master/routes/delivery.py"
    click UserSettingBP "https://github.com/tariq5mo/foodify/blob/master/routes/user_setting.py"
    click WelcomeBP "https://github.com/tariq5mo/foodify/blob/master/routes/welcome.py"
    click BaseModel "https://github.com/tariq5mo/foodify/blob/master/models/base_model.py"
    click ClientModel "https://github.com/tariq5mo/foodify/blob/master/models/client.py"
    click RestaurantModel "https://github.com/tariq5mo/foodify/blob/master/models/restaurant.py"
    click MenuItemModel "https://github.com/tariq5mo/foodify/blob/master/models/menu_item.py"
    click OrderModel "https://github.com/tariq5mo/foodify/blob/master/models/order.py"
    click OrderItemModel "https://github.com/tariq5mo/foodify/blob/master/models/order_item.py"
    click ReviewModel "https://github.com/tariq5mo/foodify/blob/master/models/review.py"
    click DBStorage "https://github.com/tariq5mo/foodify/blob/master/models/engine/db_storage.py"
    click Templates "https://github.com/tariq5mo/foodify/tree/master/templates/"
    click Script "https://github.com/tariq5mo/foodify/blob/master/static/js/script.js"
    click Search "https://github.com/tariq5mo/foodify/blob/master/static/js/search.js"
    click DeliveryJS "https://github.com/tariq5mo/foodify/blob/master/static/js/delivery.js"
    click PaymentJS "https://github.com/tariq5mo/foodify/blob/master/static/js/payment.js"
    click LoginSignupJS "https://github.com/tariq5mo/foodify/blob/master/static/js/login_signup.js"
    click OrderJS "https://github.com/tariq5mo/foodify/blob/master/static/js/order.js"
    click ContactJS "https://github.com/tariq5mo/foodify/blob/master/static/js/contact.js"
    click UserSettingJS "https://github.com/tariq5mo/foodify/blob/master/static/js/user_setting.js"
    click MySQLDB "https://github.com/tariq5mo/foodify/blob/master/database/foodify_backup.sql"

    %% Styles
    classDef frontend fill:#CCF5FF,stroke:#0066CC,color:#003366;
    classDef backend fill:#CCFFCC,stroke:#339933,color:#006600;
    classDef database fill:#FFE5CC,stroke:#FF9933,color:#CC6600;
    classDef external fill:#E5CCFF,stroke:#9933CC,color:#660066;
```
