Track calories and macros by photo or text with Google Gemini, plus barcode scanning and quick-add favorites. Installable PWA with offline manual logging. Built for personal use — bring your own Gemini API key (free tier works).
- Next.js 16 (App Router) + React 19 + Tailwind v4
- Supabase — Postgres, Auth (Google + magic-link), Storage
- Google Gemini via
@google/genai(BYOK, defaultgemini-2.5-pro) - Serwist service worker for PWA / offline
- USDA FoodData Central (text search) + Open Food Facts (barcodes)
- Deploys free on Vercel
- AI calls are proxied through
/api/analyze. Each user pastes their own Gemini key in Settings; it's AES-256-GCM encrypted and stored in a service-role-onlyuser_secretstable — never shipped to the browser. - Food entries/items/favorites are stored per-user with Row-Level Security.
- Manual entries logged offline are queued in IndexedDB and synced on reconnect.
- Node.js 20+ (tested on v22)
- A free Supabase project
- A free USDA FoodData Central API key
- (Optional) Google OAuth credentials for "Continue with Google"
- Each user needs a Gemini API key (entered in-app)
npm install
cp .env.local.example .env.local # then fill in values (see below)- Create a project at supabase.com.
- SQL Editor → New query → paste the contents of
supabase/migrations/0001_init.sqland run it. This creates all tables, RLS policies, themeal-photosstorage bucket, and a trigger that auto-creates a profile row on signup. - Project Settings → API: copy the Project URL, the
anonpublic key, and theservice_rolekey into.env.local. - Authentication → URL Configuration: set Site URL to
http://localhost:3000(and your Vercel URL in production), and add…/auth/callbackas a redirect URL. - (Optional) Authentication → Providers → Google: enable it and paste your Google OAuth client ID/secret.
NEXT_PUBLIC_SUPABASE_URL=... # Supabase Project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY=... # anon public key
SUPABASE_SERVICE_ROLE_KEY=... # service_role key (server-only secret)
APP_ENCRYPTION_KEY=... # 32-byte base64: openssl rand -base64 32
CRON_SECRET=... # any random string: openssl rand -hex 16
USDA_FDC_API_KEY=... # free USDA key
NEXT_PUBLIC_SITE_URL=http://localhost:3000A ready-to-use APP_ENCRYPTION_KEY was generated into .env.local for you.
npm run dev # http://localhost:3000Sign in → complete onboarding (sets your TDEE-based targets) → open Settings and paste your Gemini API key → start logging from the + button.
- Push to a Git repo and import it in Vercel.
- Add all the env vars above in Project Settings → Environment Variables
(set
NEXT_PUBLIC_SITE_URLto your Vercel domain). - Update the Supabase Site URL / redirect URLs to your Vercel domain.
- The daily photo-cleanup cron is configured in
vercel.json(runs/api/cron/cleanup-photosat 03:00 UTC, authorized viaCRON_SECRET).
src/
app/
(app)/ # authenticated shell: dashboard, add, history, settings
api/ # analyze, settings/key, barcode, food-search, cron
auth/callback/ # PKCE redirect (OAuth + magic link)
login, onboarding
manifest.ts, sw.ts
components/ # UI: AddFood, ReviewEditor, TodayView, HistoryView, …
lib/ # supabase clients, crypto, nutrition/TDEE, gemini prompt, outbox
supabase/migrations/ # database schema
- AI features require a saved Gemini key; manual / barcode / favorites logging works without one.
- Gemini free-tier quota is per-user (BYOK). Switch model to
gemini-2.5-flashin Settings if you hit Pro limits. - Photos live in a private bucket; enable auto-delete in Settings to purge them after N days.