How ha-mundo/food-donation-system works
Project Type and Purpose
• This is a lightweight full-stack Flask web application (monolithic) for facilitating food donations.
• The user interacts via webpages (templates), the Flask app (app.py) handles requests and business logic, and Flask-SQLAlchemy persists data in a relational database created by create_db.py.
File Structure Analysis
• Top-level files:
– app.py: main Flask application, routes, models, controllers.
– create_db.py: database schema initialization script.
– README.md: setup instructions.
• templates/: HTML templates (views) – base.html, home.html, donate.html, find_food.html, results.html.
Key Architectural Patterns
• MVC-style separation (View = templates/, Controller & Model = app.py + SQLAlchemy).
• Single process, single service (no microservices).
• Dependency on Flask for web framework and Flask-SQLAlchemy for ORM.
Main Components
a. User (Web Browser)
b. Flask Web Server (app.py)
– HTTP Routing Layer (URL endpoints: “/”, “/donate”, “/find_food”, etc.)
– Controllers & Business Logic
– ORM Models (SQLAlchemy classes defined in app.py)
c. Template Engine (Jinja2) – renders templates/*.html
d. Database (SQLite or configured RDBMS) – initialized by create_db.py
e. Development Environment – pipenv virtual environment, Python interpreter
f. External Libraries – Flask, Flask-SQLAlchemy
Relationships and Data Flows
1) Browser → Flask Web Server: user issues HTTP GET/POST.
2) Flask routes receive requests → invoke controller logic.
3) Controller uses SQLAlchemy ORM → issues SQL to Database.
4) Database returns query results → ORM maps to Python objects.
5) Controller passes data to Jinja2 templates → HTML is rendered.
6) Flask returns HTTP response → Browser displays page.
7) create_db.py is a one-time script: executed during setup to create tables.