File size: 21,446 Bytes
aefe381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# VenueFlow β€” Smart Sporting Venue Experience Platform

A Flask-based real-time system that transforms the physical event experience at large-scale sporting venues by addressing crowd movement, waiting times, and real-time coordination.

---

## Problem Statement

Attendees at large sporting events face:
- **Crowd congestion** at gates, concourses, and exits
- **Long queues** at food stalls, merchandise, and restrooms
- **Poor wayfinding** inside massive, unfamiliar venues
- **No real-time information** about crowd conditions or wait times
- **Accessibility barriers** for attendees with disabilities

VenueFlow solves these with an intelligent, real-time web platform for both **fans** (mobile-first attendee app) and **operators** (venue management dashboard).

---

## Architecture Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FRONTEND (Jinja2 + JS)                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Attendeeβ”‚  β”‚ Operator β”‚  β”‚ Heatmap  β”‚  β”‚ Chatbot  β”‚  β”‚
β”‚  β”‚   App   β”‚  β”‚Dashboard β”‚  β”‚  View    β”‚  β”‚  Widget  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                          β”‚ SSE / Fetch                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    FLASK BACKEND                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ Auth &   β”‚ β”‚ Real-time  β”‚ β”‚  AI Engine   β”‚           β”‚
β”‚  β”‚ Security β”‚ β”‚  Engine    β”‚ β”‚  (Gemini)    β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ Queue    β”‚ β”‚ Crowd      β”‚ β”‚ Notification β”‚           β”‚
β”‚  β”‚ Manager  β”‚ β”‚ Analytics  β”‚ β”‚   Service    β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                   GOOGLE SERVICES                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚ Firebase β”‚ β”‚Google Maps β”‚ β”‚   Gemini     β”‚           β”‚
β”‚  β”‚ Firestoreβ”‚ β”‚  JS API    β”‚ β”‚   2.5 API    β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚  β”‚ Cloud    β”‚ β”‚ Firebase   β”‚                             β”‚
β”‚  β”‚Translate β”‚ β”‚   Auth     β”‚                             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Tech Stack

| Layer | Technology |
|-------|-----------|
| **Backend** | Python 3.11+, Flask, Flask-SocketIO |
| **Frontend** | Jinja2 templates, Vanilla JS, CSS3 |
| **Database** | Firebase Firestore (real-time sync) |
| **Auth** | Firebase Authentication |
| **Maps** | Google Maps JavaScript API |
| **AI** | Google Gemini 2.5 Flash API |
| **Translation** | Google Cloud Translation API |
| **Real-time** | Server-Sent Events (SSE) + Firebase listeners |
| **Deployment** | Docker-ready for Cloud Run |

---

## User Review Required

> [!IMPORTANT]
> **Google API Keys Required**: You will need to provide API keys / service accounts for:
> - Firebase project (Firestore + Auth)
> - Google Maps JavaScript API key
> - Google Gemini API key
> - Google Cloud Translation API key
>
> These will be stored in a `.env` file (never committed to git).

> [!WARNING]
> **Simulated Sensor Data**: Since we don't have physical IoT sensors, the system will include a **simulation engine** that generates realistic crowd density, queue lengths, and movement patterns. This makes the demo fully functional without hardware.

> [!IMPORTANT]
> **Two User Interfaces**:
> 1. **Attendee App** (mobile-first) β€” For fans at the venue
> 2. **Operator Dashboard** β€” For venue staff/management
>
> Both are served from the same Flask app. Please confirm this dual-interface approach.

---

## Proposed Changes

### Project Structure

```
EventManager/
β”œβ”€β”€ app.py                      # Flask application factory
β”œβ”€β”€ config.py                   # Configuration & env management
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ Dockerfile                  # Container deployment
β”œβ”€β”€ .env.example                # Environment variable template
β”œβ”€β”€ .gitignore
β”‚
β”œβ”€β”€ blueprints/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ auth.py                 # Authentication routes
β”‚   β”œβ”€β”€ attendee.py             # Attendee-facing routes
β”‚   β”œβ”€β”€ operator.py             # Operator dashboard routes
β”‚   β”œβ”€β”€ api.py                  # REST API endpoints
β”‚   └── sse.py                  # Server-Sent Events stream
β”‚
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ firebase_service.py     # Firebase Firestore & Auth
β”‚   β”œβ”€β”€ crowd_service.py        # Crowd density analytics
β”‚   β”œβ”€β”€ queue_service.py        # Queue management logic
β”‚   β”œβ”€β”€ gemini_service.py       # AI chatbot & recommendations
β”‚   β”œβ”€β”€ maps_service.py         # Maps & wayfinding
β”‚   β”œβ”€β”€ translation_service.py  # Multi-language support
β”‚   β”œβ”€β”€ notification_service.py # Alert & notification engine
β”‚   └── simulator.py            # Realistic data simulation
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ venue.py                # Venue, Zone, Gate models
β”‚   β”œβ”€β”€ queue.py                # Queue & wait time models
β”‚   └── event.py                # Event & attendee models
β”‚
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”œβ”€β”€ base.css            # Design system & tokens
β”‚   β”‚   β”œβ”€β”€ attendee.css        # Attendee app styles
β”‚   β”‚   β”œβ”€β”€ operator.css        # Operator dashboard styles
β”‚   β”‚   └── accessibility.css   # A11y overrides
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ app.js              # Core JS utilities
β”‚   β”‚   β”œβ”€β”€ heatmap.js          # Crowd heatmap rendering
β”‚   β”‚   β”œβ”€β”€ queue.js            # Queue display & updates
β”‚   β”‚   β”œβ”€β”€ wayfinding.js       # Navigation & routing
β”‚   β”‚   β”œβ”€β”€ chatbot.js          # Gemini chatbot widget
β”‚   β”‚   β”œβ”€β”€ notifications.js   # Real-time notification handler
β”‚   β”‚   β”œβ”€β”€ sse-client.js       # SSE connection manager
β”‚   β”‚   β”œβ”€β”€ dashboard.js        # Operator dashboard logic
β”‚   β”‚   β”œβ”€β”€ simulator-ui.js     # Simulation controls
β”‚   β”‚   └── accessibility.js   # A11y toggle & preferences
β”‚   └── images/
β”‚       └── (generated assets)
β”‚
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html               # Base template with a11y
β”‚   β”œβ”€β”€ attendee/
β”‚   β”‚   β”œβ”€β”€ home.html           # Fan landing page
β”‚   β”‚   β”œβ”€β”€ heatmap.html        # Live crowd heatmap
β”‚   β”‚   β”œβ”€β”€ queues.html         # Queue status & booking
β”‚   β”‚   β”œβ”€β”€ navigate.html       # Wayfinding page
β”‚   β”‚   └── profile.html        # Preferences & a11y settings
β”‚   β”œβ”€β”€ operator/
β”‚   β”‚   β”œβ”€β”€ dashboard.html      # Main control dashboard
β”‚   β”‚   β”œβ”€β”€ analytics.html      # Historical analytics
β”‚   β”‚   β”œβ”€β”€ alerts.html         # Alert management
β”‚   β”‚   └── simulator.html      # Simulation controls
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ login.html
β”‚   β”‚   └── register.html
β”‚   └── components/
β”‚       β”œβ”€β”€ chatbot.html        # Chatbot widget partial
β”‚       β”œβ”€β”€ notification.html   # Notification toast partial
β”‚       └── nav.html            # Navigation component
β”‚
└── tests/
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ conftest.py             # Pytest fixtures
    β”œβ”€β”€ test_auth.py            # Authentication tests
    β”œβ”€β”€ test_crowd_service.py   # Crowd analytics tests
    β”œβ”€β”€ test_queue_service.py   # Queue management tests
    β”œβ”€β”€ test_api.py             # API endpoint tests
    β”œβ”€β”€ test_simulator.py       # Simulator logic tests
    └── test_accessibility.py   # Accessibility audit tests
```

---

### Component 1: Core Application & Configuration

#### [NEW] `app.py`
- Flask application factory pattern with blueprint registration
- CORS, CSP, and security headers middleware
- Error handlers (404, 500) with accessible error pages
- SSE stream endpoint registration

#### [NEW] `config.py`
- Environment-based configuration (dev/staging/prod)
- Secure loading of all API keys from `.env`
- Firebase, Gemini, Maps, Translation config constants

#### [NEW] `requirements.txt`
Key dependencies:
```
flask>=3.1
flask-socketio>=5.3
firebase-admin>=6.5
google-generativeai>=0.8
google-cloud-translate>=3.16
gunicorn>=22.0
python-dotenv>=1.0
pytest>=8.0
```

---

### Component 2: Authentication (Firebase Auth)

#### [NEW] `blueprints/auth.py`
- Login / Register routes using Firebase Authentication
- Role-based access: `attendee` vs `operator`
- Session management with secure HTTP-only cookies
- CSRF protection on all forms

#### [NEW] `services/firebase_service.py`
- Firebase Admin SDK initialization (singleton)
- Firestore CRUD helpers with connection pooling
- Real-time listener setup for zone/queue collections
- Token verification for authenticated API calls

---

### Component 3: Real-Time Crowd Heatmap

#### [NEW] `services/crowd_service.py`
- Processes zone density data from Firestore
- Calculates crowd density levels: 🟒 Low / 🟑 Moderate / πŸ”΄ High / ⚫ Critical
- Threshold-based alerting triggers
- Historical trend computation

#### [NEW] `static/js/heatmap.js`
- Renders interactive venue map overlay using **Google Maps JavaScript API**
- Real-time heatmap layer with color-coded zones
- Click-to-inspect zone details (capacity, current count, trend)
- Auto-refresh via SSE stream

#### [NEW] `templates/attendee/heatmap.html`
- Mobile-first responsive layout
- Legend with WCAG-compliant color indicators + text labels
- "Best route" suggestion panel
- Accessible alternative: tabular zone status view

---

### Component 4: Queue Management System

#### [NEW] `services/queue_service.py`
- Manages virtual queues for food, merchandise, restrooms
- Estimated wait time calculation (moving average algorithm)
- "Book your spot" β€” virtual queue reservation
- Queue position tracking and SMS/notification alerts

#### [NEW] `static/js/queue.js`
- Live queue dashboard with animated progress bars
- Sort/filter by wait time, category, proximity
- "Join Queue" button with confirmation modal
- Real-time position counter

#### [NEW] `templates/attendee/queues.html`
- Card-based queue listings with status indicators
- Category filters (πŸ• Food, πŸ› Merch, 🚻 Restrooms)
- Estimated wait time with confidence indicator
- Virtual queue ticket with QR code

---

### Component 5: Wayfinding & Navigation

#### [NEW] `services/maps_service.py`
- Google Maps integration for venue layout
- Shortest-path routing between venue zones
- Accessibility-aware routing (elevators, ramps)
- Points-of-interest data management

#### [NEW] `static/js/wayfinding.js`
- Interactive venue map with Google Maps JS API
- Turn-by-turn directions within the venue
- "Navigate to nearest [restroom/food/exit]" functionality
- Crowd-aware routing (avoids congested paths)

#### [NEW] `templates/attendee/navigate.html`
- Full-screen map with controls
- Quick-action buttons: "Nearest Exit", "My Seat", "Food Court"
- Step-by-step accessible text directions
- Estimated walking time display

---

### Component 6: AI Chatbot (Google Gemini)

#### [NEW] `services/gemini_service.py`
- Gemini 2.5 Flash integration for conversational AI
- Context-aware: knows venue layout, current crowd data, queue times
- Multi-language support via Cloud Translation API
- Safety filters and responsible AI guardrails
- Prompts:
  - "Where's the shortest food queue?"
  - "How do I get to Gate 7?"
  - "Is Section B crowded right now?"

#### [NEW] `static/js/chatbot.js`
- Floating chat widget (bottom-right)
- Message bubbles with typing indicator
- Quick-reply suggestion chips
- Language selector for real-time translation
- ARIA live region for screen reader announcements

#### [NEW] `templates/components/chatbot.html`
- Accessible chat interface with proper ARIA roles
- Resizable/minimizable widget
- Keyboard-navigable message list

---

### Component 7: Operator Dashboard

#### [NEW] `blueprints/operator.py`
- Protected routes (operator role required)
- Dashboard, analytics, alerts, and simulator views
- API endpoints for crowd threshold management

#### [NEW] `static/js/dashboard.js`
- Real-time KPI cards (total attendance, avg wait, alerts)
- Zone-by-zone capacity meters
- Alert timeline with severity levels
- Staff deployment recommendations

#### [NEW] `templates/operator/dashboard.html`
- Grid layout with responsive breakpoints
- Live charts (crowd trends, queue throughput)
- Draggable alert cards
- Emergency broadcast panel

---

### Component 8: Notification & Alert System

#### [NEW] `services/notification_service.py`
- Multi-channel: in-app toasts, SSE push, email
- Priority levels: Info / Warning / Critical / Emergency
- Geo-targeted: alerts to specific venue zones
- Automatic triggers from crowd density thresholds

#### [NEW] `blueprints/sse.py`
- Server-Sent Events endpoint for real-time push
- Per-user event filtering (zone, role)
- Heartbeat keep-alive for connection stability
- Graceful reconnection handling

#### [NEW] `static/js/notifications.js`
- Toast notification stack (top-right)
- Sound alerts for critical notifications
- Notification center with history
- "Do Not Disturb" mode for operators

---

### Component 9: Simulation Engine

#### [NEW] `services/simulator.py`
- Generates realistic crowd movement patterns
- Simulates event lifecycle: pre-event β†’ kickoff β†’ halftime β†’ post-event
- Queue fluctuation with realistic distributions
- Configurable parameters: venue capacity, event type, weather
- Writes simulated data to Firestore in real-time

#### [NEW] `templates/operator/simulator.html`
- Simulation control panel (start/stop/speed)
- Event phase selector
- Parameter sliders (crowd size, arrival rate)
- Live preview of simulated data

---

### Component 10: Accessibility & Internationalization

#### [NEW] `static/css/accessibility.css`
- High-contrast mode styles
- Large text mode (150% scaling)
- Reduced motion preference support
- Focus indicator styles (3px solid, 3:1 contrast)

#### [NEW] `static/js/accessibility.js`
- Accessibility preferences panel
- Toggle: high contrast, large text, reduced motion
- Persisted via localStorage
- Screen reader announcement utility

#### [NEW] `services/translation_service.py`
- Google Cloud Translation API integration
- Auto-detect user language from browser
- On-demand translation of UI strings and notifications
- Cached translations for performance

---

## Google Services Integration Summary

| Google Service | Usage | Why |
|---|---|---|
| **Firebase Firestore** | Real-time database for crowd, queue, and event data | Sub-second sync, offline support, scales automatically |
| **Firebase Auth** | User authentication (email/social login) | Secure, supports role-based access, easy integration |
| **Google Maps JS API** | Venue map, heatmap overlay, wayfinding routes | Industry standard mapping, custom overlays, directions |
| **Gemini 2.5 Flash** | AI chatbot for attendee assistance | Context-aware responses, fast inference, multi-turn |
| **Cloud Translation** | Multi-language support | Real-time translation for international events |

---

## Security Implementation

1. **Authentication**: Firebase Auth with JWT token verification
2. **Authorization**: Role-based access control (attendee/operator/admin)
3. **CSRF**: Flask-WTF CSRF tokens on all forms
4. **CSP**: Content Security Policy headers
5. **Input Validation**: Server-side validation on all endpoints
6. **Rate Limiting**: API rate limiting to prevent abuse
7. **Secrets Management**: All keys in `.env`, never in source
8. **HTTPS**: Enforced in production via Dockerfile/Cloud Run
9. **XSS Protection**: Jinja2 auto-escaping enabled
10. **SQL Injection**: N/A (NoSQL Firestore) β€” Firestore Security Rules used

---

## Accessibility Compliance (WCAG 2.2 AA)

- **Contrast**: All text β‰₯ 4.5:1 ratio, UI components β‰₯ 3:1
- **Target Size**: All interactive elements β‰₯ 44Γ—44 CSS pixels
- **Keyboard Navigation**: Full keyboard support with visible focus indicators
- **Screen Readers**: ARIA landmarks, live regions, proper heading hierarchy
- **Reduced Motion**: `prefers-reduced-motion` media query support
- **High Contrast Mode**: Toggle-able high contrast theme
- **Skip Links**: "Skip to content" link on every page
- **Semantic HTML**: Proper use of `<nav>`, `<main>`, `<aside>`, `<section>`
- **Alt Text**: All images have descriptive alt text
- **Language**: `lang` attribute on `<html>`, translated content marked

---

## Testing Strategy

### Unit Tests (pytest)
```
tests/
β”œβ”€β”€ test_crowd_service.py    # Density calculation, threshold logic
β”œβ”€β”€ test_queue_service.py    # Wait time estimation, virtual queue
β”œβ”€β”€ test_auth.py             # Login, registration, role checks
β”œβ”€β”€ test_api.py              # API endpoint responses
└── test_simulator.py        # Simulation output validation
```

### Integration Tests
- Firebase Firestore read/write operations
- Gemini API response processing
- SSE event delivery end-to-end

### Accessibility Tests
- Automated: axe-core audit via browser subagent
- Manual: keyboard navigation flow verification
- Contrast ratio verification on all pages

### Browser Testing
- Mobile viewport (375px) responsive validation
- Desktop viewport (1440px) dashboard verification
- Cross-browser visual spot checks

---

## Verification Plan

### Automated Tests
1. `pytest tests/ -v` β€” Run full test suite
2. `flask run` β€” Verify app starts without errors
3. Browser subagent: Navigate all pages, verify rendering
4. Accessibility audit via axe-core integration

### Manual Verification
1. Start simulation β†’ observe real-time heatmap updates
2. Join virtual queue β†’ verify position tracking
3. Ask chatbot questions β†’ verify Gemini responses
4. Toggle accessibility modes β†’ verify contrast/text changes
5. Switch languages β†’ verify translation

---

## Execution Phases

### Phase 1: Foundation (Core + Auth + Database)
- `app.py`, `config.py`, `requirements.txt`
- Firebase service, Auth blueprints
- Base templates with design system
- Docker setup

### Phase 2: Real-Time Core (Heatmap + Queues + SSE)
- Crowd service + heatmap visualization
- Queue management system
- SSE real-time push infrastructure
- Simulation engine

### Phase 3: Intelligence (AI + Navigation + Notifications)
- Gemini chatbot integration
- Google Maps wayfinding
- Notification/alert system
- Cloud Translation integration

### Phase 4: Operations (Dashboard + Analytics)
- Operator dashboard with live KPIs
- Historical analytics views
- Alert management interface
- Simulation control panel

### Phase 5: Polish (A11y + Testing + Security)
- Accessibility features & compliance
- Comprehensive test suite
- Security hardening
- Performance optimization
- Final UI polish

---

## Open Questions

> [!IMPORTANT]
> 1. **Do you have Google Cloud / Firebase API keys ready?** If not, I can set up the project with mock services that can be swapped for real ones later.

> [!IMPORTANT]
> 2. **Venue type preference?** Should the demo simulate a specific type of venue (cricket stadium, football stadium, Olympic arena)? This affects the venue map layout.

> [!NOTE]
> 3. **Should we include a mobile app wrapper** or keep this strictly as a responsive web app? (I recommend responsive web β€” works on all devices without installation.)