Skip to content

Repository files navigation

Cal AI Logo

Cal AI

AI-Powered Calorie Tracker with Local Food Recognition

Next.js React Supabase PyTorch Tailwind


Overview

Cal AI is a full-stack calorie tracking web application that uses a locally-running AI model to recognize food from images. Simply snap a photo of your meal, and the app identifies the food, estimates nutritional values, and logs it to your daily tracker β€” all without sending your data to any external AI service.

Key Highlights

  • πŸ€– Local AI Model β€” Food recognition runs on your machine via a ViT (Vision Transformer) model trained on Food-101. No cloud API keys needed for scanning.
  • πŸ“Έ Snap & Scan β€” Take a photo or upload an image to instantly classify food and get nutritional breakdown.
  • βš–οΈ Adjustable Portions β€” Slide to set portion size (25g–800g) and watch macro values recalculate live.
  • πŸ“Š Dashboard & Progress β€” Track daily calories, macros, weight trends, and streaks with smooth animated charts.
  • πŸ” Supabase Auth β€” Secure email-based authentication with Row Level Security.
  • πŸ“± Mobile-First Design β€” Optimized for phones with bottom navigation, swipeable calendars, and touch-friendly interactions.

Features

πŸ” Food Scan Page

  • Camera capture or image upload for food recognition
  • Text search β€” type a food name (e.g., "pizza", "sushi") for quick lookup against 101 food categories
  • AI confidence score displayed for each classification
  • Portion size slider (25g–800g) with live macro recalculation
  • Editable results β€” adjust food name, ingredients, and individual macro values before logging

🏠 Home Dashboard

  • Daily macro rings β€” visual progress for Calories, Protein, Carbs, and Fat
  • Swipeable weekly calendar β€” tap any day to view that day's meals
  • Monthly heatmap view β€” see goal adherence at a glance (green = met goal, red = exceeded)
  • Meal cards β€” view, edit, or delete logged meals with inline editing

πŸ“ˆ Progress Page

  • Weight tracking chart β€” interactive line chart with 7D/30D/60D/90D timeframes
  • Streak counter β€” consecutive days of meal logging
  • Weight logging modal β€” quick weight entry with unit preference (lbs/kg)

πŸ‘€ Profile Page

  • Avatar upload β€” profile photo with Supabase Storage
  • Personal details β€” name, weight, goal weight, unit preference
  • Daily goals β€” customizable targets for calories, protein, carbs, and fat

Tech Stack

Layer Technology
Frontend Next.js 16, React 19, TypeScript
Styling Tailwind CSS 4
Animations Framer Motion
Charts Recharts
Icons Lucide React
Auth & Database Supabase (PostgreSQL + Auth + Storage)
AI Model PyTorch + HuggingFace Transformers (nateraw/food β€” ViT on Food-101)
Model Server Python Flask
Nutritional Data Bundled JSON database (101 food categories, per-100g macros)

Project Structure

calorie_tracker_webapp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx                    # Landing/splash page
β”‚   β”‚   β”œβ”€β”€ layout.tsx                  # Root layout
β”‚   β”‚   β”œβ”€β”€ globals.css                 # Global styles
β”‚   β”‚   β”œβ”€β”€ auth/                       # Authentication page
β”‚   β”‚   β”œβ”€β”€ actions/
β”‚   β”‚   β”‚   └── scan.ts                 # Server actions (calls model API)
β”‚   β”‚   └── (app)/                      # Authenticated app routes
β”‚   β”‚       β”œβ”€β”€ layout.tsx              # App layout (header + nav)
β”‚   β”‚       β”œβ”€β”€ home/page.tsx           # Dashboard
β”‚   β”‚       β”œβ”€β”€ scan/page.tsx           # Food scanner
β”‚   β”‚       β”œβ”€β”€ progress/page.tsx       # Weight & progress charts
β”‚   β”‚       └── profile/page.tsx        # User profile & settings
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ ui/                         # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ layout/                     # Navigation components
β”‚   β”‚   β”œβ”€β”€ auth/                       # Auth components
β”‚   β”‚   └── shared/                     # Shared components
β”‚   └── lib/
β”‚       β”œβ”€β”€ supabase.ts                 # Supabase client
β”‚       └── utils.ts                    # Utility functions
β”œβ”€β”€ food-recognition-model/
β”‚   β”œβ”€β”€ server.py                       # Flask API server
β”‚   β”œβ”€β”€ requirements.txt                # Python dependencies
β”‚   β”œβ”€β”€ config.json                     # Model configuration
β”‚   β”œβ”€β”€ nutritional_database.json       # 101 food categories (per-100g macros)
β”‚   └── classification_model.h5         # Model reference
β”œβ”€β”€ supabase/
β”‚   └── schema.sql                      # Database schema + RLS policies
β”œβ”€β”€ start.sh                            # One-command startup script
β”œβ”€β”€ .env.example                        # Environment template
└── package.json                        # Node dependencies

Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • Python β‰₯ 3.10
  • Supabase account (free tier works)

1. Clone & Install

git clone https://github.com/your-username/calorie_tracker_webapp.git
cd calorie_tracker_webapp
npm install

2. Set Up Supabase

  1. Create a new project at supabase.com
  2. Run the SQL from supabase/schema.sql in the Supabase SQL Editor
  3. Copy your project URL and anon key

3. Configure Environment

cp .env.example .env

Edit .env with your Supabase credentials:

NEXT_PUBLIC_SUPABASE_URL="https://your-project.supabase.co"
NEXT_PUBLIC_SUPABASE_ANON_KEY="your-anon-key"
FOOD_MODEL_URL=http://localhost:5001

4. Set Up the AI Model

cd food-recognition-model
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Note: The first run downloads the ViT model (~350 MB). After that, it loads from cache instantly.

5. Start Everything

Option A β€” Single command (recommended):

./start.sh

This starts both servers concurrently and handles cleanup on Ctrl+C.

Option B β€” Manual (two terminals):

# Terminal 1 β€” AI Model Server
cd food-recognition-model
source venv/bin/activate
python server.py

# Terminal 2 β€” Next.js
npm run dev

6. Open the App

Navigate to http://localhost:3000 in your browser.


API Endpoints (Model Server)

The Python model server runs at http://localhost:5001:

Endpoint Method Description
/api/health GET Health check β€” returns model status and food count
/api/classify POST Image classification β€” accepts multipart/form-data with image field
/api/classify-text POST Text search β€” accepts JSON {"text": "pizza"}

Example Response (Image Classification)

{
  "food_name": "Pizza",
  "calories": 500,
  "protein": 24,
  "carbs": 60,
  "fat": 20,
  "portion_grams": 200,
  "confidence": 94.2,
  "per_100g": {
    "calories": 250,
    "protein": 12.0,
    "carbs": 30.0,
    "fat": 10.0
  },
  "ingredients": [
    { "name": "Pizza", "calories": 500, "protein": 24, "carbs": 60, "fat": 20 }
  ],
  "all_predictions": [
    { "label": "Pizza", "confidence": 94.2 },
    { "label": "Bruschetta", "confidence": 2.1 }
  ]
}

Database Schema

The app uses three main tables in Supabase:

profiles         meals              weight_logs
β”œβ”€β”€ id (UUID)    β”œβ”€β”€ id (UUID)      β”œβ”€β”€ id (UUID)
β”œβ”€β”€ display_name β”œβ”€β”€ user_id (FK)   β”œβ”€β”€ user_id (FK)
β”œβ”€β”€ weight       β”œβ”€β”€ food_name      β”œβ”€β”€ weight
β”œβ”€β”€ goal_weight  β”œβ”€β”€ calories       └── logged_date
β”œβ”€β”€ daily_*_goal β”œβ”€β”€ protein
β”œβ”€β”€ avatar_url   β”œβ”€β”€ carbs
                 β”œβ”€β”€ fat
                 β”œβ”€β”€ ingredients
                 β”œβ”€β”€ image_url
                 └── created_at

All tables use Row Level Security (RLS) β€” users can only access their own data.


Supported Food Categories

The model recognizes 101 food categories from the Food-101 dataset, including:

View all 101 categories
Apple Pie Baby Back Ribs Baklava Beef Carpaccio
Beef Tartare Beet Salad Beignets Bibimbap
Bread Pudding Breakfast Burrito Bruschetta Caesar Salad
Cannoli Caprese Salad Cappuccino Carrot Cake
Ceviche Cheesecake Cheese Plate Chicken Curry
Chicken Quesadilla Chicken Wings Chocolate Cake Chocolate Mousse
Churros Clam Chowder Club Sandwich Crab Cakes
Crème Brûlée Croque Madame Cupcakes Deviled Eggs
Donuts Dumplings Eggs Benedict Escargots
Falafel Filet Mignon Fish And Chips Foie Gras
French Fries French Onion Soup French Toast Fried Calamari
Fried Rice Frozen Yogurt Garlic Bread Gnocchi
Greek Salad Grilled Cheese Sandwich Grilled Salmon Guacamole
Gyoza Hamburger Hot And Sour Soup Hot Dog
Huevos Rancheros Hummus Ice Cream Lasagna
Lobster Bisque Lobster Roll Sandwich Macaroni And Cheese Macarons
Miso Soup Mussels Nachos Omelette
Onion Rings Oysters Pad Thai Paella
Pancakes Panna Cotta Peking Duck Pho
Pizza Pork Chop Poutine Prime Rib
Pulled Pork Sandwich Ramen Ravioli Red Velvet Cake
Risotto Samosa Sashimi Scallops
Seaweed Salad Shrimp And Grits Spaghetti Bolognese Spaghetti Carbonara
Spring Rolls Steak Strawberry Shortcake Sushi
Tacos Takoyaki Tiramisu Tuna Tartare
Waffles

License

MIT


Built with ❀️ by Anvesh Mishra

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages