How moizmakadq/moodyfood works
This is a single-process Python Streamlit web application that delivers AI-driven food recommendations. It:
• Captures user demographics + preferences in the UI
• Captures an image from webcam and runs emotion detection (DeepFace/FER/HSEmotion/custom model)
• Runs a recommendation pipeline over a CSV-backed food dataset plus user feedback/history stored in SQLite
• Provides analytics/visualizations and a feedback loop to adapt future recommendations
So the most accurate “system design” is not microservices; it’s a modular monolith with clear internal components and external dependencies.
From the tree + README, the core architectural modules are:
Configuration
• config.py — central settings for emotion model choice, thresholds, scoring weights, DB path, UI settings.
Domain / Application Services
• emotion_detector.py — encapsulates face/emotion inference using:
• DeepFace (primary)
• optional FER/HSEmotion/custom model
• depends on OpenCV/Pillow/TensorFlow stack
• recommendation_engine.py — the recommendation algorithm:
• mood/diet/cuisine/demographic filtering
• fallback relaxation strategy
• ranking/scoring (incl. randomness + feedback + location bonus)
• feedback_analyzer.py — aggregates feedback into cached statistics:
• top-rated foods
• avoid list
• emotion/demographic segmentation
Data Access / Persistence
• database.py — SQLite access layer (tables: users, user_preferences, recommendations_history, feedback)
• data_loader.py — loads/cleans/searches dataset from CSV; likely provides in-memory dataframe and search utilities
• view_database.py — operational utility (debug/admin-like viewer), not in main runtime path
Data Stores (artifacts)
• data/food_data.csv — primary item dataset (~1000+ entries)
• database/food_recommendation.db — persistent SQLite database file
• Streamlit runtime (web server + session state)
• Browser client
• Webcam device (client-side capture, then image passed to Streamlit app)
• DeepFace + model downloads (first run fetch)
• CV/ML stack (OpenCV, TensorFlow, etc.)
main.py → recommendation_engine.py with
• detected emotion
• demographics/preferences
• dataset access via data_loader.py
• feedback stats via feedback_analyzer.py (which itself uses database.py)
6. recommendation_engine.py → database.py: record recommendation session into recommendations_history
User clicks 👍/👎 in UI
• main.py → database.py: insert into feedback
• main.py → feedback_analyzer.py: invalidate/refresh cache (conceptually)
UI renders analytics
• main.py reads recommendation outputs + optional aggregated stats (Plotly/Matplotlib/Seaborn)
Secondary flows
• data_loader.py → data/food_data.csv (read-only)
• database.py → database/food_recommendation.db (read/write)
• emotion_detector.py → external model files / downloads (DeepFace assets); optionally models/best_emotion_model.h5 if present (README mentions it even if not in tree)
Architectural patterns worth explicitly encoding
• Modular monolith: one Streamlit app process, internally layered modules
• Pipeline pattern inside recommendation: filter → relax constraints → score → rank → top-N
• Feedback loop / adaptive learning: feedback updates DB → analyzer aggregates → engine consumes aggregates
• Configuration-driven strategy selection: config.py chooses emotion model backend and scoring weights
• Persistence separation:
• Static dataset (CSV) for item candidates
• SQLite for user/session/feedback state