Skip to content

Multi-Recipe Consolidation #54

@akisma

Description

@akisma

Description

Extend the ingredient consolidation logic to handle multiple recipes from a meal plan. When generating a shopping list for a week's worth of meals, ingredients across all recipes should be intelligently combined. This prevents duplicate items and provides accurate quantities for bulk shopping.

Acceptance Criteria (Gherkin)

Scenario: Consolidate same ingredients across recipes
  Given Monday dinner needs "2 cups flour"
  And Wednesday lunch needs "1.5 cups flour"
  When I generate a shopping list for the week
  Then the list contains "flour, 3.5 cups"

Scenario: Handle different units
  Given recipe A needs "500g chicken"
  And recipe B needs "1 lb chicken"
  When consolidated
  Then the list shows "chicken, 1.5 lbs" (or equivalent normalized unit)

Scenario: Respect serving adjustments
  Given recipe A serves 4 and I planned for 2
  And recipe B serves 2 and I planned for 6
  When consolidated
  Then ingredients are scaled (0.5x for A, 3x for B) before combining

Scenario: Preserve recipe associations
  Given I generate a list from 5 recipes
  When I view a shopping list item
  Then I can see which recipes required it
  And the quantity breakdown per recipe

Scenario: Category organization
  Given ingredients from multiple recipes
  When the shopping list is generated
  Then items are grouped by category (produce, dairy, etc.)

Technical Notes

File: backend/src/services/multi-recipe-consolidation.service.ts

Service Methods:

interface MealPlanShoppingListRequest {
  mealPlanId: string;
  dateRange?: { start: Date; end: Date };
  excludeRecipeIds?: string[];
}

interface ConsolidatedIngredient {
  name: string;
  normalizedName: string;
  totalQuantity: number;
  unit: string;
  category: string;
  sources: {
    recipeId: string;
    recipeName: string;
    quantity: number;
    servingsPlanned: number;
  }[];
}

async generateFromMealPlan(request: MealPlanShoppingListRequest): Promise<ConsolidatedIngredient[]>

Algorithm:

  1. Fetch all meal plan items in date range
  2. For each item, get recipe ingredients scaled to planned servings
  3. Normalize ingredient names (lowercase, singular, standardized)
  4. Group by normalized name
  5. Convert units to common base where possible
  6. Sum quantities
  7. Track source recipe for each contribution

Unit Normalization:

  • Leverage Measurement Conversion Service #49 Measurement Conversion Service
  • Prefer larger sensible units (cups over tablespoons for large amounts)
  • Keep original units if conversion not possible

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions