Sprint6_DetailedNutrition_Decisions.md 2.2 KB

Sprint 6: US-08 Detailed Nutritional Information — Technical Decisions

Overview

Sprint 6 (User Story #08 / US-08) enhances the food search results by providing a structured, in-depth nutritional breakdown for every food item. It builds upon the macro dashboard by adding vitamins, minerals, and extended macronutrient data.


Task #41: Structured Food Detail API

What we chose

  • Granular endpoint: GET /api/food/{food_id}
    • Reasoning: Instead of sending all detailed data for every search result (which would bloat the search payload), we fetch the full profile only when the user specifically requests it.
  • Categorized JSON Structure:
    • Nutrients are grouped into macros, extended, vitamins, and minerals.
    • Reasoning: Makes it easier for the frontend to render distinct "sections" of a nutrition label rather than a flat list of 15+ keys.
  • Data Integrity Fix:
    • Expanded the NUTRIENT_MAP in mega_seed_usda.py to include Calcium (301), Iron (303), Potassium (306), Vitamin A (318), Vitamin C (401), and Cholesterol (601).
    • Re-seeded the database with 7,793 items to ensure all micronutrient columns are populated correctly.
  • Backend security: The endpoint requires a valid JWT Bearer token, ensuring food data is only accessible to authenticated users.

Task #40: Expandable Detail View UI

What we chose

  • On-demand rendering: The detailed panel is empty by default and populated via the API only on the first "Details" click.
  • Visual Feedback: A loading state is shown during the API fetch to ensure a responsive feel.
  • Grid-based Layout: Used a CSS Grid (grid-template-columns: repeat(2, 1fr)) for the nutrient lists.
    • Reasoning: Maximizes vertical space and mimics the look of a traditional nutrition facts panel while remaining readable on mobile.
  • Independent Click Targets:
    • Click Name/Header -> Auto-fill chat (Fast Action).
    • Click "Details" -> Expand/Collapse (Investigation Action).
    • Reasoning: Preserves the fast "Add to Meal" workflow while allowing deep-dives.
  • Smooth Transition: max-height transitions combined with glassmorphism effects maintain the premium aesthetic.