A full-stack web application simulating a food spoilage detection system using multi-gas sensors (NH3, H2S, TMA, DMS) with real-time LED indicators and breadboard-style circuit visualization.
This simulation demonstrates how gas sensors detect food spoilage by measuring volatile organic compounds. The system:
- Reads gas concentration levels (in ppm) from sensors
- Analyzes thresholds using Python-based logic
- Displays LED status indicators (Green/Yellow/Red)
- Provides visual circuit diagram simulation
- Allows dataset navigation with automatic analysis
3-Tier Stack:
- Frontend - React + TypeScript + Vite + Tailwind CSS
- Backend - Node.js + Express (API Gateway)
- Analysis Service - Python + Flask (Threshold Analysis Logic)
Data Flow:
Frontend (Sliders/Dataset)
↓ POST /api/simulate
Backend (Node.js Port 3001)
↓ POST /analyze
Python Service (Flask Port 5000)
↓ Returns LED Status
Frontend Updates UI & Circuit
- Node.js (v16+)
- Python (3.8+)
- npm (comes with Node.js)
# from the project root
npm installcd backend
npm install
cd ..cd python-service
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
cd ..From the root directory, run:
npm run allThis will start all three services concurrently in a single terminal with color-coded output.
Alternative - Separate Windows:
.\start-all.ps1This PowerShell script opens each service in its own terminal window.
You need 3 terminals running simultaneously:
cd python-service
.venv\Scripts\Activate.ps1
python app.pyExpected Output:
* Running on http://127.0.0.1:5000
* Debug mode: on
cd backend
npm startExpected Output:
Node.js backend running on port 3001
Python service URL: http://localhost:5000
# from the project root
npm run devExpected Output:
VITE ready in XXX ms
➜ Local: http://localhost:5173/
Navigate to http://localhost:5173 in your browser.
- SVG-based interactive circuit diagram
- Shows Arduino board, 4 gas sensors, 4 LEDs
- Animated signal wires when sensors are active
- Real-time LED color updates (Green/Yellow/Red)
- Breadboard aesthetic with hole patterns and power rails
- Previous/Next buttons to iterate through 20 CSV data rows
- Wrap-around navigation (last → first, first → last)
- Auto-updates sliders with dataset values
- Auto-simulation on every navigation
- Shows current position: "X / 20"
- Displays expected status: "✓ Fresh" or "
⚠️ Spoiled"
- 4 interactive sliders for NH3, H2S, TMA, DMS
- Real-time color feedback (green → yellow → red)
- Manual "Simulate Detection" button
- Range: 0 to max ppm for each gas
- 4 individual gas LEDs with live animations
- Main "Food Status" LED (Fresh/Spoiled)
- Threshold reference table
Located at: backend/dataset/gas_sensor_dataset.csv
Format:
NH3 (ppm),H2S (ppm),TMA (ppm),DMS (ppm),Food Spoiled
4.23,0.08,6.15,0.72,No
11.37,0.18,8.56,0.92,Yes
...
20 sample rows with various gas concentration levels.
| Gas | Threshold | Warning (70%) | Unit |
|---|---|---|---|
| NH3 (Ammonia) | 7.5 | 5.25 | ppm |
| H2S (Hydrogen Sulfide) | 0.2 | 0.14 | ppm |
| TMA (Trimethylamine) | 10.0 | 7.0 | ppm |
| DMS (Dimethyl Sulfide) | 1.0 | 0.7 | ppm |
LED Logic:
- Green: Below 70% of threshold
- Yellow: 70-99% of threshold
- Red: At or above threshold
- Food Status = Spoiled if ANY gas LED is Red
.
├── backend/
│ ├── dataset/
│ │ └── gas_sensor_dataset.csv # 20 sample gas readings
│ ├── server.js # Express API (ports 3001)
│ └── package.json
├── python-service/
│ ├── app.py # Flask analysis service
│ ├── requirements.txt # Flask==3.0.0, Flask-CORS==4.0.0
│ └── .venv/ # Virtual environment (created)
├── src/
│ ├── components/
│ │ ├── CircuitDiagram.tsx # ⭐ NEW: Breadboard SVG circuit
│ │ ├── GasSlider.tsx # Gas control slider
│ │ ├── LEDIndicator.tsx # LED status display
│ │ └── MicrocontrollerDiagram.tsx # (optional legacy)
│ ├── config/
│ │ └── sensors.ts # Sensor metadata & thresholds
│ ├── services/
│ │ └── api.ts # ⭐ UPDATED: Added fetchDataset()
│ ├── types/
│ │ └── index.ts # TypeScript interfaces
│ ├── App.tsx # ⭐ UPDATED: Dataset nav + auto-sim
│ └── main.tsx
├── package.json # Frontend dependencies
└── README.md # This file
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/simulate |
Forward gas readings to Python service |
| GET | /api/dataset |
⭐ NEW: Returns CSV dataset as JSON array |
| GET | /health |
Health check |
| Method | Endpoint | Description |
|---|---|---|
| POST | /analyze |
Analyze gas readings, return LED status |
| GET | /health |
Health check with thresholds |
curl http://localhost:3001/api/datasetcurl -X POST http://localhost:5000/analyze `
-H "Content-Type: application/json" `
-d '{"NH3":8.5,"H2S":0.15,"TMA":11.0,"DMS":0.9}'curl -X POST http://localhost:3001/api/simulate `
-H "Content-Type: application/json" `
-d '{"NH3":3.0,"H2S":0.05,"TMA":5.0,"DMS":0.4}'- Gas Sensor Controls - Left panel with 4 sliders
- Dataset Navigation - Previous/Next buttons with counter
- Circuit Diagram - Breadboard-style SVG visualization
- LED Status Panel - Right panel with 4 gas LEDs + Food Status
- Threshold Reference - Quick lookup table
# Find process using port 3001 or 5000
netstat -ano | findstr :3001
netstat -ano | findstr :5000
# Kill process by PID
taskkill /PID <PID> /F# Allow script execution (run as Administrator)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Then retry activation
.venv\Scripts\Activate.ps1- Ensure Python service is running on port 5000
- Check
PYTHON_SERVICE_URLenvironment variable - Verify Flask output shows "Running on http://127.0.0.1:5000"
- Ensure backend is running on port 3001
- Check browser console for CORS errors
- Verify
VITE_API_URL(defaults to http://localhost:3001)
- Add more dataset samples
- Export analysis results to CSV
- Real-time chart/graph of gas levels over time
- Configurable thresholds via UI
- Docker Compose for one-command startup
- Unit tests for Python analysis logic
- E2E tests with Playwright
- All Python commands must run inside the virtual environment (
.venv) - Dataset navigation uses wrap-around (circular navigation)
- Auto-simulation triggers on every dataset row change
- Circuit diagram shows animated wires when gas levels are high
- TypeScript type errors are compile-time only; app runs fine after
npm install
# Frontend
npm run dev # Start Vite dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
# Backend
npm start # Start Node.js server
npm run dev # Start with --watch (auto-restart)
# Python (in virtual environment)
python app.py # Start Flask serverThis project is for research and educational purposes.
Created for: Food Freshness Research Project
Last Updated: November 6, 2025