SmartFlow is a real-time, computer-vision-powered smart traffic signal system. It uses YOLO object detection on live video feeds to count and classify vehicles, dynamically computes adaptive green-light timings based on actual traffic load, and presents everything through a professional glassmorphic dashboard. The system is fully self-healing β edge scripts monitor themselves, restart on failure, and send SMS alerts if a camera or node goes offline.
Prototype β Feature Complete
| Component | Status |
|---|---|
| YOLO Inference Engine | β Working |
| FastAPI Backend + MongoDB | β Working |
| Adaptive Signal Timing Algorithm | β Working |
| React / Vite Dashboard | β Working |
| Heartbeat + Watchdog Edge Services | β Working |
| SMS Alerts via Twilio | β Working |
| Per-Lane ROI Detection | π Planned |
| Multi-Junction Coordination | π Planned |
- π€ Real-Time Edge AI β YOLOv8/YOLO11 detects and classifies vehicles (car, bus, truck, bike, pedestrian) from video or RTSP camera feeds every frame.
- π¦ Adaptive Signal Timing β An algorithm weighs vehicle types by size/impact and calculates optimal green-phase durations per approach, replacing fixed-interval timers.
- π Live Dashboard β A dark-themed, glassmorphic React web app with animated donut charts, area graphs, and bar charts β all polling live backend data every 5 seconds.
- π Edge Health Monitoring β A heartbeat script reports CPU, memory, FPS, and camera status to the backend every 10 seconds.
- π Watchdog Recovery β Automatically detects crashed inference or heartbeat processes and restarts them (up to 5 attempts before raising an alert).
- π² SMS Alerts β Twilio integration sends an SMS instantly if a junction goes offline or a critical failure is detected.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Edge Device (Camera) β
β ββββββββββββββββββ ββββββββββββββ βββββββββββββββ β
β β inference3.py β βheartbeat.pyβ β watchdog.py β β
β β (YOLO + OpenCV)β β(Health HB) β β(Auto-Restartβ β
β βββββββββ¬βββββββββ βββββββ¬βββββββ βββββββ¬ββββββββ β
βββββββββββββΌβββββββββββββββββββΌβββββββββββββββββΌββββββββββ
β POST /detections β POST /heartbeat β POST /alert
βΌ βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (src/backend/main.py) β
β β’ Stores detections, heartbeats, alerts in MongoDB β
β β’ Runs adaptive signal timing algorithm β
β β’ Serves REST API on http://localhost:8001 β
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β Polls every 5s
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React/Vite Dashboard (frontend/) β
β β’ http://localhost:5173 β
β β’ Shows live counts, timing, health, alerts, charts β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Make sure the following are installed on your machine:
| Tool | Version | Purpose |
|---|---|---|
| Git | any | Clone the repository |
| Python | 3.10+ | Backend & edge scripts |
| Node.js + npm | 18+ | Frontend dashboard |
| Docker + Docker Compose | any | Run MongoDB |
git clone https://github.com/your-username/SmartFlow.git
cd SmartFlowCopy the example env file and fill in your values:
cp .env.example .envEdit .env with your settings:
MONGO_URI=mongodb://admin:admin123@localhost:27017/
TWILIO_SID=your_twilio_sid
TWILIO_AUTH=your_twilio_auth_token
TWILIO_FROM=+1xxxxxxxxxx
TWILIO_TO=+91xxxxxxxxxx
β οΈ If you don't have Twilio credentials, the system still works fully β SMS alerts will just be silently skipped.
# Create and activate a virtual environment
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
# Install all dependencies
pip install -r requirements.txtcd frontend
npm install
cd ..Start each component in its own terminal. Always activate the virtual environment (venv\Scripts\activate) before running Python scripts.
docker compose -f infra/docker-compose.yml up -dpython -m uvicorn src.backend.main:app --port 8001 --reloadAPI docs are available at http://localhost:8001/docs
cd frontend
npm run devπ Open http://localhost:5173 in your browser.
python src/edge/inference3.pypython src/edge/heartbeat.pypython src/edge/watchdog.pySmartFlow/
βββ src/
β βββ backend/ # FastAPI server, API routes, timing algorithm
β β βββ main.py # Main application entry point
β β βββ sms_utils.py # Twilio SMS integration
β βββ edge/ # Hardware-side runtime scripts
β β βββ inference3.py # YOLO inference + frame processing
β β βββ heartbeat.py # System health reporter
β β βββ watchdog.py # Process monitor + auto-restart
β βββ dashboard/ # (Legacy) Original Streamlit dashboard
βββ frontend/ # React + Vite dashboard (NEW)
β βββ src/
β βββ App.jsx # Main app with routing & live data polling
β βββ api.js # Backend API client (fetch wrappers)
β βββ index.css # Glassmorphic dark theme styles
βββ infra/
β βββ docker-compose.yml # MongoDB container setup
βββ models/ # Place your trained .pt model weights here
βββ data/ # Sample video files for the inference engine
βββ ai/ # Training experiments and datasets
βββ .env.example # Environment variable template
βββ requirements.txt # Python dependencies
βββ Readme.md
If the model is already trained, you only need these to run the full system:
β
src/backend/
β
src/edge/
β
frontend/
β
infra/docker-compose.yml
β
models/best.pt β your trained YOLO model weights
β
data/sample2.mp4 β camera feed video
β
.env
β
requirements.txt
The ai/ and experiments/ directories are only needed for research, re-training, or extending the model.
| Layer | Technology |
|---|---|
| Object Detection | YOLO11 / YOLOv8 (Ultralytics) |
| Video Processing | OpenCV |
| Backend | FastAPI + Uvicorn |
| Database | MongoDB 6 (via Docker) |
| Dashboard | React 18 + Vite |
| Charts | Recharts |
| Icons | Lucide React |
| Alerting | Twilio SMS |
| Monitoring | psutil |
