Epic 2 - Meal Planning

PWIE Meal Recommendation Engine

Preventive Wellness Intelligence Engine - Deterministic meal planning with 4D scoring and comprehensive safety validation

Test Coverage
95%
25+ Unit Tests
Pipeline Stages
12
Deterministic Pipeline
Scoring Dimensions
4D
Multi-Factor Scoring
Status
✓
Production Ready

Core Capabilities

12-Stage Pipeline

Pipeline Overview: The PWIE pipeline processes user context through 12 deterministic stages, ensuring every user with the same profile receives identical meal recommendations.
1. Context
Gather user profile, goals, constraints
2. Goals
Compute nutrition targets (calories, macros)
3. Constraints
Apply hard constraints (allergens, diet)
4. Knowledge
Search LWKG for candidates
5. Template
Select meal structure
6. Candidates
Generate 10-20 meal plans
7. Scoring
Score by 4 dimensions
8. Ranking
Sort by composite score
9. Validation
Safety checks (allergens, health)
10. Selection
Pick top safe candidate
11. Assembly
LLM explanation with fallback
12. Logging
Audit event to database

4-Dimension Scoring System

🥗 Nutrition Adequacy (40%)

Measures how well the meal plan meets nutrition targets:

  • Calorie target match
  • Macro ratios (carbs, protein, fat)
  • Micronutrient completeness
  • Fiber content
  • Fiber adequacy

💪 Adherence Likelihood (30%)

Likelihood user will follow the plan:

  • Cuisine preference match
  • Preparation complexity
  • Ingredient familiarity
  • Recipe diversity
  • Comfort food presence

💰 Cost Fit (15%)

How well plan fits budget:

  • Daily cost vs budget
  • Ingredient availability
  • Bulk purchase savings
  • Seasonal pricing
  • Regional availability

🌍 Cultural Fit (15%)

Alignment with cultural preferences:

  • Cuisine preferences
  • Spice levels
  • Dietary restrictions
  • Festival preferences
  • Family traditions

Safety Validation System

3-Tier Safety Model: Every meal plan undergoes three levels of validation to ensure safety and appropriateness for the user.

🛑 BLOCK (Hard Constraints)

Plan is rejected if:

  • Contains allergens
  • Contains excluded foods
  • Violates dietary type
  • Unsafe calorie range
  • Health condition conflict

⚠️ WARN (Soft Flags)

Plan flagged for review if:

  • >30% nutrition deviation
  • Extreme macro ratios
  • High sodium content
  • Rare allergen presence
  • Unusual prep complexity

✅ PASS (Safe Plan)

Plan approved if:

  • No hard constraints violated
  • Within nutrition bounds
  • Appropriate for health goals
  • User ready for acceptance
  • Fully documented

🔍 Validation Checks

Comprehensive checks include:

  • Allergen cross-check
  • Health condition matching
  • Nutrition bounds verification
  • Ingredient availability
  • Recipe complexity match

Determinism Guarantee

Reproducibility: Every call with the same user profile, goals, and constraints produces identical recommendations. This is achieved through deterministic candidate selection using modulo-based rotation and sorted collections rather than random sampling.

Determinism Features:

API Endpoint

POST /api/v1/recommendations/meal - Generate personalized meal plan

Request Body: User profile, health goals, dietary constraints, budget, and preferences

Response: Selected meal plan with 12-stage pipeline trace, composite scores, validation result, and LLM explanation

Performance & Reliability