Skip to content

About

AI-powered pantry and grocery analytics platform for receipt scanning, expiry tracking, reminders, waste insights, and grocery price inflation monitoring.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

88 Commits

Folders and files

Repository files navigation

FridgeLedger

FridgeLedger is an AI-assisted pantry and grocery analytics platform. It turns grocery receipts into structured pantry records, estimates food shelf life, tracks spending over time, and highlights price increases from repeat purchases.

The application is built as a full-stack web product with a Next.js frontend, FastAPI backend, Supabase Auth/Postgres/Storage, and Amazon Bedrock for receipt understanding.

Features

  • Supabase authentication: Email/password sign-up and login with JWT-protected backend APIs.
  • AI receipt scanning: Upload receipt images and extract merchant, purchase date, item names, quantities, prices, categories, and shelf-life estimates.
  • Receipt assistant: Ask follow-up questions or request corrections against the uploaded receipt image.
  • Private receipt image storage: Receipt images are stored in Supabase Storage and served through short-lived signed URLs.
  • Duplicate receipt detection: Warns when a receipt from the same merchant and purchase date already exists.
  • Pantry tracking: View extracted food items, expiry estimates, and item status.
  • Usage and waste status: Mark items as consumed, wasted, or restore them to active.
  • Reminders: Create grocery reminders and track pending tasks.
  • Expiry emails: Send immediate or scheduled email reminders for food expiring soon.
  • Analytics dashboard: Visualize monthly spending, category spending, store spending, expiry status, waste ratio, and price inflation trends.
  • Telegram webhook: Scan receipt photos and ask receipt-related questions through a Telegram bot integration.

Tech Stack

Layer Technology
Frontend Next.js 16, React 19, TypeScript, Tailwind CSS 4
State/Data TanStack Query, Supabase JS
Charts Recharts
Backend Python, FastAPI, Pydantic, Uvicorn
Database Supabase Postgres
Auth Supabase Auth
Storage Supabase Storage
AI Amazon Bedrock Converse API
Email Gmail SMTP
Bot Telegram Bot API
Local Orchestration npm + concurrently

Architecture

Browser / Mobile Web
  -> Next.js App Router frontend
  -> Supabase Auth for sessions
  -> FastAPI backend with Bearer token validation
  -> Amazon Bedrock for receipt extraction and correction
  -> Supabase Postgres for receipts, items, reminders, and notifications
  -> Supabase Storage for private receipt images
  -> Gmail SMTP for expiry reminder emails
  -> Telegram webhook for bot-based receipt scanning

The model performs perception and structuring tasks. Financial and pantry logic, such as price-change detection, expiry grouping, duplicate checks, and waste metrics, remains deterministic in application code.

Repository Structure

.
|-- backend/
|   |-- api/index.py                  # Serverless entrypoint
|   |-- app/
|   |   |-- api/                      # FastAPI routers
|   |   |-- core/                     # Settings and auth helpers
|   |   |-- schemas/                  # Pydantic models
|   |   |-- services/                 # Bedrock, Supabase, email, Telegram services
|   |   `-- main.py                   # FastAPI app factory
|   |-- scripts/                      # Maintenance and cron scripts
|   |-- requirements.txt
|   `-- vercel.json
|-- frontend/
|   |-- app/                          # Next.js routes
|   |-- components/                   # Shared UI shell/providers
|   |-- lib/                          # Supabase, API, store, hooks, types
|   |-- package.json
|   `-- next.config.ts
|-- supabase/
|   `-- migrations/                   # RLS, storage, reminders, item status migrations
|-- test/
|-- package.json                      # Root dev runner
`-- README.md

Application Routes

Route Purpose
/login Sign in
/signup Create account
/chatbot Upload receipts and chat about extraction results
/dashboard High-level spending, receipt, reminder, and expiry overview
/history Browse saved receipts by date
/expiry Track expiring items and mark consumed or wasted
/reminders Manage grocery reminders
/analytics Spending, waste, expiry, and inflation charts
/profile User summary and navigation shortcuts

Backend API

All product APIs require a Supabase access token:

Authorization: Bearer <supabase-access-token>
Method Endpoint Description
GET /health API health check
POST /receipts/scan Parse an uploaded receipt image
POST /receipts/chat Ask/correct a receipt extraction with the image as context
POST /receipts/image Upload a receipt image to private Supabase Storage
GET /receipts/image-url Create a signed URL for a private receipt image
POST /receipts/scan-text Parse pasted receipt text
POST /receipts/{receipt_id}/notify-expiry Send upload-time expiry email notifications
GET /pantry List pantry items, optionally filtered by status
GET /insights/analytics Return spending, expiry, and inflation analytics
GET /insights/waste Return consumed-versus-wasted metrics
POST /telegram/webhook Receive Telegram bot updates

Prerequisites

  • Node.js 20 or newer
  • npm
  • Python 3.11 or newer
  • A Supabase project
  • An AWS account with Bedrock runtime access to the configured model
  • Optional: Gmail app password for expiry emails
  • Optional: Telegram bot token for Telegram receipt scanning

Environment Variables

Create a root .env file. The backend reads ../.env from the backend directory, and the frontend reads public variables through Next.js.

# App
APP_NAME=FridgeLedger API
APP_ENV=development
API_CORS_ORIGINS=http://localhost:3000

# Frontend
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
NEXT_PUBLIC_API_URL=http://127.0.0.1:8000

# Supabase backend access
SUPABASE_URL=
SUPABASE_SERVICE_ROLE_KEY=
SUPABASE_STORAGE_BUCKET=receipts

# AWS Bedrock
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
BEDROCK_MODEL_ID=

# Optional model compatibility settings
MODEL_BASE_URL=
MODEL_NAME=

# Email reminders
GMAIL_SMTP_USER=
GMAIL_SMTP_APP_PASSWORD=
GMAIL_FROM_EMAIL=

# Telegram
TELEGRAM_BOT_TOKEN=

Never expose SUPABASE_SERVICE_ROLE_KEY, AWS credentials, Gmail credentials, or Telegram tokens in frontend code.

Supabase Setup

This repository includes migrations for item status, reminders, expiry email notification tracking, Row Level Security policies, and private receipt image access.

Apply the SQL files in order:

supabase/migrations/202605140001_receipt_item_status.sql
supabase/migrations/202605140002_security_rls_storage.sql

The application expects these main tables:

  • receipts: receipt header records with id, user_id, merchant, purchase_date, saved_at, and image_url.
  • receipt_items: extracted receipt line items with receipt_id, name, normalized_name, category, quantity, unit, price, shelf_life_days, status, and used_at.
  • reminders: user-created grocery reminders.
  • expiry_email_notifications: sent-email audit records.

Storage buckets used by the app:

  • receipt-images
  • receipts

Both buckets should be private. The backend creates signed URLs for display.

Local Development

Install frontend and root dependencies:

npm install
cd frontend
npm install

Create and install the backend virtual environment:

cd backend
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt

Run both apps from the repository root:

npm run dev

Or run them separately:

cd backend
.venv\Scripts\activate
uvicorn app.main:app --reload
cd frontend
npm run dev

Default local URLs:

  • Frontend: http://localhost:3000
  • Backend: http://127.0.0.1:8000
  • Health check: http://127.0.0.1:8000/health

Useful Scripts

Send expiry reminder emails in dry-run mode:

cd backend
python scripts/send_expiry_reminder_emails.py

Send real expiry reminder emails and record notifications:

cd backend
python scripts/send_expiry_reminder_emails.py --apply

Backfill receipt item category, normalized name, and shelf life:

cd backend
python scripts/backfill_shelf_life.py

Migrate older receipt image URLs into private Supabase Storage paths:

cd backend
python scripts/migrate_receipt_images_private.py

Quality Checks

Frontend lint:

cd frontend
npm run lint

Frontend production build:

cd frontend
npm run build

Backend smoke check:

cd backend
uvicorn app.main:app --reload

Then open:

http://127.0.0.1:8000/health

Deployment Notes

  • Deploy the frontend as a Next.js app and set all NEXT_PUBLIC_* variables.
  • Deploy the backend as an ASGI FastAPI service and set server-side secrets there.
  • Configure API_CORS_ORIGINS to include the production frontend origin.
  • Ensure Bedrock model access is enabled in the AWS region configured by AWS_REGION.
  • Keep Supabase Storage buckets private and serve images through signed URLs.
  • Run send_expiry_reminder_emails.py --apply on a daily scheduler for recurring expiry notifications.
  • Configure the Telegram webhook URL to point to /telegram/webhook if using the bot integration.

Security Model

  • Frontend Supabase queries rely on RLS policies scoped to auth.uid().
  • Backend APIs validate Supabase JWTs before returning user data.
  • Backend database access uses the Supabase service role key and must only run server-side.
  • Receipt image paths are namespaced by user ID.
  • Signed image URLs are short-lived and generated only after ownership checks.
  • Receipt upload size is limited to 8 MB at the API boundary.
  • Images sent to Bedrock are compressed when needed to stay under model limits.

Product Status

FridgeLedger is an MVP-stage full-stack product. The core workflow is implemented: authenticate, upload receipt, extract grocery items, save pantry data, review receipt history, track expiry and waste, manage reminders, and view analytics. The most important next improvements are adding a complete baseline database migration, automated tests, and production observability.

About

AI-powered pantry and grocery analytics platform for receipt scanning, expiry tracking, reminders, waste insights, and grocery price inflation monitoring.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages