Description:
A full-stack web application that scans barcodes of household products and uses AI to provide region-specific disposal instructions. Built with React, Node.js, and OpenAI.
WasteSorter/
├─ frontend/ # React app with barcode scanner
├─ backend/ # Node.js Express backend
└─ ai-service/ # FastAPI AI service
- Node.js >= 18
- npm >= 9
- Python >= 3.10
- pip
- OpenAI API key
- Navigate to AI service folder:
cd WasteSorter/ai-service- Install Python dependencies:
pip install fastapi uvicorn openai pydantic python-dotenv- Create a
.envfile inai-service:
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Replace with your real OpenAI API key
- Start the AI service:
uvicorn main:app --reload --port 8000- The service runs at
http://127.0.0.1:8000
- Navigate to backend folder:
cd WasteSorter/backend- Install Node dependencies:
npm install express cors axios- Start backend server:
node index.js- The backend runs at
http://localhost:5001 - Logs all incoming requests
- Navigate to frontend folder:
cd WasteSorter/frontend- Install React dependencies:
npm install
npm install react-qr-barcode-scanner- Start frontend:
npm start- The app runs at
http://localhost:3000 - Scan barcodes or enter them manually
curl -X POST http://127.0.0.1:8000/analyze \
-H "Content-Type: application/json" \
-d '{"barcode":"0123456789012","city":"Toronto"}'- Should return JSON like:
{
"product_type": "Plastic water bottle",
"material": "PET plastic",
"category": "Recycling",
"explanation": "Plastic water bottle made of PET plastic should go in Recycling. Rinse and place in blue bin."
}curl -X POST http://localhost:5001/dispose \
-H "Content-Type: application/json" \
-d '{"barcode":"0123456789012","city":"Toronto"}'- Should return the same JSON from AI
- Backend logs should show:
Request reached backend!
Body: { barcode: "0123456789012", city: "Toronto" }
Calling AI service...
AI response: {...}
- Open browser at
http://localhost:3000 - Use the camera scanner to scan a barcode
- Check that disposal instructions appear
- Alternatively, enter a barcode manually and click Submit
- Kill any Node processes if backend port is busy:
lsof -i :5001 # List processes
kill -9 <PID> # Kill process- Restart AI service:
uvicorn main:app --reload --port 8000- Restart backend:
node index.js- Make sure the AI service (port 8000) runs before the backend
- Make sure the backend (port 5001) runs before the frontend