Skip to content

AMVamsi/food-diary

Repository files navigation

Food Diary

AI-powered mobile food diary — photograph a meal to identify it, or search ingredients manually. Built with React Native, FastAPI, and the LogMeal food recognition API.

CI AI Usage Check codecov GitHub Release License

Android iOS

React Native Expo TypeScript React Navigation Zustand

Python FastAPI Pydantic Docker Ruff

Supabase Railway


What it does

Food Diary lets users track daily calorie intake through two logging flows:

  • Photo log — take a photo or pick one from the gallery. The image is sent to the LogMeal segmentation API, which returns bounding boxes and top-5 dish candidates for each detected food region. Users confirm (or correct) each region, edit the serving size in grams, and kcal updates instantly without an extra API call.
  • Manual log — search a locally cached ingredient catalogue (≈3 000 items), add ingredients to a basket, set grams per item, and compute total kcal in one call.

All entries are stored in a date-grouped diary with per-day kcal totals, photo thumbnails, and swipe-to-delete. An optional profile screen tracks weight, height, goal, and dietary preference, with live BMI calculation.


Architecture

Android App  (Expo / React Native + TypeScript)
      │
      │  HTTPS + Bearer JWT
      ▼
FastAPI  (Railway)  ─────────────────────────────┐
  ├── /auth       →  Supabase Auth               │
  ├── /profile    →  Supabase Postgres            │
  ├── /diary      →  Supabase Postgres            │
  └── /logmeal/*  →  LogMeal API  (key server-side only)
                                                  │
                     Supabase Storage  ◄──────────┘
                     (meal-images bucket — public URL
                      stored in diary_entries.image_url)

The mobile app never calls LogMeal directly. The LOGMEAL_API_KEY lives only in Railway environment variables and is never shipped in the APK.


Stack

Layer Technology
Mobile React Native, Expo SDK 54, TypeScript (strict)
State Zustand — one store per domain
Backend Python 3.12, FastAPI 0.115, httpx async
Database Supabase Postgres (profiles, diary entries, ingredient cache)
Auth Supabase Auth — JWT, OTP email verification, auto-refresh
Storage Supabase Storage — meal-images bucket
AI LogMeal API — food segmentation, confirmation, nutrition
Deployment Railway (backend), EAS Build (Android APK)

Getting started

Run the one-shot setup script to wire git hooks, create the Python virtualenv, install mobile dependencies, and validate project files:

bash setup.sh

Or set up each part manually:

Prerequisites

Tool Version
Python 3.12
Node.js ≥ 20
EAS CLI latest — npm install -g eas-cli

Backend

cd backend
python3 -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env          # fill in the three variables below
uvicorn app.main:app --reload

requirements.lock is the pinned lockfile generated from requirements.txt. The Dockerfile uses the lockfile for reproducible builds. To update dependencies: pip-compile requirements.txt -o requirements.lock

Confirm it is running:

curl http://127.0.0.1:8000/health
# {"status":"ok"}

Mobile

cd mobile
npm install

Create mobile/.env:

EXPO_PUBLIC_API_URL=https://food-diary-production-cd15.up.railway.app

Start the dev server and press a to open on an Android device or emulator:

npx expo start

Environment variables

backend/.env

Variable Description
SUPABASE_URL Supabase project URL
SUPABASE_SECRET_KEY Service role key — backend only, never in mobile
LOGMEAL_API_KEY LogMeal API bearer token — backend only, never in mobile

mobile/.env

Variable Description
EXPO_PUBLIC_API_URL FastAPI backend base URL
EXPO_PUBLIC_SUPABASE_URL Supabase project URL (for client-side session refresh)
EXPO_PUBLIC_SUPABASE_ANON_KEY Supabase anon key (public — safe in mobile)

APK

Download APK

Requires Android 10 (API 29) or later. To install: go to Settings → Apps → Special app access → Install unknown apps, enable installation from your browser or file manager, open the APK, and tap Install.


Demo

https://www.youtube.com/watch?v=bUg6UNzSWow


Repository structure

food-diary/
├── backend/          FastAPI — auth, profile, diary, LogMeal proxy
│   ├── app/
│   │   ├── routers/  auth.py  profile.py  diary.py  logmeal.py
│   │   ├── models/   schemas.py
│   │   ├── middleware/auth_guard.py
│   │   └── db/       supabase.py
│   └── Dockerfile
├── mobile/           Expo React Native — Android app
│   └── src/
│       ├── screens/  PhotoLogScreen  ManualLogScreen  DiaryScreen  ProfileScreen
│       ├── components/BboxOverlay  Toast  Button  Input  PickerField
│       ├── store/    auth.ts  diary.ts
│       ├── api/      client.ts
│       └── theme/    colors  spacing  typography
├── docs/             Architecture and user manual
├── .github/          CI workflow and Copilot instructions
├── .githooks/        Pre-commit AI usage guardrail
├── .vscode/          Recommended extensions, workspace settings, and debug configs
└── setup.sh          One-shot dev environment bootstrap

Docs

About

An AI-powered food diary application for nutrition

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors