RoadGuard AI
Real-time pothole detection, severity assessment, and automated maintenance reporting platform built with YOLOv11, ByteTrack, FastAPI WebSockets, and Next.js—engineered for sub-second live inference on scale-to-zero serverless CPU.
Problem Space
Municipal road inspections are manual and reactive, while standard sequential cv2.VideoCapture loops suffer 60s+ MJPEG/FFmpeg buffer lag when camera streams outpace CPU inference.
Production Architecture
Decouples camera ingestion from YOLO inference inside a 2-thread FastAPI WebSocket backend on Azure Container Apps, pairing persistent ByteTrack pothole IDs with Supabase persistence, Leaflet geotagging, and automated PDF maintenance reports.
Execution Pipeline
- STAGE 01
ZeroBufferFrameGrabber
Auto-switches HTTP IP webcams to persistent /shot.jpg keep-alive polling and drains stale RTSP/FFmpeg buffers (nobuffer, low_delay, BUFFERSIZE=1).
- STAGE 02
Decoupled Async YOLO Worker
Background worker grabs only the latest frame (640px max width) and runs YOLOv11 + ByteTrack (imgsz=416) behind an INFERENCE_SEMAPHORE.
- STAGE 03
Live ~15 FPS WSS Broadcast
Streams freshest JPEG frames (Q55) over WebSockets with resolution-independent normalized boxes and persistent track IDs to prevent double-counting.
- STAGE 04
Cost Estimation & PDF Dispatch
Classifies Critical/High/Medium severity, estimates repair cost, stores sharp context crops in Supabase, and emails compiled PDF reports via Gmail SMTP.
Key Engineering Trade-Offs & Decisions
- Eliminated 60s+ stream lag on serverless CPU by isolating frame capture from asynchronous model inference.
- Hardened production against SSRF (ALLOW_PRIVATE_CAM_IPS=false, ALLOW_LOCAL_CAM=false), supporting mobile IP webcams via Cloudflare Quick Tunnel or native browser camera.
- Enforced strict Content-Security-Policy whitelisting exact Azure ACA https/wss, Supabase, and OpenStreetMap origins in vercel.json.
- Deployed on Azure Container Apps (Central India, 2 vCPU / 4 GiB, min-replicas: 0) via GHCR for zero idle cost.
Tech Stack
Live at road-guard-ai-lake.vercel.app; FastAPI + YOLOv11 container (ghcr.io/tusharsingh-sde/roadguard-backend:v2) running scale-to-zero on Azure Container Apps.
Open-source repo: PRs, issues, and feature collabs are always welcome on GitHub.