This repository contains the complete source code for CampusSentinel, an integrated system for intelligent campus security and monitoring with AI-powered predictions, occupancy forecasting, and real-time alerts.
For detailed setup and configuration, please refer to the README files inside each module.
- Multi-Source Activity Tracking: WiFi logs, CCTV frames, card swipes, lab bookings, library checkouts
- Face Recognition: pgvector-based cosine similarity search for instant identity matching
- Intelligent Alerts: AI-enhanced recommendations for missing persons, overcrowding, access violations, and after-hours access
- Location Prediction: Random Forest ML model predicts entity's next location based on behavioral patterns
- Occupancy Forecasting: Real-time predictions for all campus locations with capacity status
- Timeline Summarization: Natural language summaries of daily activities via Google Gemini
- Smart Recommendations: Context-aware, actionable suggestions for security alerts
- Real-time Dashboard: Comprehensive view of campus activities and occupancy
- Predictive Analytics: Forecast crowd patterns and potential security concerns
- Historical Analysis: Track patterns and trends across time periods
- Capacity Management: Monitor and optimize space utilization across 16+ locations
The project is divided into three main modules:
User interface for monitoring, visualization, and interaction.
- Real-time occupancy dashboard with live predictions
- Interactive entity timeline with AI summaries
- Face recognition search interface
- Alert management with AI recommendations
- Location prediction visualization
π Documentation: /Frontend/README.md
Core logic, API services, and database management using Django REST Framework (DRF).
- JWT Authentication with token refresh
- RESTful API for all operations
- PostgreSQL with pgvector extension (Supabase)
- ML models for location & occupancy prediction
- Google Gemini integration for AI features
- LangChain for structured LLM interactions
π Documentation: /Backend/README.md
Environment Variables:
.envfile required for backend configuration:
Required Environment Variables:
# Database
DB_NAME=your_database_name
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_HOST=your_db_host
DB_PORT=5432
# Google Gemini API
GEMINI_API_KEY=your_gemini_api_key_hereMachine learning and facial recognition pipelines for predictive analytics and cross-source entity resolution.
- Face embedding generation (InceptionResnetV1)
- Entity resolution across multiple data sources
- Behavioral pattern analysis
- Anomaly detection capabilities
π Documentation: /AI/README.md
- Python 3.10+
- Node.js 16+
- PostgreSQL with pgvector (Supabase)
- Google Gemini API key
-
Backend First (Core Services)
cd Backend/CampusSentinal pip install -r requirements.txt # Configure .env file python manage.py runserver
-
AI Module (Optional, for data processing)
cd AI pip install -r requirements.txt # Run face recognition & data pipelines
-
Frontend (User Interface)
cd Frontend npm install npm start
Servers:
- Backend API:
http://localhost:8000 - Frontend UI:
http://localhost:3000
βββββββββββββββββββ
β Frontend β React + Material-UI
β (Port 3000) β - Dashboard & Visualization
ββββββββββ¬βββββββββ - Real-time Monitoring
β
βΌ
βββββββββββββββββββ
β Backend API β Django REST Framework
β (Port 8000) β - JWT Authentication
ββββββββββ¬βββββββββ - ML Predictions
β - AI Integration
ββββββββββββββββββββββββ
βΌ βΌ
βββββββββββββββββββ ββββββββββββββββ
β PostgreSQL β β Gemini AI β
β + pgvector β β LangChain β
β (Supabase) β ββββββββββββββββ
βββββββββββββββββββ
Forecast occupancy for 16+ campus locations using Random Forest ML models:
- Locations: Library, Cafeteria, Gym, Labs, Auditorium, Hostel, and more
- Status: Normal, Overcrowded, Underused
- Single Location:
/api/forecast/- Detailed prediction with AI explanation - Batch Mode:
/api/forecast-all/- All locations at once for dashboard
AI-powered alerts with actionable recommendations:
- Missing Person: Detects extended absences (excludes sleeping hours)
- Overcrowding: Monitors capacity violations in real-time
- Access Violation: Flags unauthorized area access
- After Hours Access: Tracks late-night facility usage
Each alert includes context-aware recommendations via Google Gemini 2.0 Flash.
Predict entity's next location based on historical patterns:
- Analyzes temporal features (hour, day, weekend)
- Provides natural language explanations
- Displays past activity timeline
Convert raw event data into human-readable narratives:
- Daily activity summaries
- Time spent at each location
- Natural language descriptions
Instant identity matching using pgvector:
- 512-dimensional face embeddings
- Cosine similarity search
- Sub-second query response
POST /users/register/ # User registration
POST /users/token/ # Login (get JWT)
POST /users/token/refresh/ # Refresh access tokenGET /api/entities/ # Search entities
GET /api/alerts/ # Get intelligent alerts
POST /api/predict/ # Predict next location
POST /api/forecast/ # Forecast occupancy (single)
POST /api/forecast-all/ # Forecast all locations
GET /api/entities/{id}/timeline/ # Get timeline with AI summary
POST /api/search/face/ # Face recognition search- Framework: Django 5.2 + Django REST Framework
- Authentication: JWT (Simple JWT)
- Database: PostgreSQL + pgvector
- AI/ML: Google Gemini 2.5 Flash, scikit-learn, LangChain
- Data: pandas, numpy
- Framework: React
- UI: Material-UI
- State: React Context/Hooks
- Charts: Recharts/Chart.js
- Face Recognition: InceptionResnetV1
- Embeddings: 512D vectors
- Storage: pgvector
Occupancy tracking and prediction for:
| Location | Capacity | Location | Capacity |
|---|---|---|---|
| Library | 2150 | Cafeteria | 1360 |
| Auditorium | 1360 | Hostel | 5000 |
| Gym | 1012 | Faculty Office | 650 |
| Seminar Room | 1800 | Main Building | 30 |
| LAB_101 | 40 | LAB_102 | 15 |
| LAB_305 | 30 | LAB_A1 | 20 |
| LAB_A2 | 12 | LAB | 30 |
| WORKSHOP | 20 | Admin Lobby | 710 |
curl -X POST "http://localhost:8000/api/forecast/" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"location_id": "Library", "future_time": "2024-10-25T14:30:00Z"}'curl "http://localhost:8000/api/alerts/" \
-H "Authorization: Bearer <token>"curl -X POST "http://localhost:8000/api/search/face/" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"embedding": [0.123, -0.456, ...]}' # 512 floatsFor detailed setup, API documentation, and configuration:
- Frontend:
/Frontend/README.md - Backend:
/Backend/README.md - AI Module:
/AI/README.md
- Real-time monitoring of all entities
- Instant alerts for unusual activity
- Predictive threat detection
- Optimize room allocations
- Forecast peak usage times
- Improve resource utilization
- Track attendance patterns
- Identify students needing support
- Analyze facility usage
- Quick entity location tracking
- Missing person detection
- Evacuation planning
- JWT authentication with token refresh and blacklist
- Role-based access control (student, faculty, staff)
- Secure face embedding storage
- Encrypted database connections
- API rate limiting
- Real-time occupancy streaming via WebSockets
- Anomaly detection for unusual patterns
- Multi-location route optimization
- Predictive maintenance alerts
- Mobile app integration
- Integration with building management systems
ChaosCoded



