Pantry-aware, macro-constrained weekly meal planning for normal people.
Meal Plan Autopilot is a full-stack web app that generates a weekly meal plan using:
- ingredients you already have
- your dietary constraints
- your macro targets
It then produces an aggregated shopping list, surfaces explainable planning decisions, and includes medication/supplement informational checks using public FDA label data.
- Source code: https://github.com/dcsid/meal-plan-autopilot
- Deployment:
render.yamlin this repo provides a one-click Render Blueprint deploy (see Deployment)
Most meal tools are recipe browsers. This project is a decision engine:
- It optimizes for pantry reuse.
- It enforces diet/allergen constraints.
- It scores recipes against macro targets.
- It explains why each recommendation was selected.
- Add pantry items from USDA search results or manual entries.
- Store normalized gram quantities with display units.
- Merge repeated food additions into existing pantry rows.
- Diet tags (for example: vegetarian, halal, gluten-free).
- Allergen/dislike blocking.
- Daily calorie and macro range targets (protein/carbs/fat min/max).
- Candidate recipes are filtered by constraints.
- Recipes are scored by pantry coverage and macro fit.
- Variety bonus reduces repeated main proteins.
- Greedy day-by-day selection consumes pantry quantities over the week.
Each planned day includes:
- macro profile
- pantry usage percentage
- score + macro error
- short explanation string describing why the meal was selected
- Computes missing ingredients from selected recipes vs pantry inventory.
- Returns aggregated quantities (grams) and per-item deficits.
- Local DB search first.
- USDA FoodData Central enrichment when API key is available.
- Remote errors/rate limits are surfaced as metadata for graceful UI handling.
- Uses FDA openFDA label data to gather interaction/diet/nutrient signals.
- Includes disclaimers and clinician handoff text by design.
- Avoids prescriptive medical directives.
- Uses location-aware nearby store discovery (OSM Nominatim).
- Builds budget/tradeoff recommendation options.
- Returns strategy-ranked store plans and estimated basket totals.
flowchart LR
UI["Browser UI (HTML/CSS/JS)"] --> API["Flask API (/api/*)"]
API --> DB["SQLite / SQLAlchemy models"]
API --> USDA["USDA FoodData Central"]
API --> FDA["FDA openFDA (drug labels)"]
API --> OSM["OpenStreetMap Nominatim / Overpass"]
app/routes/ui.pyGET /app shellGET /healthzhealth endpoint
app/routes/meal.py- API endpoints for pantry/preferences/macros/plan generation/lookup/recommendations
app/services/meal_planner.py- day-by-day selection logic with pantry consumption
app/services/recipe_filter.py- filtering and scoring primitives
app/services/food_lookup.py- local + USDA search, merge, and rank
app/services/drug_interactions.py- FDA label lookup and interaction/diet signal extraction
app/services/smart_shopping.py- budget-aware store recommendation strategies
app/services/store_locator.py- nearby store discovery and profiling
app/services/restaurant_finder.py- restaurant ranking module (API surface available)
app/services/geocoding.py- address/location geocoding
Main SQLAlchemy models (app/models.py):
FoodItem- canonical food record, macro values per 100g, optional USDA
fdc_id
- canonical food record, macro values per 100g, optional USDA
PantryItem- inventory quantity in grams + display unit/quantity
Recipe- recipe metadata, diet tags, macros per serving
RecipeIngredient- recipe-to-food many-to-many join with grams per ingredient
UserPreferences- persisted diet tags, allergens, dislikes
MacroTarget- calories + macro min/max targets
GeneratedPlan- history of generation events
Scoring logic (from app/services/recipe_filter.py):
coverage = covered_ingredients / total_ingredients
macro_error = |protein - protein_target| + |carbs - carbs_target| + |fat - fat_target|
score = (coverage * 3.0) - (macro_error * 0.5) + variety_bonus
Generation loop (from app/services/meal_planner.py):
- Load recipes and filter by user constraints.
- For each day, score each candidate with current pantry state.
- Select highest-scoring recipe.
- Consume pantry grams for selected ingredients.
- Repeat for requested day count.
- Build macro summary and shopping list from selected recipes.
Variety behavior:
- first use of a protein gets a positive bonus
- repeated proteins get reduced/negative bonus
- repeated exact recipes receive an additional penalty
GET /GET /healthz
GET /api/bootstrapGET /api/foods/search?q=<term>&limit=<1..50>&page=<1..50>POST /api/location/geocode
GET /api/pantryPOST /api/pantryPUT /api/pantry/<id>DELETE /api/pantry/<id>
GET /api/preferencesPUT /api/preferencesGET /api/macro-targetPUT /api/macro-target
GET /api/recipesPOST /api/meal-plan/generate
POST /api/interactions/checkPOST /api/shopping/recommendPOST /api/restaurants/recommend
git clone https://github.com/dcsid/meal-plan-autopilot.git
cd meal-plan-autopilot
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
cp .env.example .env
python3 run.pyOpen: http://127.0.0.1:5000
From .env.example:
FLASK_ENV=developmentFLASK_DEBUG=1SECRET_KEY=change-meDATABASE_URL=sqlite:///meal_autopilot.dbAUTO_CREATE_TABLES=trueAUTO_SEED_DATA=trueAUTO_SEED_DEMO_PANTRY=falseUSDA_API_KEY=DEMO_KEY
Notes:
- If
USDA_API_KEYis blank, service falls back toDEMO_KEY. DATABASE_URLsupportspostgresql://...and normalizespostgres://...automatically.
This repo already includes render.yaml and Procfile.
- Push to GitHub.
- In Render, choose
New +->Blueprint. - Select this repo.
- Blueprint path:
render.yaml. - Deploy and share resulting public URL.
- Start command uses Gunicorn:
gunicorn run:app --bind 0.0.0.0:$PORT --workers 2 --threads 4 --timeout 120 --worker-tmp-dir /tmp
- Default free-tier DB target in blueprint:
sqlite:////tmp/meal_autopilot.db
- Data in
/tmpis ephemeral across restarts/redeploys.
source .venv/bin/activate
PYTHONPYCACHEPREFIX=/tmp/pycache pytest -qCurrent test suite validates:
- endpoint contracts and status/error paths
- planner behavior and scoring outcomes
- service-level logic (lookup, constraints, recommendations)
- seed idempotency and bootstrap behavior
- UI route integrity
- USDA
DEMO_KEYcan be rate-limited; production key improves coverage. - Store and restaurant availability/menu information is inferred from public map data and may be incomplete.
- Drug/supplement checks are informational and derived from labeling text; not medical advice.
- SQLite in
/tmpon free hosting is good for demoing, not durable production storage.