Skip to content

Aakansh-tandon/FreshTrack_AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FreshTrack AI

Scan ยท Track ยท Cook โ€” Before It Expires

Live Demo License

Next.js 16 React 19 TypeScript Tailwind CSS FastAPI Python Supabase Gemini 2.0

๐Ÿ“– Overview

FreshTrack AI is a full-stack, AI-powered food expiry tracking and waste reduction web application. Designed with a premium dark cyberpunk aesthetic, it helps users track their pantry, intelligently predicts when items will spoil, and automatically generates recipes using expiring ingredients to minimize food waste.


โœจ Features

๐Ÿ“ธ Smart Expiry Scanning

Camera-based OCR using Tesseract.js directly in the browser. It extracts expiry dates with confidence scoring (High/Medium/Low) and supports over 7 different date formats. Privacy first: All OCR processing happens client-side; no image data is ever sent to any external server.

๐Ÿ—„๏ธ Full-Stack Inventory Management

A robust PostgreSQL-backed pantry tracking product name, category, expiry date, and quantity. The system auto-computes status (Fresh โ†’ Expiring Soon โ†’ Critical โ†’ Expired) and days remaining via generated columns. Row Level Security (RLS) ensures strict user data isolation.

โš–๏ธ Weighted Urgency Scoring Algorithm

A dedicated FastAPI microservice calculates a dynamic urgency score per item using the formula: score = (1 / days_remaining) ร— category_weight ร— quantity_factor Items are ranked and displayed with visual urgency badges to prioritize consumption.

๐Ÿค– Automated Recipe Generation Pipeline

Zero user input required. When critical items are detected, a pipeline triggers: detects critical cluster โ†’ ranks by urgency โ†’ sends a structured POST request to Google Gemini 2.0 Flash โ†’ parses the JSON recipe response โ†’ saves to recipe history โ†’ notifies the user.

๐Ÿณ Custom Recipe Generator

Users can specify available ingredients alongside dietary preferences (e.g., gluten-free, vegan). This uses the same Gemini 2.0 Flash pipeline with preference injection for highly tailored culinary suggestions.

๐Ÿ”” Smart Notifications

Database-backed, actionable alerts such as "Milk expires in 2 days โ†’ Make Pancakes". The dashboard auto-refreshes these alerts every 60 seconds. Notifications are triggered automatically upon item addition and auto-recipe generation.

๐Ÿ“Š Waste Reduction Analytics Dashboard

Visualizes your impact using Recharts. Includes a PieChart for inventory status breakdown and a BarChart comparing total category count vs. critical items. Tracks key metrics: Items Saved This Week, Waste Reduction %, Critical Count, and Total Tracked.

โ™ป๏ธ Consumption Tracking

Allows users to mark items as Consumed or Discarded (Expired/Waste). This historical log feeds the analytics engine, enabling precise waste reduction percentage calculations.

๐Ÿ” Supabase Auth

Secure real email/password authentication via JWT. All routes are strictly auth-gated. A pre-configured demo account (demo@freshtrack.ai) with seeded realistic inventory is available for instant exploration.

๐ŸŽจ Premium UI/UX

A sleek dark cyberpunk/neon aesthetic featuring glassmorphism cards and fluid Framer Motion page transitions. The interface is fully responsive, offering a desktop sidebar and a mobile bottom navigation bar, styled with custom color tokens: Primary (#00ff9d), Accent (#00d4ff), and Secondary (#bf00ff).


๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                       CLIENT TIER                           โ”‚
โ”‚  Browser / Mobile Device (React 19, Tailwind, Framer)       โ”‚
โ”‚  [ Tesseract.js (In-Browser OCR) ]                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                              โ”‚
               โ–ผ                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      FRONTEND HOSTING      โ”‚  โ”‚        MICROSERVICE         โ”‚
โ”‚  Vercel (Next.js 16 App)   โ”‚  โ”‚  Render (FastAPI / Python)  โ”‚
โ”‚  - API Routes              โ”œโ”€โ”€โ”ผโ”€โ–บ - Urgency Scoring         โ”‚
โ”‚  - Server Actions          โ”‚  โ”‚   - External AI Calls       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                              โ”‚
               โ–ผ                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    DATABASE & AUTH TIER    โ”‚  โ”‚       AI LLM TIER           โ”‚
โ”‚  Supabase (PostgreSQL)     โ”‚  โ”‚  Google Gemini 2.0 Flash    โ”‚
โ”‚  - Row Level Security      โ”‚  โ”‚  - JSON Recipe Generation   โ”‚
โ”‚  - JWT Auth                โ”‚  โ”‚                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Tech Stack

Layer Technology
Frontend Framework Next.js 16, React 19, TypeScript
Styling & UI Tailwind CSS, shadcn/ui, Framer Motion
Backend Service FastAPI (Python)
Database & Auth Supabase (PostgreSQL + RLS)
LLM / AI Google Gemini 2.0 Flash
Computer Vision Tesseract.js
Data Visualization Recharts
Deployment Vercel (Frontend), Render (Backend)

๐Ÿ—ƒ๏ธ Database Schema

The system relies on 4 core tables managed in Supabase PostgreSQL:

  1. inventory_items
    • id (uuid, PK), user_id (uuid, FK), name (text), category (text), expiry_date (date), quantity (int), status (computed), created_at (timestamp)
  2. consumption_logs
    • id (uuid, PK), item_id (uuid, FK), user_id (uuid, FK), action (text: consumed/discarded), logged_at (timestamp)
  3. recipe_history
    • id (uuid, PK), user_id (uuid, FK), recipe_json (jsonb), used_items (text[]), created_at (timestamp)
  4. notifications
    • id (uuid, PK), user_id (uuid, FK), message (text), type (text), is_read (boolean), created_at (timestamp)

๐Ÿš€ Getting Started

Prerequisites

  • Node.js 18+
  • Python 3.10+
  • Supabase Account
  • Google Gemini API Key

Installation

  1. Clone the repository

    git clone https://github.com/Aakansh-tandon/FreshTrack_AI.git
    cd FreshTrack_AI
  2. Setup the Frontend (Next.js)

    npm install
  3. Setup the Backend (FastAPI)

    cd backend
    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    pip install -r requirements.txt

Environment Variables

Create a .env.local in the root (for Next.js) and a .env in the /backend folder (for FastAPI).

Variable Location Description
NEXT_PUBLIC_SUPABASE_URL Frontend Your Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY Frontend Your Supabase anonymous API key
NEXT_PUBLIC_API_URL Frontend URL of the FastAPI backend (e.g., http://localhost:8000)
SUPABASE_SERVICE_ROLE_KEY Backend Supabase service key for backend admin operations
GEMINI_API_KEY Backend Google Gemini 2.0 Flash API key for recipe generation

Running Locally

Start the FastAPI Backend:

cd backend
uvicorn main:app --reload

(Runs on http://localhost:8000)

Start the Next.js Frontend:

# In the project root
npm run dev

(Runs on http://localhost:3000)


๐Ÿ”Œ API Reference

The FastAPI backend exposes the following endpoints:

Method Endpoint Description
GET /api/inventory Fetch all user inventory items.
POST /api/inventory Add a new item. Body: { name, category, expiry_date, quantity }
PATCH /api/inventory/[id] Update item status or quantity.
POST /api/recipes Generate custom recipe. Body: { ingredients: [], preferences: [] }
GET /api/notifications Fetch user notifications.
POST /api/notifications Create a new alert or mark as read.
GET /api/consumption-logs Fetch historical logs for analytics.
GET /api/auto-trigger Manually invoke the automated recipe pipeline.

โš–๏ธ Urgency Scoring

To prioritize which food needs to be eaten first, the FastAPI service calculates a score based on expiration proximity, item type, and amount.

Formula: Score = (1 / Days Remaining) ร— Category Weight ร— Quantity Factor

Category Weights:

Category Weight Reason
Seafood 2.0 Highest risk of foodborne illness
Meat 1.8 High spoilage risk
Dairy 1.5 Moderate to high spoilage risk
Produce 1.2 Moderate spoilage, visually detectable
Frozen/Pantry 0.5 Long shelf life

Items with higher scores receive priority placement and aggressive UI highlighting.


๐Ÿง  AI Pipeline: Automated Recipe Generation

FreshTrack AI proactively prevents waste by suggesting what to cook before it goes bad.

  1. Trigger: The system detects a cluster of items entering the "Critical" state (โ‰ค 2 days remaining).
  2. Rank: Items are sorted descending by their Urgency Score.
  3. Prompt Construction: The backend formats the top critical ingredients into a structured prompt, enforcing JSON output requirements.
  4. LLM Invocation: The prompt is sent to Google Gemini 2.0 Flash.
  5. Parsing: The response is validated and parsed into a JSON recipe object (title, prep time, instructions, macros).
  6. Persistence & Alert: The recipe is saved to recipe_history and a notification is dispatched to the user dashboard.

๐ŸŽฎ Demo

A pre-populated demo account is available for recruiters and reviewers to instantly explore the dashboard without setting up an account.

Login Credentials:

  • Email: demo@freshtrack.ai
  • Password: (Try logging in via the demo button on the auth page)

What's included in the Demo:

  • A populated pantry with a mix of Fresh, Expiring Soon, and Critical items.
  • Pre-calculated waste reduction analytics on the dashboard.
  • Historical consumption logs.
  • Generated recipes based on the current critical inventory.

๐ŸŒ Deployment

1. Supabase Setup

  • Create a new Supabase project.
  • Execute the provided SQL schema file to generate tables and RLS policies.
  • Retrieve the URL, Anon Key, and Service Role Key.

2. Render Setup (FastAPI)

  • Connect your GitHub repository to Render.
  • Create a new Web Service.
  • Build Command: pip install -r requirements.txt
  • Start Command: uvicorn main:app --host 0.0.0.0 --port 10000
  • Add GEMINI_API_KEY and SUPABASE_SERVICE_ROLE_KEY to Environment Variables.

3. Vercel Setup (Next.js)

  • Import the repository into Vercel.
  • Framework Preset: Next.js.
  • Add NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_ANON_KEY, and NEXT_PUBLIC_API_URL (pointing to the Render URL) to Environment Variables.
  • Click Deploy.

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

FreshTrack AI is an AI-powered food inventory and waste reduction system that uses OCR to extract expiry dates from product labels and intelligently tracks item lifecycles. It automatically identifies items nearing expiry, prioritizes them, and generates smart recipe recommendations using LLMs to help users take timely action

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors