Skip to content

code-silver01/challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CartIQ Assist β€” AI-Powered Grocery Decision Engine

Helping busy urban shoppers make better grocery decisions with minimum changes and maximum nutritional impact.

Architecture React GCP License


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    React Frontend                           β”‚
β”‚  (Vite + Tailwind v4 Β· Firebase Auth Β· Firebase Hosting)    β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚Onboardingβ”‚  β”‚Cart Inputβ”‚  β”‚Results β”‚  β”‚Impact Charts β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                       β”‚                                     β”‚
β”‚              Data Access Layer (DAL)                         β”‚
β”‚         (No raw Firestore SDK in components)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚ HTTP
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Orchestrator (Cloud Run :8080)                β”‚
β”‚         Fans out to agents, collects results              β”‚
β”‚                                                           β”‚
β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚    β”‚Cart Parseβ”‚  β”‚Behavior  β”‚  β”‚Context β”‚  β”‚Optimize  β”‚  β”‚
β”‚    β”‚  :8081   β”‚  β”‚  :8082   β”‚  β”‚ :8083  β”‚  β”‚  :8084   β”‚  β”‚
β”‚    β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚
β”‚          β”‚            β”‚            β”‚             β”‚         β”‚
β”‚   Open Food     Firestore     Time/Season   Constraint    β”‚
β”‚   Facts API     History       Signals       Solver        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό             β–Ό              β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚Firestore β”‚  β”‚Cloud     β”‚  β”‚Vertex AI  β”‚
    β”‚(profiles,β”‚  β”‚Vision APIβ”‚  β”‚(Gemini)   β”‚
    β”‚history,  β”‚  β”‚(OCR)     β”‚  β”‚(optional) β”‚
    β”‚feedback) β”‚  β”‚          β”‚  β”‚           β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Agent Roles

Agent Port Role
Cart Parser 8081 Classifies items, looks up nutrition via bundled DB + Open Food Facts API
Behavior Analysis 8082 Reads Firestore purchase history, detects snack dependency, protein deficit
Context Engine 8083 Injects day/time, season, lifestyle, cooking willingness signals
Optimization 8084 Constraint solver: produces 3-5 swaps prioritizing protein gap closure
Orchestrator 8080 Fans out to all agents via HTTP, aggregates results for frontend

πŸ“‚ Project Structure

challenge/
β”œβ”€β”€ frontend/                   # React + Vite + Tailwind v4
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ agents/             # Local agent implementations (browser fallback)
β”‚   β”‚   β”‚   β”œβ”€β”€ cartParser.js
β”‚   β”‚   β”‚   β”œβ”€β”€ behaviorAgent.js
β”‚   β”‚   β”‚   β”œβ”€β”€ contextEngine.js
β”‚   β”‚   β”‚   └── optimizationAgent.js
β”‚   β”‚   β”œβ”€β”€ components/         # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ CartInput.jsx   # Text + image upload input
β”‚   β”‚   β”‚   β”œβ”€β”€ CartSummary.jsx # Nutrition stats + item tags
β”‚   β”‚   β”‚   β”œβ”€β”€ InsightCard.jsx # Behavior + context insight
β”‚   β”‚   β”‚   β”œβ”€β”€ SuggestionCard.jsx # ADD/REPLACE/REMOVE cards
β”‚   β”‚   β”‚   β”œβ”€β”€ ImpactChart.jsx # Before vs After comparison
β”‚   β”‚   β”‚   └── Navbar.jsx
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Landing.jsx     # Auth + demo mode
β”‚   β”‚   β”‚   β”œβ”€β”€ Onboarding.jsx  # 3-screen onboarding
β”‚   β”‚   β”‚   └── Dashboard.jsx   # Main analysis view
β”‚   β”‚   β”œβ”€β”€ context/            # React context providers
β”‚   β”‚   β”œβ”€β”€ services/           # Firebase config, DAL, API client
β”‚   β”‚   └── data/               # Bundled grocery dataset (100+ items)
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── package.json
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ orchestrator/           # Fan-out orchestrator
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── Dockerfile
β”‚   β”œβ”€β”€ cart-parser/            # Cart Parser Agent
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ groceryDB.json
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── Dockerfile
β”‚   β”œβ”€β”€ behavior-agent/         # Behavior Analysis Agent
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── Dockerfile
β”‚   β”œβ”€β”€ context-engine/         # Context Engine Agent
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   └── Dockerfile
β”‚   └── optimization/           # Optimization Agent
β”‚       β”œβ”€β”€ index.js
β”‚       β”œβ”€β”€ package.json
β”‚       └── Dockerfile
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Quick Start (Local Development)

Prerequisites

  • Node.js 20+
  • npm 9+

1. Frontend

cd frontend
npm install
npm run dev
# β†’ http://localhost:5173

The frontend includes local agent implementations that run entirely in the browser, so it works without the backend services. Click "Try Demo" on the landing page to skip Firebase Auth.

2. Backend (optional, for full Cloud Run architecture)

# Install deps for each service
cd backend/orchestrator && npm install
cd ../cart-parser && npm install
cd ../behavior-agent && npm install
cd ../context-engine && npm install
cd ../optimization && npm install

# Run all services (use separate terminals)
cd backend/orchestrator && npm run dev    # :8080
cd backend/cart-parser && npm run dev     # :8081
cd backend/behavior-agent && npm run dev  # :8082
cd backend/context-engine && npm run dev  # :8083
cd backend/optimization && npm run dev    # :8084

☁️ GCP Deployment

Firebase Setup

  1. Create a Firebase project at console.firebase.google.com
  2. Enable Authentication β†’ Google Sign-In provider
  3. Enable Cloud Firestore (start in test mode)
  4. Create a .env file in frontend/:
VITE_FIREBASE_API_KEY=your-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_ID=000000000
VITE_FIREBASE_APP_ID=1:000:web:000

Cloud Build & Cloud Run Deployment

We've included a cloudbuild.yaml file that automatically builds and pushes all 5 microservice containers at once.

# 1. Set your project
export PROJECT_ID=your-gcp-project
gcloud config set project $PROJECT_ID

# 2. Submit the build to Cloud Build (builds all 5 images)
gcloud builds submit --config cloudbuild.yaml .

# 3. Deploy each service to Cloud Run
for service in orchestrator cart-parser behavior-agent context-engine optimization; do
  gcloud run deploy cartiq-$service \
    --image gcr.io/$PROJECT_ID/cartiq-$service \
    --platform managed \
    --region us-central1 \
    --allow-unauthenticated
done

Then update the orchestrator's environment variables with each service URL:

gcloud run services update cartiq-orchestrator \
  --set-env-vars "CART_PARSER_URL=https://cartiq-cart-parser-xxx.run.app,BEHAVIOR_URL=https://cartiq-behavior-agent-xxx.run.app,CONTEXT_URL=https://cartiq-context-engine-xxx.run.app,OPTIMIZATION_URL=https://cartiq-optimization-xxx.run.app"

Firebase Hosting

cd frontend
npm run build
firebase init hosting   # select your project, set public dir to "dist"
firebase deploy --only hosting

Cloud Vision API (OCR)

  1. Enable the Cloud Vision API in your GCP project
  2. The orchestrator service handles OCR via @google-cloud/vision
  3. Cloud Run services automatically authenticate via service account

🎯 Demo Scenario

Input: Maggi, chips, biscuits, white bread, butter, cola, eggs, banana

Output:

  • Cart is 62% processed food, protein deficit detected
  • 3-5 suggestions:
    1. πŸ”„ REPLACE butter β†’ peanut butter β€” Spread swap, +14g protein/week
    2. πŸ”„ REPLACE chips β†’ roasted nuts β€” Same crunch, +18g protein/week
    3. πŸ”„ REPLACE Maggi β†’ oats β€” Same 5-min prep, +9g protein/week
    4. ❌ REMOVE cola β€” Zero nutrition, save β‚Ή40/week
    5. πŸ”„ REPLACE biscuits β†’ dates β€” Natural sweetness, no refined sugar
  • Before: 12% protein, 62% junk
  • After: 31% protein, 10% junk
  • Effort: unchanged

πŸ”§ Google Services Used

Service Purpose
Firestore User profiles, purchase history, feedback, "never suggest" lists
Cloud Run Hosts all 5 agent APIs as serverless microservices
Cloud Vision API OCR for offline bill/receipt scanning
Vertex AI (Gemini) Optional: natural language reasoning for swap explanations
Firebase Hosting Deploys the React frontend
Firebase Auth Google Sign-In for user authentication

πŸ“Š Data Sources

  1. Bundled Dataset β€” 100+ common Indian grocery items with full macros (protein, carbs, fat, calories)
  2. Open Food Facts API β€” Fallback lookup for items not in the local dataset
  3. Mock Purchase History β€” Simulated data for first-time/demo users

πŸ›‘οΈ Code Quality

  • βœ… Each agent is a separate Cloud Run service with clean REST API
  • βœ… Agents communicate via HTTP (decoupled, independently deployable)
  • βœ… Frontend calls an orchestrator that fans out to agents
  • βœ… All Firestore operations go through a Data Access Layer (services/dataLayer.js)
  • βœ… No raw Firebase SDK calls in UI components
  • βœ… Dockerfiles included for every backend service
  • βœ… Local agent fallbacks for offline/demo operation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages