How samadarsh/bitewise works
1. Purpose and deployable entry points
BiteWise is a food-intelligence platform with two bounded product modules: nutrition-aware Swiggy meal ordering (NutriOrder) and shared pantry/meal/grocery planning (SmartPantry). The backend FastAPI application starts at backend/main.py; the browser client is a Next.js App Router application rooted at frontend/app/page.tsx, with authenticated product UI at frontend/app/app/page.tsx and a guided demo at frontend/app/pitch/page.tsx.
2. API composition and persistence boundary
backend/main.py composes route domains for users/authentication, coach/nutrition, recommendations, orders, household, pantry, grocery, and demo data. SQLAlchemy persistence is centralized through backend/db/session.py and backend/db/models.py, with SQLite/PostgreSQL-ready models. Domain-level models live beside their APIs, including backend/household/models.py, backend/pantry/models.py, and backend/recommendations/models.py.
3. Identity, sessions, and Swiggy authorization
User authentication and session handling are separated from Swiggy delegated authorization. backend/auth/user_auth.py and backend/auth/sessions.py protect BiteWise users; backend/auth/swiggy_oauth.py implements OAuth 2.1 PKCE and encrypted token handling for Swiggy. backend/auth/rate_limiter.py forms an API-protection boundary. The frontend supplies auth state and request integration through frontend/lib/auth-context.tsx and frontend/lib/api.ts.
4. NutriOrder decision pipeline
The AI/decision layer converts profile, goals, and preferences into explainable meal candidates. Core orchestration is in agent/pipeline.py and agent/agent.py; it derives nutrition targets and estimates nutrition through agent/nutrition_targets.py and agent/nutrition_estimator.py, then ranks candidates with tradeoffs such as macros, price, delivery, taste, confidence, and priorities in agent/ranking.py. Recommendation APIs/service expose the resulting shortlist via backend/recommendations/service.py and backend/recommendations/routes.py. Caching, memory, resilience, and observability are explicit operational layers in agent/caching.py, agent/memory.py, agent/resilience.py, and agent/observability.py.
5. Food execution and safety boundary
BiteWise consumes Swiggy Food through an MCP client boundary rather than directly embedding provider calls: backend/mcp/swiggy_client.py and mcp/mcp_client.py. Mock implementations (mcp/mcp_mock.py, mcp/instamart_mock.py) support demos and local operation. Order APIs and lifecycle controls are in backend/orders/routes.py and backend/orders/state_machine.py. Execution is deliberately gated by review, explicit confirmation, environment configuration, and the order-placement lock; real Instamart checkout is excluded.
6. SmartPantry household planning flow
Household membership and dietary constraints enter through backend/household/routes.py and are synthesized by backend/household/service.py / backend/household/intelligence.py. Pantry inventory APIs and seeded recipe templates in backend/pantry/routes.py and backend/pantry/templates.py identify stock gaps, cookable recipes, and low-stock conditions. Those gaps flow to grocery-list/category/priority generation and a mock cart preview through backend/grocery/routes.py and backend/grocery/models.py. This module plans purchases; it does not execute Instamart payment or checkout.
7. Client experience, runtime, and infrastructure
The Next.js/React/TypeScript frontend presents NutriOrder dashboards and recommendation controls via frontend/components/NutriOrderDashboard.tsx and frontend/components/RecommendationCard.tsx, while SmartPantry is composed in frontend/components/household/HouseholdDashboard.tsx and related panels. Python/FastAPI runs the API and agent stack; Node.js runs the Next.js client. Docker deployment is represented by Dockerfile and frontend/Dockerfile; render.yaml supplies platform deployment configuration. Runtime behavior, provider mode, credentials, and safety switches are centralized in config/settings.py and .env.example.
Main entry points: main.py API application · session.py SQLAlchemy persistence · pipeline.py Decision pipeline · page.tsx Authenticated product UI
Components 22
Next.js client
- Public entry
frontend/app/page.tsx - Authenticated product UI
frontend/app/app/page.tsx - Guided demo
frontend/app/pitch/page.tsx - NutriOrder dashboard
frontend/components/NutriOrderDashboard.tsx - Household dashboard
frontend/components/household/HouseholdDashboard.tsx - Auth state & API client
frontend/lib/auth-context.tsx
FastAPI platform
- API application · Composes all product route domains.
backend/main.py - User auth & sessions
backend/auth/user_auth.py - Swiggy OAuth PKCE · Encrypts provider tokens.
backend/auth/swiggy_oauth.py - Recommendation service
backend/recommendations/service.py - Order lifecycle · Review and confirmation gate execution.
backend/orders/state_machine.py - SQLAlchemy persistence
backend/db/session.py
NutriOrder intelligence
- Decision pipeline · Builds explainable meal shortlists.
agent/pipeline.py - Nutrition & ranking · Targets, estimates, and ranks macro, price, delivery, taste, and confidence tradeoffs.
agent/ranking.py - Agent operations
agent/caching.py
SmartPantry
- Household intelligence · Synthesizes membership and dietary constraints.
backend/household/intelligence.py - Pantry & recipes · Finds cookable recipes, stock gaps, and low-stock items.
backend/pantry/templates.py - Grocery list & cart preview · Plans categories and priorities without checkout.
backend/grocery/routes.py
Provider & deployment
- Swiggy MCP boundary · Provider calls are isolated behind MCP.
backend/mcp/swiggy_client.py - Mock provider · Supports local and demo operation.
mcp/mcp_mock.py - Runtime safety settings · Controls provider mode, credentials, and placement safety switches.
config/settings.py - Docker deployment
Dockerfile
Connections 30
- Public entry → Authenticated product UI: enters
- Authenticated product UI → NutriOrder dashboard: renders
- Authenticated product UI → Household dashboard: renders
- Guided demo → API application: demo requests
- NutriOrder dashboard → Auth state & API client: uses
- Household dashboard → Auth state & API client: uses
- Auth state & API client → API application: authenticated API calls
- API application → User auth & sessions: protects requests
- API application → Recommendation service: serves
- API application → Order lifecycle: serves
- API application → Household intelligence: serves
- API application → Pantry & recipes: serves
- User auth & sessions → SQLAlchemy persistence: stores users and sessions
- Swiggy OAuth PKCE → SQLAlchemy persistence: stores encrypted tokens
- Recommendation service → Decision pipeline: requests shortlist
- Decision pipeline → Nutrition & ranking: derives and ranks candidates
- Decision pipeline → Agent operations: uses
- Decision pipeline → Swiggy MCP boundary: retrieves food options
- Order lifecycle → Swiggy OAuth PKCE: uses delegated authorization
- Order lifecycle → Swiggy MCP boundary: places only after confirmation
- Swiggy MCP boundary → Mock provider: uses in demo mode
- Household intelligence → Pantry & recipes: applies household constraints
- Pantry & recipes → Grocery list & cart preview: sends stock gaps
- Household intelligence → SQLAlchemy persistence: persists household data
- Pantry & recipes → SQLAlchemy persistence: persists inventory
- Grocery list & cart preview → SQLAlchemy persistence: persists lists
- Runtime safety settings → Swiggy MCP boundary: selects provider mode
- Runtime safety settings → Order lifecycle: enforces safety switches
- Docker deployment → API application: runs Python API
- Docker deployment → Authenticated product UI: runs frontend build