Skip to content

Prachi5791/VigilAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VigilAI: Smart Surveillance Event Detection & Analysis System

Author: Prachi Maruti Patil β€” Vidyalankar Institute of Technology

A production-ready, multi-service AI-powered video surveillance system featuring YOLOv8 object detection, rule-based event analysis, on-demand clip generation, and an Advanced Database Management System (ADBMS) analytics dashboard.


πŸ”— Live Deployments

Service URL Status
🌐 Frontend (React) https://vigil-ai-five.vercel.app Live
βš™οΈ Backend (Node.js) https://vigilai-ytg4.onrender.com Live
🐍 Python Engine (Flask + YOLOv8) https://vigilai-1-njnz.onrender.com Live

πŸ“‘ Table of Contents

  1. System Architecture
  2. ADBMS Concepts & Features
  3. Event Types & Detection Rules
  4. Quick Start β€” Docker
  5. Quick Start β€” Local Dev
  6. Project Structure
  7. API Reference
  8. Key Design Rules
  9. Troubleshooting

πŸ— System Architecture

Browser :3000 β†’ nginx (frontend) β†’ /api proxy β†’ backend :4000
                                                      β”‚
                                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                         β–Ό            β–Ό             β–Ό
                                     MongoDB      Python        shared
                                     :27017       :5000         volumes
                                                (Flask+YOLO)

Service Ports

Service Port Description
frontend 3000 React app served via nginx
backend 4000 Node.js / Express REST API
python-engine 5000 Flask + YOLOv8 + OpenCV
mongodb 27017 MongoDB 7.0 database

πŸ—„ ADBMS Concepts & Features

This system incorporates several Advanced Database Management System (ADBMS) concepts to ensure efficient querying, high availability, and optimal performance at scale.

1. Indexing & Query Optimization

  • Compound Indexes on event_type, video_id, and timestamp allow fast filtering across large event collections without full-table scans.
  • The /api/adbms/index-comparison endpoint lets you compare query execution plans with and without indexes in real time, demonstrating measurable speedup.
  • Filter parameters (min_duration, min_confidence, zone) are designed to leverage these indexes for sub-millisecond lookups.

2. Caching Layer

  • NodeCache is used as an in-memory caching layer in the Node.js backend.
  • Frequently accessed aggregation results (event counts, summaries, stats) are cached to avoid redundant MongoDB aggregation pipelines.
  • The /api/adbms/cache-stats and /api/adbms/cache-test endpoints expose live miss β†’ hit demonstrations, illustrating cache effectiveness.

3. Replication & Fault Tolerance

  • The system is designed with MongoDB replica set concepts in mind.
  • The /api/adbms/replication-test endpoint simulates primary failure and restore scenarios (fail_primary / restore), showcasing how the system maintains availability during node failure.
  • /api/adbms/server-selection demonstrates read/write routing β€” writes go to the primary, reads can be distributed to secondaries.

4. Bulk Write Operations (Upsert Pattern)

  • All events from the Python engine are committed via POST /api/events/bulk, which uses MongoDB's bulkWrite with upsert semantics.
  • Event deduplication is guaranteed by a deterministic event_id = MD5(video_id:type:track:frame) hash, preventing duplicate records even on reprocessing.

5. Query Logging & Observability

  • Every significant database query is logged to a QueryLog collection, recording execution time, query type, and result size.
  • /api/adbms/query-logs surfaces these logs with aggregate statistics, enabling database performance monitoring over time.

6. Sequential vs. Parallel Processing

  • The system supports both sequential and parallel video processing pipelines.
  • /api/adbms/processing-comparison compares throughput between the two strategies, demonstrating how concurrency impacts database write patterns and overall performance.

🚨 Event Types & Detection Rules

Event Trigger Condition Priority
zone_entry Person transitions into a defined zone polygon 3
zone_loitering Person remains inside a zone for > 8 seconds 8
loitering Person moves < 80 px over > 10 seconds 6
abandoned_object Bag/object moves < 30 px over > 15 seconds 10
vehicle_stop Vehicle speed < 2 px/frame for > 8 seconds 5
crowd_formation 3+ persons detected in a zone for > 1 second 9

🐳 Quick Start β€” Docker

Prerequisites

  • Docker >= 24
  • Docker Compose >= 2.20
  • 8 GB RAM recommended (for YOLOv8 large model)

Run the Full Stack

docker compose up --build

First build downloads YOLOv8 weights (~87 MB) β€” allow 3–5 minutes.

Open http://localhost:3000 once all services are healthy.

Stop & Teardown

# Stop all containers
docker compose down

# Full teardown including volumes (resets all data)
docker compose down -v

πŸ’» Quick Start β€” Local Dev

# 1. Start MongoDB
docker run -d -p 27017:27017 mongo:7.0

# 2. Start Python Engine (Flask + YOLOv8)
cd python-engine
pip install -r requirements.txt
python3 app.py                        # Runs on :5000

# 3. Start Backend (Node.js)
cd backend
npm install
npm run dev                           # Runs on :4000

# 4. Start Frontend (React)
cd frontend
npm install
npm start                             # Runs on :3000

πŸ“ Project Structure

surveillance-system/
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ backend/                          # Node.js / Express API
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ .env
β”‚   β”œβ”€β”€ server.js
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Event.js
β”‚   β”‚   β”œβ”€β”€ Video.js
β”‚   β”‚   └── QueryLog.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ videos.js
β”‚   β”‚   β”œβ”€β”€ events.js
β”‚   β”‚   β”œβ”€β”€ clips.js
β”‚   β”‚   └── adbms.js
β”‚   └── public/
β”‚       β”œβ”€β”€ uploads/
β”‚       └── clips/
β”‚
β”œβ”€β”€ python-engine/                    # Flask + YOLOv8 Processing
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ app.py                        # Flask HTTP service
β”‚   β”œβ”€β”€ pipeline.py                   # Processing orchestrator
β”‚   β”œβ”€β”€ rule_engine.py                # 6 event detection rules
β”‚   β”œβ”€β”€ tracker.py                    # TrackStore + DetectionFilter
β”‚   β”œβ”€β”€ detector.py                   # YOLOv8 + MockDetector
β”‚   β”œβ”€β”€ models.py                     # Shared dataclasses
β”‚   β”œβ”€β”€ backend_client.py
β”‚   └── generate_clip.py              # On-demand clip renderer
β”‚
└── frontend/                         # React UI
    β”œβ”€β”€ Dockerfile
    β”œβ”€β”€ nginx.conf
    β”œβ”€β”€ package.json
    └── src/
        β”œβ”€β”€ App.js
        β”œβ”€β”€ index.css
        β”œβ”€β”€ services/api.js
        └── pages/
            β”œβ”€β”€ UploadPage.js
            β”œβ”€β”€ EventsPage.js
            β”œβ”€β”€ ClipViewer.js
            └── AdbmsPage.js          # ADBMS analytics dashboard

πŸ“‘ API Reference

Videos

Method Endpoint Description
POST /api/videos/upload Upload single video (multipart: video, zones, processing_mode)
POST /api/videos/upload-multiple Upload multiple videos (multipart: videos[], zones, processing_mode)
POST /api/videos/:id/process Start sequential processing for a video
POST /api/videos/process-parallel Concurrent processing ({ video_ids: [] })
GET /api/videos List all videos
GET /api/videos/:id Get single video + event count
DELETE /api/videos/:id Delete video and all associated events

Events

Method Endpoint Description
POST /api/events/bulk Upsert event array (called from Python engine)
GET /api/events List events with filters: video_id, event_type, min_duration, min_confidence, zone
GET /api/events/:id Get single event
GET /api/events/stats/summary Aggregated event counts and summaries

Clips

Method Endpoint Description
GET /api/events/:id/clip Generate or return a cached video clip
DELETE /api/events/:id/clip Delete a generated clip

ADBMS Analytics

Method Endpoint Description
GET /api/adbms/index-comparison Index vs. no-index query benchmark (?event_type=loitering)
GET /api/adbms/query-logs All query logs + aggregate stats
GET /api/adbms/cache-stats NodeCache hit/miss counters
GET /api/adbms/cache-test Live cache miss β†’ hit demonstration
GET /api/adbms/server-selection Read/write routing demo (?type=read|write)
POST /api/adbms/replication-test Simulate replication events ({ action: "fail_primary" | "restore" })
GET /api/adbms/processing-comparison Sequential vs. parallel processing stats

Python Engine (Internal)

Method Endpoint Description
GET /health Liveness probe
GET /status/:video_id Job status for a video
POST /process Start processing ({ video_id, video_path, zones, backend_url })
POST /generate-clip Render a clip ({ event, video_path, clip_dir, clip_fname, buffer })

πŸ“ Key Design Rules

Rule Implementation
No duplicate events event_id = MD5(video_id:type:track:frame) + MongoDB upsert
No clips generated in Python generate_clip.py is only called when Node.js POSTs to /generate-clip
Bulk inserts only POST /api/events/bulk β†’ MongoDB bulkWrite upsert
Consistent clip naming <event_id>_<clip_uuid>.mp4
Shared file volumes shared_uploads (read-only for Python) + shared_clips (read-write for both)

πŸ›  Troubleshooting

# View logs for all services
docker compose logs -f

# Python engine is slow to start (downloading YOLOv8 weights)
docker compose logs python-engine

# Check MongoDB event count
docker compose exec mongodb mongosh surveillance \
  --eval "db.events.countDocuments()"

# List all generated clips
docker compose exec backend ls /app/public/clips

# Manual pipeline test (local, no backend required)
cd python-engine
python3 pipeline.py /path/to/video.mp4 \
  --video_id test-123 \
  --no_backend \
  --zones '[{"name":"A","polygon":[[0,0],[300,0],[300,300],[0,300]]}]'

πŸ§‘β€πŸ’» Author

Prachi Maruti Patil
Vidyalankar Institute of Technology


Built with YOLOv8 Β· Flask Β· Node.js Β· React Β· MongoDB Β· Docker

About

A production-ready, multi-service AI-powered video surveillance system featuring YOLOv8 object detection, rule-based event analysis, on-demand clip generation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors