AI-powered real-time crowd intelligence platform for smart stadium management. Built with Next.js, Node.js, Socket.io, and Google Gemini.
Managing crowd flow in large stadiums during live events creates three critical challenges:
- Safety hazards β Uncontrolled crowd surges at exits, bottlenecks in concourses, and delayed emergency response
- Long wait times β Fans spend 20+ minutes in food queues while nearby stalls sit empty
- 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.
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 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- 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.
- 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.
- Event Phase Patterns β Knows halftime β food court surge (88% confidence), post-event β exit surge (95% confidence).
- Occupancy Trend Extrapolation β Calculates rate-of-change per zone per minute. If rising at 20+ users/min, forecasts when HIGH threshold will be hit.
| 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 |
- 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)
- Skip-to-content link for keyboard navigation
- ARIA labels on all interactive elements (buttons, navigation, inputs)
aria-current="page"on active navigation tabsaria-liveregions for real-time update announcementsprefers-reduced-motionβ Disables all animations for vestibular disordersprefers-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 properroleattributes
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
- 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
- Node.js 20+
- npm 9+
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:3001cd crowdflow-frontend
npm install
npm run dev # β http://localhost:3000| 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 |
- 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
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
MIT License β Built for Virtual Hackathon 2026