A mobile-first Progressive Web App that helps people with medical conditions make safe food choices while grocery shopping.
Live Demo Β· Documentation Β· Report Bug Β· Request Feature
- About The Project
- Key Features
- Tech Stack
- Getting Started
- Usage
- Project Structure
- Testing
- Deployment
- API Documentation
- Contributing
- Citation
- License
- Contact
- Acknowledgments
DietScan (ScanSafe) bridges the gap between doctor's dietary advice and real grocery shopping decisions. Instead of manually reading labels and cross-referencing medical restrictions, users simply scan products to get instant, personalized safe/caution/avoid verdicts.
People with medical conditions face daily challenges:
- Complex dietary restrictions from doctors
- Overwhelming nutrition labels
- Uncertainty about food safety
- Time-consuming manual label reading
- Risk of consuming harmful foods
DietScan provides:
- Instant Analysis: Scan any barcode or ingredient label
- AI-Powered Guidance: Personalized verdicts based on your condition
- Medical Accuracy: GPT-4o analyzes products against your diet plan
- Guest-Friendly: Try 3 scans before signing in
- Multi-Disease Support: Manage multiple conditions seamlessly
- Next.js 14 - React framework with App Router
- TypeScript - Type safety
- Tailwind CSS - Styling
- Prisma - Database ORM
- NextAuth.js - Authentication
- OpenAI GPT-4o - AI analysis
- ZXing-js - Barcode scanning
- Open Food Facts - Product database
- Neon - Serverless PostgreSQL
- Vercel - Deployment
- Intelligent auto-suggestions for specific disease variants
- 400ms debounced search for smooth UX
- Handles misspellings naturally
- 8 clinically specific suggestions per query
- AI-generated plans tailored to your condition
- Editable: Add/remove items based on doctor's advice
- Structured format: Avoid / Prefer / Watch / Nutrients
- Saved to database or localStorage (guest mode)
- Client-side scanning with ZXing-js (no server needed)
- Supports EAN-13, UPC-A, Code 128, QR codes, and more
- Works on iOS 14.3+ and Android
- Instant product lookup from Open Food Facts (3M+ products)
- GPT-4o Vision extracts ingredients from photos
- Fallback when barcode isn't available
- Works with any language on the label
- Smart image quality guidance
- Three clear states: Safe / Caution / Avoid
- Disease-specific reasoning (2-3 sentences)
- Flagged nutrients highlighted
- Safe alternative suggestions
- Track all your scans (authenticated users)
- Review past decisions
- Export-ready for doctor visits
- Manage multiple conditions
- Quick switching between diseases
- One active disease at a time for scanning
- Try 3 scans without signing in
- Soft authentication prompts
- Seamless data migration on sign-in
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14.2.35 | Full-stack React framework |
| React | 18 | UI library |
| TypeScript | 5.x | Type safety |
| Tailwind CSS | 3.4.1 | Utility-first styling |
| Technology | Version | Purpose |
|---|---|---|
| Next.js API Routes | 14.2.35 | RESTful API |
| Prisma ORM | 7.4.2 | Database access |
| Neon PostgreSQL | 16 | Serverless database |
| NextAuth.js | 5.0.0-beta.30 | Google OAuth |
| Service | Model/Version | Purpose |
|---|---|---|
| OpenAI GPT-4o | latest | Disease suggestions, diet plans |
| OpenAI GPT-4o-mini | latest | Verdict analysis |
| OpenAI GPT-4o Vision | latest | Ingredient OCR |
| Open Food Facts API | v2 | Product database |
| ZXing-js | 0.21.3 | Barcode scanning |
| Technology | Version | Purpose |
|---|---|---|
| Vitest | 4.0.18 | Unit testing |
| React Testing Library | 16.3.2 | Component testing |
| fast-check | 4.5.3 | Property-based testing |
| ESLint | 8.x | Code linting |
- Node.js 18+ (Download)
- npm or yarn
- PostgreSQL database (Neon recommended)
- OpenAI API key (Get one)
- Google OAuth credentials (Setup guide)
-
Clone the repository
git clone https://github.com/priyamjyotsna/ScanSafe.git cd ScanSafe -
Install dependencies
npm install
-
Setup environment variables
cp .env.example .env
Edit
.envwith your credentials (see Environment Setup) -
Generate Prisma client
npx prisma generate --schema=prisma/schema.prisma
-
Run database migrations
npx prisma migrate dev
-
Start development server
npm run dev
Create a .env file in the root directory:
# Database (Neon PostgreSQL)
DATABASE_URL="postgresql://user:pass@host/dietscan?sslmode=require&pgbouncer=true"
DIRECT_URL="postgresql://user:pass@host/dietscan?sslmode=require"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-generated-secret" # Generate: openssl rand -base64 32
# Google OAuth (from Google Cloud Console)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# OpenAI
OPENAI_API_KEY="sk-..."
# App
NEXT_PUBLIC_APP_URL="http://localhost:3000"
# Rate Limiting (requests per window per user/IP)
RATE_LIMIT_DISEASE_SUGGEST=10
RATE_LIMIT_DIET_PLAN_GENERATE=5
RATE_LIMIT_INGREDIENT_OCR=10
RATE_LIMIT_VERDICT=20
RATE_LIMIT_WINDOW_MS=60000Mobile camera access requires HTTPS:
npm run dev:httpsAccess at https://localhost:3000
Note: You'll see a browser warning about self-signed certificate. Click "Advanced" β "Proceed to localhost".
-
Setup (one-time):
- Enter your medical condition
- Review AI-generated diet plan
- Edit if needed (add doctor's specific instructions)
-
Daily Use:
- Open the app
- Scan product barcode or ingredient label
- Get instant verdict: Safe / Caution / Avoid
- Read reasoning and flagged nutrients
-
Multi-Disease:
- Add multiple conditions
- Switch active disease anytime
- Each has its own diet plan
# Development
npm run dev # Start dev server
npm run dev:https # Start with HTTPS (for camera)
npm run build # Build for production
npm start # Start production server
npm run lint # Lint code
# Database
npx prisma generate # Generate Prisma client
npx prisma migrate dev # Run migrations (dev)
npx prisma migrate deploy # Deploy migrations (prod)
npx prisma studio # Open visual DB browser
# Testing
npm test # Run all tests
npm run test:watch # Watch mode
npx vitest <file> # Run specific testdietscan/
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Migration files
β
βββ src/
β βββ app/ # Next.js App Router
β β βββ api/ # API routes
β β β βββ disease/suggest/ # AI disease suggestions
β β β βββ diet-plan/ # Diet plan generation
β β β βββ scan/ # Barcode, OCR, verdict
β β β βββ user/ # User profile
β β βββ setup/ # Disease selection & diet plan
β β βββ scan/ # Scanner & verdict
β β βββ profile/ # User profile
β β βββ (auth)/signin/ # Sign-in page
β β
β βββ components/
β β βββ auth/ # Auth components
β β βββ diet-plan/ # Diet plan display
β β βββ disease/ # Disease search
β β βββ scanner/ # Barcode & OCR
β β βββ verdict/ # Verdict display
β β βββ ui/ # Reusable UI components
β β
β βββ hooks/ # Custom React hooks
β βββ lib/ # Core utilities
β βββ types/ # TypeScript types
β βββ utils/ # Helper functions
β βββ test/ # Test setup
β
βββ public/ # Static assets
βββ .env.example # Environment template
βββ DOCUMENTATION.md # Complete documentation
βββ DietScan-TechSpec.md # Technical specification
βββ README.md # This file
- Components: ~80% coverage
- Hooks: ~90% coverage
- Utils: ~95% coverage
- API routes: ~70% coverage
# Run all tests once
npm test
# Watch mode (re-run on file changes)
npm run test:watch
# Run specific test file
npx vitest src/components/Button.test.tsx
# Run with coverage report
npx vitest --coverageTests are co-located with source files:
src/components/Button.tsx
src/components/Button.test.tsx
-
Push to GitHub
git push origin main
-
Import in Vercel
- Go to vercel.com
- Click "New Project"
- Import from GitHub
- Select your repository
-
Configure Environment Variables
In Vercel dashboard β Settings β Environment Variables, add all variables from
.env.example -
Update Google OAuth
In Google Cloud Console β APIs & Services β Credentials:
- Add
https://your-app.vercel.app/api/auth/callback/googleto authorized redirect URIs
- Add
-
Deploy
Vercel automatically deploys on push to main
The build script in package.json includes Prisma client generation:
{
"scripts": {
"build": "prisma generate --schema=prisma/schema.prisma && next build"
}
}| Endpoint | Method | Purpose |
|---|---|---|
/api/disease/suggest |
POST | Get AI disease suggestions |
/api/diet-plan/generate |
POST | Generate personalized diet plan |
/api/diet-plan/save |
POST | Save user's diet plan |
/api/scan/barcode |
POST | Lookup product by barcode |
/api/scan/ingredients |
POST | Extract ingredients via OCR |
/api/scan/verdict |
POST | Analyze product safety |
/api/scan/history |
POST | Save scan to history |
/api/user/profile |
GET | Get user profile |
/api/user/profile |
PUT | Update user profile |
/api/user/active-disease |
PATCH | Switch active disease |
POST /api/scan/verdict
Content-Type: application/json
{
"diseaseName": "Type 2 Diabetes",
"dietPlan": {
"avoid": ["High sugar foods"],
"prefer": ["Whole grains"],
"watch": ["Carbohydrate intake"],
"nutrients": { "Sugar": "< 5g/serving" }
},
"product": {
"name": "Chocolate Bar",
"ingredients": ["Sugar", "Cocoa", "Milk"],
"nutrients": { "sugar": 25, "carbohydrates": 30 }
}
}Response:
{
"verdict": "AVOID",
"reason": "Very high sugar content (25g) exceeds your limit of 5g per serving. This could cause dangerous blood sugar spikes for Type 2 Diabetes.",
"flaggedNutrients": ["sugar"],
"safeAlternative": "Look for sugar-free dark chocolate with <5g sugar per serving."
}See DOCUMENTATION.md for complete API documentation.
Contributions are what make the open source community amazing! Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'feat: add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
We follow Conventional Commits:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changes (formatting, etc.)refactor:Code refactoringtest:Adding or updating testschore:Maintenance tasks
If you use this project in your research or work, please cite it:
@software{dietscan2026,
author = {Priyamjyotsna},
title = {DietScan (ScanSafe): AI-Powered Food Safety Scanner for Medical Conditions},
year = {2026},
publisher = {GitHub},
url = {https://github.com/priyamjyotsna/ScanSafe},
doi = {10.5281/zenodo.18942716}
}DOI: https://doi.org/10.5281/zenodo.18942716
This project is private and proprietary. All rights reserved.
Priyamjyotsna - @priyamjyotsna
Project Link: https://github.com/priyamjyotsna/ScanSafe
Live Demo: https://scan-safe.vercel.app
- Next.js - The React framework for production
- OpenAI - AI models for medical analysis
- Open Food Facts - Open product database
- Neon - Serverless PostgreSQL
- Vercel - Deployment platform
- ZXing - Barcode scanning library
- Tailwind CSS - Utility-first CSS framework
- Prisma - Next-generation ORM
Built with β€οΈ for better health management