Skip to content

Nish2005karsh/Calorie-tracker

Repository files navigation

πŸ₯— CalorieAI β€” Your Smart Nutrition Tracker

Snap a photo of your meal and let AI instantly log its calories and macros. CalorieAI turns nutrition tracking from a tedious chore into a one-tap habit β€” with personalized goals, streaks, analytics, and more.


πŸ“– What is CalorieAI?

CalorieAI is a modern web app that helps you eat healthier without the friction of manual food logging. Instead of searching databases and guessing portion sizes, you simply take a photo of your food β€” an AI vision model identifies the meal and estimates its full nutritional breakdown (calories, protein, carbs, fat, fiber, sugar, sodium) plus a health score.

Around that core, the app gives you everything you need to actually stick with your goals: a personalized calorie & macro plan, a daily dashboard, water and weight tracking, a streak-and-badge system to keep you motivated, and rich analytics over time.

In one sentence: Onboard β†’ get a personalized plan β†’ snap your meals β†’ watch your progress.


πŸ–ΌοΈ Screenshots

Landing Page Onboarding Flow Authentication (Clerk)
Landing Flow Login/Signup
Personalized Plan Meal Logging Dashboard & Insights
Summary Meal Logging Dashboard

The original AI pipeline was built as an n8n workflow (shown below). It has since been fully reimplemented in application code β€” see How the AI works.

Legacy n8n Flow


🌟 Features

  • πŸ“Έ AI meal recognition β€” photograph your food and get instant calories, macros, a confidence score, and a health rating.
  • ⌨️ Manual entry β€” type in a meal's nutrition by hand when you prefer.
  • πŸ”– Barcode scanning β€” scan a packaged product's barcode to auto-fill nutrition from the Open Food Facts database.
  • 🎯 Personalized goals β€” your daily calorie & macro targets are computed from your body stats and goals using the Mifflin-St Jeor equation (not hardcoded guesses).
  • πŸ“Š Daily dashboard β€” calories remaining, macro distribution donut, per-meal breakdown, and day-by-day navigation.
  • πŸ—“οΈ Calendar view β€” a color-coded month grid showing how each day measured against your goal.
  • πŸ“ˆ Analytics β€” weekly/monthly calorie trends, macro trends, and a weight-progress chart.
  • πŸ”₯ Streaks & badges β€” build a logging habit and unlock milestone badges (3, 7, 10, 14, 21 days).
  • πŸ’§ Water tracking β€” log your daily glasses toward a hydration goal.
  • βš–οΈ Weight tracking β€” log weigh-ins and visualize the trend over time.
  • βš™οΈ Settings β€” edit goals/weights, recalculate your plan, switch units, and manage your account.
  • πŸŒ— Dark mode β€” light / dark / system theme.
  • πŸ” Secure auth β€” sign-up/sign-in via Clerk, with per-user data isolation enforced by Supabase Row-Level Security.

⚑ How It Works

  1. Sign up with Clerk (email or social login).
  2. Onboard β€” a short, guided flow asks for your gender, body stats, weight goal, activity level, and pace. From this, CalorieAI generates a personalized calorie & macro plan.
  3. Log meals β€” snap a photo, scan a barcode, or type it in. The AI fills in the nutrition; you review and save.
  4. Track everything β€” meals, water, and weight all roll up into your daily dashboard.
  5. Stay motivated β€” keep your streak alive, earn badges, and watch your trends in Analytics.

πŸ€– How the AI Works

CalorieAI's nutrition analysis is powered by Google Gemini's vision model, called directly from the app.

Note on the architecture change: the meal-analysis pipeline was originally built as a hosted n8n workflow (a webhook that called an LLM vision API and a second LLM to format the result β€” pictured in the screenshot above). When that hosting was retired, the entire workflow was rebuilt natively in the codebase. There is no external webhook anymore β€” everything runs in our own code.

The current flow (src/lib/gemini.ts):

  1. The meal image is converted to base64 in the browser.
  2. It's sent to Gemini with a detailed "AI Nutrition Analyst" prompt.
  3. Gemini's structured-output feature (responseSchema) returns strictly-typed JSON in a single call β€” collapsing what used to be two separate n8n nodes (vision analysis + JSON formatting) into one.
  4. The validated result (mealName, calories, protein, carbs, fat, fiber, sugar, sodium, confidenceScore, healthScore, rationale) is shown for review and saved to Supabase.

πŸ’» Tech Stack

Layer Technology
Frontend React 18, TypeScript, Vite
UI Tailwind CSS, shadcn/ui, Recharts, Motion
Authentication Clerk
Database Supabase (Postgres + Row-Level Security)
AI / Vision Google Gemini
Barcode lookup Open Food Facts + ZXing
Deployment Vercel

πŸš€ Getting Started

Prerequisites

1. Clone & install

git clone https://github.com/Nish2005karsh/Calorie-tracker.git
cd Calorie-tracker
npm install

2. Set up the database

In your Supabase project, open the SQL Editor and run the contents of supabase_setup.sql. This creates all tables (daily_meals, user_profiles, user_streaks, user_badges, weight_logs, water_logs) and their Row-Level-Security policies in one go.

3. Connect Clerk to Supabase (Third-Party Auth)

So Supabase trusts Clerk-issued logins:

  1. In Clerk β†’ enable the Supabase integration and copy your Clerk domain (e.g. https://your-app.clerk.accounts.dev).
  2. In Supabase β†’ Authentication β†’ Third-Party Auth β†’ Add provider β†’ Clerk, and paste that domain.

4. Configure environment variables

Create a .env.local file in the project root:

# Supabase
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your_supabase_publishable_key

# Clerk
VITE_CLERK_PUBLISHABLE_KEY=pk_test_your_clerk_key

# Google Gemini
VITE_GEMINI_API_KEY=your_gemini_api_key
# Optional: override the model (default: gemini-2.0-flash)
# VITE_GEMINI_MODEL=gemini-2.0-flash

5. Run it

npm run dev

Open the local URL Vite prints (usually http://localhost:8080).


☁️ Deployment (Vercel)

  1. Push the repo to GitHub and import it into Vercel (it auto-detects Vite β€” build command npm run build, output dist).
  2. Add the same environment variables from .env.local under Settings β†’ Environment Variables.
  3. Deploy, then add your *.vercel.app URL to Clerk's allowed origins.

SPA routing is handled by vercel.json so deep links (e.g. /dashboard) work on refresh.


πŸ“ Project Structure

src/
β”œβ”€ pages/                 # Route screens
β”‚  β”œβ”€ Landing.tsx         # Marketing page (hero, how-it-works, features, testimonials)
β”‚  β”œβ”€ Dashboard.tsx       # Daily overview: calories, macros, meals, water, streaks
β”‚  β”œβ”€ Analytics.tsx       # Trend charts
β”‚  β”œβ”€ Calendar.tsx        # Month grid of daily intake
β”‚  β”œβ”€ Settings.tsx        # Goals, units, theme, account
β”‚  β”œβ”€ onboarding/         # Guided multi-step onboarding flow
β”‚  └─ dashboard/AddMeal.tsx  # Photo / barcode / manual meal entry
β”œβ”€ components/            # Reusable UI (Footer, HowItWorks, BarcodeScanner, ui/*)
β”œβ”€ hooks/                 # useOnboarding, etc.
└─ lib/
   β”œβ”€ gemini.ts           # AI meal analysis (replaces the old n8n workflow)
   β”œβ”€ openfoodfacts.ts    # Barcode β†’ nutrition lookup
   β”œβ”€ goals.ts            # Mifflin-St Jeor calorie & macro calculation
   β”œβ”€ supabase.ts         # Supabase client + Clerk third-party auth
   β”œβ”€ api.ts              # Meals, profile, weight, water data access
   β”œβ”€ streaks.ts          # Streaks & badges
   └─ analytics.ts        # Weekly/monthly aggregation

πŸ“œ License

MIT

About

A smart calorie-tracking app built with React (TSX), Clerk Auth, Supabase DB, ShadCN UI, and n8n workflows. Not deployed online yet due to workflow dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages