Case Study

NutriPlan

AI-powered meal planning with vector embeddings and personalised nutrition

Production meal planning platform with FastAPI async backend serving iOS frontend, using GPT-4o and pgvector for personalised weekly meal plans.

Overview

NutriPlan is an AI meal planning app combining user preferences, dietary constraints, and nutrition science to generate personalised weekly meal plans. The backend uses FastAPI and GPT-4o; the RAG pipeline retrieves candidate meals via pgvector similarity search before LLM optimisation. Deployed on Render.com with Supabase PostgreSQL. SwiftUI iOS frontend is in beta.

Problem

Meal planning is time-consuming and requires balancing taste, nutrition, and constraints. Most tools are template-based and static. NutriPlan personalises plans using AI: learning from feedback, adapting to preferences, and generating meals that hit precise calorie and macro targets using UK nutrition guidelines.

Key Decisions and Trade-offs

  • RAG over pure LLM generation. Pure GPT-4o generation risks repeated meals. RAG first retrieves ~100 candidate meals via pgvector similarity, then LLM optimises within that candidate set. Trade-off is latency; payoff is quality and diversity.
  • GPT-4o + GPT-4o-mini. Used GPT-4o for meal generation (quality) and GPT-4o-mini for feedback analysis (cost efficiency). LiteLLM abstraction lets us swap models without code changes.
  • Vector embeddings for preferences. User feedback updates preference embeddings rather than explicit rules. Learns implicitly what meals the user likes.
  • Async FastAPI. Async throughout for high throughput on Render's free tier. Structured Pydantic models for type safety.

Stack and Why

Layer Technology Rationale
Frontend Swift/SwiftUI, iOS 26 Native iOS performance with Liquid Glass design system.
Backend API FastAPI (Python) Async, high performance, automatic OpenAPI docs, Pydantic validation.
Database Supabase (PostgreSQL 15) Managed PostgreSQL with pgvector extension, RLS for security.
Vector Search pgvector with text-embedding-3-small 1536-dim embeddings, cosine similarity for meal retrieval.
LLM GPT-4o (meal gen), GPT-4o-mini (feedback) Quality primary model, cost-efficient secondary. Abstracted via LiteLLM.
Deployment Render.com Simple deploy from GitHub, environment variables, free tier adequate for MVP.

What Shipped

  • FastAPI backend: Async endpoints for meal plan generation, swapping, feedback, and nutrition analytics.
  • RAG pipeline: Vector similarity search over meal database, LLM optimisation with calorie/macro targeting.
  • Nutrition engine: Henry/Oxford equations per SACN guidelines. Targets within +/- 10% accuracy, supports macro splits (e.g. 40% carbs, 30% protein, 30% fat).
  • Preference learning: User feedback updates preference embeddings. 14-day meal history to avoid repetition.
  • Meal swapping: Intelligence swap logic finding alternatives matching similar taste profiles, macros, and constraints.
  • iOS frontend: SwiftUI interface for onboarding, viewing plans, swapping meals, and providing feedback.

Metrics

  • Calorie accuracy: within +/- 10% of target
  • Macro targeting: user-defined ratios with < 5% variance
  • Generation latency: < 2 seconds end-to-end (RAG + LLM)
  • API uptime: 99.8% on Render.com
  • User feedback integration: 100+ meals in preference embeddings database

What Is Next

Complete SwiftUI iOS implementation and launch beta. Integrate real recipe APIs (Spoonacular, Edamam) for richer meal database. Build web dashboard for meal history and analytics. Plan progression: free tier (calorie tracker), premium tier (meal planning), pro tier (advanced personalisation and macro tracking).

Learn more: GitHub repository