Skip to content

About

Macro Meter: AI calorie and macro tracker (installable web app). Google Gemini reads food photos or text. Next.js, Supabase, offline support.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🔥 Macro Meter — AI Calorie & Macro Tracker (PWA)

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).

Stack

  • Next.js 16 (App Router) + React 19 + Tailwind v4
  • Supabase — Postgres, Auth (Google + magic-link), Storage
  • Google Gemini via @google/genai (BYOK, default gemini-2.5-pro)
  • Serwist service worker for PWA / offline
  • USDA FoodData Central (text search) + Open Food Facts (barcodes)
  • Deploys free on Vercel

How it works

  • 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-only user_secrets table — 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.

1. Prerequisites

2. Install

npm install
cp .env.local.example .env.local   # then fill in values (see below)

3. Supabase setup

  1. Create a project at supabase.com.
  2. SQL Editor → New query → paste the contents of supabase/migrations/0001_init.sql and run it. This creates all tables, RLS policies, the meal-photos storage bucket, and a trigger that auto-creates a profile row on signup.
  3. Project Settings → API: copy the Project URL, the anon public key, and the service_role key into .env.local.
  4. Authentication → URL Configuration: set Site URL to http://localhost:3000 (and your Vercel URL in production), and add …/auth/callback as a redirect URL.
  5. (Optional) Authentication → Providers → Google: enable it and paste your Google OAuth client ID/secret.

4. Environment variables

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:3000

A ready-to-use APP_ENCRYPTION_KEY was generated into .env.local for you.

5. Run

npm run dev      # http://localhost:3000

Sign in → complete onboarding (sets your TDEE-based targets) → open Settings and paste your Gemini API key → start logging from the + button.

6. Deploy to Vercel

  1. Push to a Git repo and import it in Vercel.
  2. Add all the env vars above in Project Settings → Environment Variables (set NEXT_PUBLIC_SITE_URL to your Vercel domain).
  3. Update the Supabase Site URL / redirect URLs to your Vercel domain.
  4. The daily photo-cleanup cron is configured in vercel.json (runs /api/cron/cleanup-photos at 03:00 UTC, authorized via CRON_SECRET).

Project layout

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

Notes & limits

  • 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-flash in Settings if you hit Pro limits.
  • Photos live in a private bucket; enable auto-delete in Settings to purge them after N days.

About

Macro Meter: AI calorie and macro tracker (installable web app). Google Gemini reads food photos or text. Next.js, Supabase, offline support.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages