Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

CampusBrain AI

The Intelligence Layer for Smart Campuses

"An AI brain that understands, predicts, and optimizes an entire educational campus."

FastAPI Next.js React TailwindCSS SQLAlchemy OpenRouter PostgreSQL CPU Only System Audit


1. Problem Statement

Modern university campuses function like miniature smart cities housing thousands of students, faculty, and physical assets. However, their operations remain fragmented across disconnected legacy systems:

  • ⚑ Energy Waste: HVAC and lighting grids run at full power in empty lecture halls and auditoriums.
  • πŸ›‘ Safety Blindspots: Incident reports, perimeter bottlenecks, and overcrowding events are logged reactively without early-warning risk scoring.
  • 🚌 Transit Congestion: Campus shuttles suffer from unpredicted overcrowding surges without dynamic route balancing.
  • 🏫 Classroom Imbalances: Overbooked rooms coexist alongside vacant, climate-controlled auditoriums.

2. The Solution: CampusBrain AI

CampusBrain AI is a unified, AI-powered operating system for educational institutions. It unifies live telemetry across classrooms, energy, security, transit, attendance, complaints, and emergency alerts to deliver:

  • Interactive Campus Digital Twin (2D/3D): Visualizes building occupancy, climate, and active transit units with layer filters and timeline scrubbers.
  • CPU-Friendly Anomaly Detection: Statistical standard-deviation ($Z$-score) algorithms that detect HVAC waste and capacity surges without heavy neural networks.
  • Proactive AI Recommendation Engine: Automatically generates actionable operational interventions (HVAC setbacks, classroom rebalancing, patrol dispatches).
  • AI Campus Copilot: Natural language assistant powered by OpenRouter LLM integration with deterministic fallback.
  • Campus Health Index: Composite score ($30%\text{ Safety} + 25%\text{ Efficiency} + 20%\text{ Energy} + 15%\text{ Classrooms} + 10%\text{ Transport}$).

3. Hardware & 8GB RAM Optimization

Target Platform: 8GB RAM | CPU-Only (No GPU Required) | Windows / Linux / macOS
Memory Footprint: < 350 MB RAM (Backend + Frontend)
Zero Deep Learning Bloat: Scikit-learn + NumPy + Statistical Thresholding + OpenRouter Cloud LLM
  • No CUDA or GPU required: Runs smoothly on standard student laptops.
  • Zero cloud lock-in: The application operates with 100% functionality using the built-in deterministic intelligence engine even if offline.
  • Seamless DB fallback: Automatically boots with SQLite (campusbrain.db) or connects to PostgreSQL 16 on port 5432.

4. System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Next.js 15+ Enterprise Frontend                      β”‚
β”‚      Dark/Light Command Center β€’ Recharts β€’ Linear-Style Ctrl+K        β”‚
β”‚          Interactive Digital Twin β€’ Command Palette β€’ Mobile Drawer    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚ REST APIs / JWT (Port 8000)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FastAPI Python 3.12 Backend                         β”‚
β”‚                                                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ AI Health Score Engine β”‚  β”‚ Anomaly Engine  β”‚  β”‚ AI Copilot      β”‚ β”‚
β”‚  β”‚ (30/25/20/15/10 Wgt)   β”‚  β”‚ (Z-Score / IQR) β”‚  β”‚ (OpenRouter/Det)β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ IoT & Transit Simulation Engine (5s Ticks)  β”‚  β”‚ RBAC Security   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚ SQLAlchemy 2.0 ORM
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 PostgreSQL 16 / SQLite Database                        β”‚
β”‚   5 Buildings β€’ 30 Rooms β€’ 500 Students β€’ 10 Buses β€’ Safety & Alarms  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5. Core Modules & Routes

Route Module Purpose
/ Landing Page World-class startup presentation hero, feature cards, and demo launcher
/dashboard Executive Dashboard Live status strip, Campus Health Score (87/100), AI Insights, trend charts
/digital-twin Campus Digital Twin 2D architectural map, layer filters (Occupancy, Energy, Safety, Transit), time scrubber
/classrooms Smart Classrooms 30 smart rooms, occupancy bars, climate telemetry, IoT AC/lighting toggles
/energy Energy Intelligence Daily/weekly kWh charts, peak hours, Science Building 27% surge detection
/safety SafeCampus Center Perimeter risk zones (Gate 2: 82/100 risk), incident timeline, emergency broadcast
/transport Transport Fleet Real-time GPS bus tracker, overcrowding alerts (BUS-07 94%), reserve dispatch
/attendance Attendance Intelligence Cohort trends, department stats, academic risk registry (< 65% attendance)
/complaints Complaints Hub Rule-based automatic priority routing (Safety β†’ Critical, Transport β†’ High)
/alerts Alert Center Unified alarm aggregation, severity filters, 1-click acknowledge
/ai-assistant AI Campus Copilot Natural language conversational intelligence with structured action cards
/admin Admin Control Operations analytics, live simulation tick controls, instant data reset
/settings System Settings OpenRouter free LLM configuration and hardware profile inspection
/login Authentication 1-click role switcher (Admin, Faculty, Student, Security) & JWT login

6. Bangladesh-Inspired Demo Campus

The system comes pre-seeded with a realistic university campus dataset:

  1. Central Academic Building (CAB): 5 Floors, 8 Smart Lecture Halls, 65% Occupancy.
  2. Science & Engineering Building (SEB): 6 Floors, Labs & Amphitheater, 318 kWh Energy Surge (+27%).
  3. Central Library Building (LIB): 4 Floors, Quiet Study Zones & Digital Archives.
  4. Administration Building (ADM): 4 Floors, Council Chambers & Executive Wings.
  5. Student Activity Center (STC): 3 Floors, Multipurpose Auditorium & Lounges.

7. The 8-Step Hackathon Demo Scenario

Follow this exact walkthrough during judging:

  1. Step 1 β€” Executive Dashboard (/dashboard):
    • Inspect the Campus Health Score: 87/100 (Excellent) radial gauge.
    • View live metrics (1,842 Headcount, 42 Active Rooms, 1.28 MWh Energy).
  2. Step 2 β€” Digital Twin (/digital-twin):
    • View interactive campus layout and toggle layers (Occupancy, Energy, Safety, Transit).
    • Click on the glowing Science & Engineering Building.
    • Drawer slides in showing: Occupancy: 31%, Energy Draw: 318 kWh (HIGH).
  3. Step 3 β€” Anomaly Detection:
    • AI Insight flags: "Energy consumption is 27% higher than normal pattern while occupancy is at 31%".
  4. Step 4 β€” Energy Intelligence (/energy):
    • Open Energy Center. View anomaly callout: 318 kWh vs 250 kWh baseline.
  5. Step 5 β€” Actionable AI Recommendation:
    • Click [Apply Eco-HVAC Setback] to normalize consumption across empty rooms.
  6. Step 6 β€” SafeCampus Command (/safety):
    • Inspect Gate 2 Risk Score: 82/100 (High Risk) with 12 incidents this month.
    • Demonstrate the [Emergency Broadcast] dispatch modal.
  7. Step 7 β€” Transport Fleet (/transport):
    • Locate BUS-07 on Route A carrying 47 / 50 passengers (94% capacity).
    • View overcrowding prediction: "Overflow predicted in 8 minutes near Gate 2 Junction".
    • Click [Dispatch Reserve Bus BUS-09] to relieve route congestion.
  8. Step 8 β€” AI Campus Copilot (/ai-assistant):
    • Ask: "What are the biggest problems on campus right now?"
    • Copilot provides a 3-point synthesized briefing (Science Building energy, Gate 2 security, BUS-07 transit) with direct 1-click action buttons.

8. Installation & Quick Start

1. Backend Setup

# Navigate to project directory
cd "CAMPUSBRAIN AI"

# Create and activate Python virtual environment
py -m venv venv
.\venv\Scripts\activate  # On Linux/macOS: source venv/bin/activate

# Install dependencies
pip install -r backend/requirements.txt

# Run backend server (Runs on port 8000)
python backend/run.py

2. Frontend Setup

# In a second terminal:
cd frontend

# Install dependencies
npm install

# Start Next.js development server (Runs on port 3000)
npm run dev

Open http://localhost:3000 in your browser.


9. Environment Variables (.env)

# Database Connection (PostgreSQL or local SQLite fallback)
DATABASE_URL=sqlite:///./campusbrain.db

# JWT Security Key
SECRET_KEY=campusbrain-super-secret-production-key-2026-xyz987

# OpenRouter AI LLM Key & Free Model Routing
LLM_API_KEY=your_openrouter_api_key_here
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_MODEL=openrouter/free

# Frontend API URL
NEXT_PUBLIC_API_URL=http://127.0.0.1:8000/api
PORT=8000

10. Automated Verification Suite (16/16 Checks Passed)

Run the full end-to-end audit script:

.\venv\Scripts\python test_full_system_audit.py

Verification Output:

==================================================================
        CAMPUSBRAIN AI - COMPLETE END-TO-END SYSTEM AUDIT         
==================================================================
[1/16] [PASS] FastAPI Backend Server: HEALTHY (200 OK)
[2/16] [PASS] JWT Authentication: PASS (Logged in Admin with token)
[3/16] [PASS] Dashboard & Campus Health Score: PASS (85.0/100 - Excellent)
[4/16] [PASS] Digital Twin Telemetry: PASS (5 Campus Buildings Active)
[5/16] [PASS] Smart Classrooms & IoT: PASS (30 Rooms, IoT Switches Responsive)
[6/16] [PASS] Energy Intelligence: PASS (Detected 1 Anomaly: Science & Engineering Building)
[7/16] [PASS] SafeCampus Command: PASS (Gate 2 Risk Score: 82.0/100)
[8/16] [PASS] Transit Fleet Tracking: PASS (10 Buses, BUS-07 Load: 48/50)
[9/16] [PASS] Attendance Intelligence: PASS (Avg Attendance: 85.6%)
[10/16] [PASS] Complaints Management: PASS (5 Active Tickets)
[11/16] [PASS] Real-time Alerts: PASS (5 Telemetry Alarms Active)
[12/16] [PASS] AI Copilot (OpenRouter LLM): PASS (Generated by: OpenRouter (openrouter/free))
[13/16] [PASS] Simulation Engine: PASS (Live Telemetry Tick Verified)
[14/16] [PASS] Admin Control Center: PASS (Database Summary Verified)
[15/16] [PASS] Frontend Web Server (Port 3000): PASS (200 OK)
[16/16] [PASS] Frontend App Routes (12 Modules): PASS (All 12 Pages 200 OK)

==================================================================
 AUDIT RESULT: 16/16 CHECKS PASSED (100% OPERATIONAL) 
==================================================================

11. Demo Credentials

Role Email Password Access Scope
Admin [email protected] campusbrain123 Full operations & executive control
Faculty [email protected] campusbrain123 Classrooms & academic analytics
Student [email protected] campusbrain123 Transit schedules & issue reporting
Security [email protected] campusbrain123 SafeCampus command & patrol logs

(Or use the 1-Click Role Switcher inside the top-right header menu)


Built with ❀️ for the Smart Campus Hackathon.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages