Skip to content

cyber-pranav/crowdflow-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏟️ CrowdFlow AI β€” Intelligent Stadium Crowd Management

AI-powered real-time crowd intelligence platform for smart stadium management. Built with Next.js, Node.js, Socket.io, and Google Gemini.

CrowdFlow AI Node.js Next.js TypeScript Socket.io Tests


🎯 Problem Statement

Managing crowd flow in large stadiums during live events creates three critical challenges:

  1. Safety hazards β€” Uncontrolled crowd surges at exits, bottlenecks in concourses, and delayed emergency response
  2. Long wait times β€” Fans spend 20+ minutes in food queues while nearby stalls sit empty
  3. Reactive management β€” Staff responds to congestion after it happens, not before

CrowdFlow AI solves this with predictive intelligence that detects, forecasts, and redirects crowd flow in real time.

πŸ’‘ How It Solves the Problem

Every feature directly maps to a real-world crowd management outcome:

Feature Problem Solved How
Real-time Heatmap Staff can't see crowd distribution Aggregates 500+ user positions into zone-level density with trend tracking (rising/falling/stable)
Predictive Engine Congestion detected too late 3 algorithms (velocity vectors, event phase patterns, occupancy trends) forecast congestion 10+ minutes ahead
A Smart Routing* Fans walk through crowded zones Crowd-aware pathfinding with 3 weight modes (fastest, least crowded, balanced) that continuously reroutes
Queue Optimizer Fans join the nearest, not shortest queue Composite scoring (wait time Γ— 0.5 + walk time Γ— 0.3 + density Γ— 0.2) ranks all vendors dynamically
AI Assistant Fans have no centralised information Gemini-powered NLP with injected live stadium data answers "Where should I eat?" with real-time accuracy
Emergency Evacuation Slow evacuation response One-click A* routing to nearest exit for all zones using dedicated emergency paths

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  CrowdFlow AI Frontend                       β”‚
β”‚  Next.js 16 β€’ Tailwind CSS v4 β€’ TypeScript                   β”‚
β”‚  Real-time WebSocket β€’ Responsive β€’ WCAG Accessible          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                   WebSocket (Socket.io)                       β”‚
β”‚         density:update β€’ prediction:alert β€’ queue:update      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  CrowdFlow AI Backend                         β”‚
β”‚  Express.js β€’ TypeScript β€’ Helmet β€’ Rate Limiting             β”‚
β”‚                                                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚ CrowdDensityβ”‚  β”‚ Predictive  β”‚  β”‚   Smart     β”‚          β”‚
β”‚  β”‚   Engine    β”‚  β”‚   Engine    β”‚  β”‚   Router    β”‚          β”‚
β”‚  β”‚ (Heatmap)   β”‚  β”‚ (Forecast)  β”‚  β”‚  (A* Path)  β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚   Queue     β”‚  β”‚ AI Assistantβ”‚  β”‚  Firestore  β”‚          β”‚
β”‚  β”‚ Optimizer   β”‚  β”‚  (Gemini)   β”‚  β”‚   Sync      β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Google Cloud Services                            β”‚
β”‚  Gemini AI β€’ Firebase Firestore β€’ Firebase Admin              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧠 Where AI is Used

Google Gemini AI (Deep Integration)

  • Context-Aware Chat: Every Gemini API call includes injected live data β€” current zone densities, active prediction alerts, vendor queue lengths, and the user's location. This enables responses like "North Food Court has a 3-minute wait and is only 50m from you" rather than generic advice.
  • Conversation Memory: Maintains a 6-message sliding window for multi-turn dialogue.
  • Intelligent Fallback: When Gemini is unavailable, a rule-based engine covers food, exit, crowd, route, and timing queries using the same live data.

Predictive Intelligence (Custom ML-like Algorithms)

  1. Velocity Vector Analysis β€” Tracks user movement direction over 2-minute windows. If 30+ users are heading toward Zone A, predicts congestion 2-8 minutes ahead.
  2. Event Phase Patterns β€” Knows halftime β†’ food court surge (88% confidence), post-event β†’ exit surge (95% confidence).
  3. Occupancy Trend Extrapolation β€” Calculates rate-of-change per zone per minute. If rising at 20+ users/min, forecasts when HIGH threshold will be hit.

πŸ”Œ Where Google Services are Used

Service Integration Depth Usage
Gemini API Core feature Powers AI assistant with live context injection, conversation history, and intelligent fallback
Firebase Firestore Data persistence Batch-writes crowd snapshots, prediction alerts, and queue data every 5 ticks for analytics and state recovery
Firebase Admin Authentication-ready Initialised for user auth/personalization (service account integration)
Google Stitch Design tooling Used for UI/UX mockup generation and design system creation

πŸ”’ Security

  • Helmet.js β€” HTTP security headers
  • Input Validation β€” All route params validated against stadium graph (zone IDs), enums (vendor types), and safe ranges (userCount: 1-5000, tickInterval: 500-10000ms)
  • Rate Limiting β€” Read endpoints: 200 req/min, Write endpoints: 30 req/min
  • CORS β€” Restricted to deployed frontend origin in production
  • Message Sanitization β€” Chat messages trimmed and length-capped (500 chars)

β™Ώ Accessibility

  • Skip-to-content link for keyboard navigation
  • ARIA labels on all interactive elements (buttons, navigation, inputs)
  • aria-current="page" on active navigation tabs
  • aria-live regions for real-time update announcements
  • prefers-reduced-motion β€” Disables all animations for vestibular disorders
  • prefers-contrast: more β€” High-contrast color overrides
  • Focus-visible outlines β€” 2px primary-colored rings on keyboard focus
  • Minimum 44-48px touch targets on all interactive elements
  • Semantic HTML β€” <header>, <main>, <nav> with proper role attributes

πŸ§ͺ Testing

52 tests across 6 test suites β€” all passing

βœ“ CrowdDensityEngine β€” Heatmap Brain (5 tests)
βœ“ PredictiveEngine β€” Congestion Forecasting (5 tests)
βœ“ SmartRouter β€” A* Pathfinding (6 tests)
βœ“ QueueOptimizer β€” Dynamic Vendor Ranking (10 tests)
βœ“ SimulationService β€” Crowd Behavior Scenarios (9 tests)
βœ“ Input Validators β€” Security Layer (17 tests)

Run tests: cd crowdflow-backend && npm test

⚑ Efficiency

  • Binary Heap Priority Queue β€” A* pathfinding uses O(log n) enqueue/dequeue instead of O(n log n) array sort
  • Batched Firestore Writes β€” Buffers 5 snapshots before flushing to reduce write operations
  • Split Rate Limiting β€” Separate limits for read (200/min) and write (30/min) endpoints
  • Edge Weight Caching β€” Stadium graph pre-computes density-adjusted edge weights on occupancy change

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • npm 9+

Backend

cd crowdflow-backend
cp .env.example .env
# Add your GEMINI_API_KEY to .env
npm install
npm test        # Run 52 tests
npm run dev     # β†’ http://localhost:3001

Frontend

cd crowdflow-frontend
npm install
npm run dev     # β†’ http://localhost:3000

πŸ“± Screens

Screen Route Description
🏟️ Stadium / Live heatmap, fastest food, exit time, AI chat
🧠 Intelligence /dashboard Analytics, predictive timeline, simulation controls
🚢 Flow /queues Queue rankings, gates, washrooms, AI alerts
πŸ—ΊοΈ Navigation /map Full-screen routing with real-time path rendering
πŸ”” Alerts /alerts Critical, predictive, and opportunity notifications

🎨 Design System

  • Colors: Neon Cyan #8ff5ff β€’ Purple #ebb2ff β€’ Green #8eff71
  • Fonts: Space Grotesk (headlines) β€’ Inter (body) β€’ Material Symbols
  • Style: Glassmorphism, neon glows, dark mode, bento grid layouts

πŸ”§ Tech Stack

Frontend: Next.js 16, React 19, Tailwind CSS v4, TypeScript, Socket.io Client
Backend: Express.js, Socket.io, Google Gemini AI, Firebase Admin, TypeScript
Infrastructure: Vercel (frontend), Render (backend)
Design: Google Stitch for UI/UX mockups

πŸ“„ License

MIT License β€” Built for Virtual Hackathon 2026

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors