LabelLens is an AI-powered food label scanner that helps users decide whether a product fits their dietary needs (allergies, dietary preferences, and medical/health goals). Users save their preferences once, then upload a product/ingredient label image to get a personalized safety analysis and a history of past scans.
- Personalized preferences: store allergies, dietary preferences, medical conditions, and health goals per user.
- Image-based scanning: drop/upload an image and receive extracted product info + ingredients.
- Conflict detection: ingredients are checked against saved preferences and flagged by severity.
- Nutrition + alternatives: estimates basic nutrition and suggests safer alternatives.
- History: view past scans and drill into prior results.
- Frontend: React, TypeScript, TailwindCSS, Vite, Axios, React Router
- Backend: Python, FastAPI, Uvicorn, Pillow
- Auth/DB: Supabase (Auth + Postgres)
- AI: Google Gemini API (
google-generativeai)
backend/ # FastAPI API + Gemini pipeline + Supabase integration
frontend/ # React UI (Vite) + Supabase Auth client
The backend runs a 3-stage pipeline:
- Vision analysis: extract product name/brand/ingredients from the image using Gemini.
- Conflict analysis: compare ingredients against user preferences and mark the product safe/unsafe.
- Nutrition & alternatives: estimate nutrition and suggest 2–3 alternatives; alternatives are cached by an ingredient hash.
One way to think about “risk” is a weighted sum of detected conflicts:
[ R = \sum_{i=1}^{n} w_i \cdot \mathbf{1}[\text{conflict}_i] ]
- Node.js (recommended: 18+)
- Python (recommended: 3.10+)
- A Supabase project (URL + keys)
- A Gemini API key
Create backend/.env:
SUPABASE_URL="https://YOUR_PROJECT.supabase.co"
SUPABASE_SERVICE_KEY="YOUR_SUPABASE_SERVICE_ROLE_KEY"
GEMINI_API_KEY="YOUR_GEMINI_KEY"Notes:
SUPABASE_SERVICE_KEYis used server-side; do not expose it in the frontend.
Create frontend/.env:
# Backend base URL (FastAPI)
VITE_API_URL="http://localhost:8000"
# Supabase (client-side)
VITE_SUPABASE_URL="https://YOUR_PROJECT.supabase.co"
VITE_SUPABASE_ANON_KEY="YOUR_SUPABASE_ANON_KEY"cd backend
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Health checks:
GET /→ “LabelLens API is running”GET /health→{ "status": "healthy" }
cd frontend
npm install
npm run devOpen the Vite dev server URL shown in your terminal (typically http://localhost:5173).
Base URL (local): http://localhost:8000
POST /users/— create user + preferencesGET /users/{user_id}— fetch user + preferencesPUT /users/{user_id}— update preferences
POST /scan— scan a base64 image ({ image, user_id })POST /scan/upload— scan via multipart form upload (file,user_id)GET /scan/{scan_id}— fetch a scan by id
GET /history/{user_id}?limit=50— list scans (most recent first)GET /history/{user_id}/{scan_id}— get full detail for a specific scan
The backend reads/writes these tables:
usersuser_id(string)preferences(json)created_at(string/timestamp)updated_at(string/timestamp)
scansuser_id(string)product_name(string)brand(string nullable)safe(boolean)conflicts(json array)alternatives(json array)nutrition(json)timestamp(string/timestamp)
cached_alternativesingredient_hash(string)alternatives(json array)created_at(string/timestamp)
The backend currently uses permissive CORS settings. In real deployments, CORS can still fail depending on browser rules and whether credentials/cookies are involved.
If you see CORS errors:
- Set
allow_originsto your exact frontend domain(s) (e.g.,https://your-app.vercel.app) instead of["*"]. - If you need credentials, avoid wildcard origins and ensure the frontend request includes credentials consistently.
- Verify preflight (
OPTIONS) requests succeed and that the backend returns the expectedAccess-Control-*headers.
- Confirm
VITE_API_URLpoints to your backend (local:http://localhost:8000). - Confirm your backend is actually running on port
8000.
- Frontend: Vercel (typical)
- Backend: Railway (typical)
Make sure to:
- Configure environment variables in both platforms.
- Update
VITE_API_URLto the deployed backend URL. - Configure CORS origins to include the deployed frontend domain.
Python, TypeScript, JavaScript, HTML, CSS, FastAPI, React, TailwindCSS, Supabase, Gemini API