How tariq5mo/foodify works
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.