Overview
SmartEat AI uses PostgreSQL as its relational database, managed through SQLAlchemy ORM. The schema is designed to support user authentication, nutritional profiles, recipe management, and personalized meal planning.Core Tables
Users
Theusers table stores authentication and basic user information.
- One-to-one with
profiles - One-to-many with
plans
Profiles
Theprofiles table contains detailed nutritional and health information for each user.
- Many-to-many with
tastes(viaprofiles_tastes) - Many-to-many with
restrictions(viaprofiles_restrictions) - Many-to-many with
diet_types(viaprofiles_diet_types)
Recipes
Therecipes table stores all available recipes with nutritional information.
- Many-to-many with
meal_types(viarecipe_meal_types) - Many-to-many with
diet_types(viarecipe_diet_types)
Plans
Theplans table represents weekly meal plans for users.
- Belongs to
user - One-to-many with
daily_menus
Daily Menus
Thedaily_menus table contains daily meal schedules within a plan.
- Belongs to
plan - One-to-many with
meal_details
Meal Details
Themeal_details table stores individual meals within a daily menu.
- Belongs to
recipe - Belongs to
daily_menu
Category Tables
Diet Types
Thediet_types table defines available dietary preferences.
Meal Types
Themeal_types table categorizes when recipes can be consumed.
Tastes
Thetastes table stores user flavor preferences.
Restrictions
Therestrictions table defines dietary restrictions and allergies.
Junction Tables
Junction tables implement many-to-many relationships:Profile Relationships
profiles_tastesRecipe Relationships
recipe_meal_typesEntity Relationship Diagram
The database follows this relationship structure:Cascade Behavior
The schema implements the following cascade rules:DELETE CASCADE:
- Deleting a user deletes their profile and plans
- Deleting a plan deletes all daily menus
- Deleting a daily menu deletes all meal details
- Deleting a profile removes all taste/restriction/diet type associations
- Recipes cannot be deleted if referenced in meal details
Model Files
All models are located inbackend/app/models/:
user.py- User authentication modelprofile.py- User nutritional profilerecipe.py- Recipe and nutritional dataplan.py- Meal plan containerdaily_menu.py- Daily meal schedulemeal_detail.py- Individual meal entrymeal_type.py- Meal time categoriesdiet_type.py- Diet style categoriestaste.py- Flavor preferencesrestriction.py- Dietary restrictions- Junction tables:
profile_taste.py,profile_restriction.py,profile_diet_type.py,recipe_meal_type.py,recipe_diet_type.py
Working with Models
Example of accessing related data:All relationships use lazy loading by default. For performance-critical queries, use
joinedload() or selectinload() to eager load relationships.