How raj-sarkar123/nutrition-recommendation- works
1. Purpose and Runtime Topology
NutriScan AI is a full-stack nutrition tracking and AI meal-analysis application. A React/Vite single-page client calls an Express REST API; the backend coordinates Supabase persistence, AI analysis, image/OCR processing, email OTP, and notifications. Frontend deployment is configured for Vercel; the README identifies Render for backend deployment.
• frontend/src/main.jsx
• frontend/src/App.jsx
• backend/server.js
2. Client Application and Navigation
The frontend is the primary user entry point. App.jsx routes users through authentication, onboarding, dashboard, scan, analysis, meal tracking, insights, profile, and progress views. Shared layout/navigation separates app-shell concerns from page features.
• frontend/src/App.jsx
• frontend/src/components/layout/AppLayout.jsx
• frontend/src/pages/ScanPage.jsx
3. Client State and API Boundary
React contexts centralize cross-page state for authentication, nutrition data, scanning, notifications, and Supabase realtime synchronization. HTTP communication is isolated through an Axios client, while browser-side Supabase access supports realtime subscriptions. This creates a boundary between UI state/realtime events and backend-owned REST workflows.
• frontend/src/api/axios.js
• frontend/src/context/AuthContext.jsx
• frontend/src/context/RealtimeSyncContext.jsx
4. Express API Composition and Security
backend/server.js is the backend entry point and mounts domain route modules for auth, users, meals, scans, progress, and notifications. Controllers implement request orchestration; JWT middleware protects authenticated endpoints. CORS and multipart upload handling are explicit middleware boundaries.
• backend/server.js
• backend/middleware/auth.js
• backend/routes/scan.routes.js
5. Identity and User Lifecycle
Authentication supports registration/login and session access through auth routes/controllers, backed by JWTs. OTP state and email delivery are implemented separately, indicating verification or password-recovery flows. User profile/onboarding information is handled as a dedicated user domain rather than embedded in meal operations.
• backend/controllers/auth.controller.js
• backend/data/otpStore.js
• backend/services/email.service.js
6. Scan-to-Nutrition Analysis Pipeline
The scan domain accepts uploaded food/menu images, preprocesses them, extracts or parses content, calculates nutritional values, then invokes Groq-backed analysis for recommendations. Temporary uploads form a filesystem boundary before AI/nutrition processing; the trained OCR data file indicates local OCR capability.
• backend/controllers/scan.controller.js
• backend/services/imagePreprocess.service.js
• backend/services/analysis.groq.service.js
7. Nutrition, Tracking, and Insights Flow
Meal operations persist or retrieve food-log data, while progress operations aggregate intake/goals into tracking views. The client exposes this through dashboard, tracker, progress, analysis, and smart-insights pages. Nutrition calculation is a dedicated service, keeping deterministic macro computation separate from AI-generated guidance.
• backend/controllers/meal.controller.js
• backend/controllers/progress.controller.js
• backend/services/nutrition.calc.js
8. Persistence, Realtime, and External Services
Supabase is the database integration point in both backend and frontend. SQL files define core schema extensions and realtime notification setup. Notifications have an API/controller/service path and client subscription/UI path. External dependencies include Supabase, Groq, Gemini (per README/environment), nutrition APIs, and email infrastructure.
• backend/config/supabase.js
• database/realtime_notifications_setup.sql
• frontend/src/lib/supabaseClient.js
Main entry points: server.js Express server · auth.controller.js Auth controller · supabase.js Backend Supabase client · App.jsx App router
Components 22
React Client
- App router · Routes authentication and nutrition-tracking views.
frontend/src/App.jsx - App layout
frontend/src/components/layout/AppLayout.jsx - Scan page
frontend/src/pages/ScanPage.jsx - Auth context
frontend/src/context/AuthContext.jsx - Realtime sync context
frontend/src/context/RealtimeSyncContext.jsx - Axios API client
frontend/src/api/axios.js - Browser Supabase client
frontend/src/lib/supabaseClient.js
Express API
- Express server · Composes domain routes and middleware.
backend/server.js - JWT middleware
backend/middleware/auth.js - Scan routes
backend/routes/scan.routes.js - Auth controller
backend/controllers/auth.controller.js - Scan controller
backend/controllers/scan.controller.js - Meal controller
backend/controllers/meal.controller.js - Progress controller
backend/controllers/progress.controller.js
Processing Services
- Image preprocessing · Processes uploaded food or menu images before analysis.
backend/services/imagePreprocess.service.js - Nutrition calculator
backend/services/nutrition.calc.js - Groq analysis
backend/services/analysis.groq.service.js - OTP store
backend/data/otpStore.js - Email service
backend/services/email.service.js
Data & External Systems
- Backend Supabase client
backend/config/supabase.js - Supabase · Shared persistence and realtime platform.
- Realtime notification setup
database/realtime_notifications_setup.sql
Connections 25
- App router → App layout: renders
- App router → Scan page: routes to
- App router → Auth context: uses
- Scan page → Axios API client: submits scans
- Realtime sync context → Browser Supabase client: subscribes through
- Axios API client → Express server: REST requests
- Express server → JWT middleware: protects endpoints
- Express server → Scan routes: mounts
- Express server → Auth controller: auth requests
- Express server → Meal controller: meal requests
- Express server → Progress controller: progress requests
- Scan routes → Scan controller: dispatches
- Scan controller → Image preprocessing: preprocesses upload
- Image preprocessing → Nutrition calculator: extracts food input
- Nutrition calculator → Groq analysis: provides nutrition context
- Scan controller → Groq analysis: requests recommendations
- Meal controller → Nutrition calculator: calculates macros
- Auth controller → OTP store: manages OTPs
- Auth controller → Email service: sends verification email
- Auth controller → Backend Supabase client: persists users
- Meal controller → Backend Supabase client: reads and writes logs
- Progress controller → Backend Supabase client: reads intake and goals
- Backend Supabase client → Supabase: connects to
- Browser Supabase client → Supabase: realtime subscriptions
- Realtime notification setup → Supabase: configures notifications