YDB-App: Redefining Personal Nutrition with Gemini AI

  1. About the Project

YDB-App (Your Diet Bot) is a next-generation iOS application designed to bridge the gap between visual food consumption and nutritional data. Instead of manually searching through databases for every ingredient, users can simply take a photo of their meal. Using the Gemini 2.5 Flash model, the app performs a multimodal analysis to identify ingredients, estimate portion sizes, and calculate macronutrients in real-time.

  1. Inspiration

The inspiration for YDB-App came from a common frustration: manual calorie counting is a chore that leads to burnout. Most health enthusiasts start tracking their food but stop within a week because typing in "Chicken Breast (150g)" and "Brown Rice (1 cup)" for every meal is tedious. We wanted to build something that felt like a "second brain" for your diet—an assistant that sees what you see and provides instant, actionable health insights.

  1. How We Built It

The project was built using a modern mobile tech stack:

SwiftUI: For a fluid, responsive user interface.

Firebase Authentication: To ensure secure user access and email verification.

Cloud Firestore: To persist user profiles (age, weight, goals) across sessions.

Gemini AI API: To power the vision and nutritional analysis engine.

The Nutritional Logic

The app doesn't just "guess"; it follows established nutritional science. When Gemini analyzes a meal, it calculates the total energy value using the Atwater system. We represent the calorie estimation using the following formula:

$$C_{total} = (4.0 \times P) + (4.0 \times C) + (9.0 \times F)$$

Where:

$C_{total}$ is the total estimated calories.

$P$ is the grams of Protein.

$C$ is the grams of Carbohydrates.

$F$ is the grams of Fat.

We also calculate a Health Score ($H$) based on a weighted average of micronutrient density and the presence of processed sugars:

$$H = \sum_{i=1}^{n} (w_i \cdot \text{Nutrient}i) - \text{Penalty}{sugar}$$

  1. Challenges Faced

Building YDB-App was not without its hurdles. During the development sprint, we faced three major obstacles:

Multimodal Data Integrity: AI models can sometimes return decimals when expecting integers (e.g., $12.5g$ of protein). This originally caused our JSON parser to crash. We solved this by upgrading our data models to use Double types and implementing "bulletproof" decoding logic.

State Synchronization: Managing the transition between "Logged Out," "Email Not Verified," "Profile Not Set," and "Dashboard" was complex. We solved this by building a centralized Master Router in ContentView that monitors the user's progress through the onboarding funnel.

Real-Time Persistence: We struggled with data resetting every time the app was closed. By implementing Firestore with specific user paths (/artifacts/ydb-app/users/{uid}/profile), we ensured that once a user completes their profile, it is saved to the cloud permanently.

  1. What We Learned

This project taught us the importance of Multimodal AI prompting. We learned that the more specific the JSON schema provided to the AI, the more reliable the mobile app becomes. We also gained deep experience in SwiftUI state management, learning how to handle complex navigation stacks without breaking the user experience.

YDB-App is more than just a calorie counter; it's a testament to how AI can make healthy living more accessible for everyone.

Built With

Share this project:

Updates