How vr22124/world-cup-planner works
Purpose and deployment shape
StadiumIQ is a TypeScript monorepo for stadium-operations command workflows: simulated live conditions feed a React operations UI and Gemini-powered recommendations/chat. The frontend is a Vite SPA intended for Vercel; the Express API is a separate Render service, with client-side API calls proxied/routed by deployment configuration. Core deployment artifacts: vercel.json, render.yaml, pnpm-workspace.yaml.
Application entry points
The web runtime mounts React from apps/web/src/main.tsx and composes routes/pages in apps/web/src/App.tsx. The API process starts from apps/api/src/index.ts, builds the Express application in apps/api/src/app.ts, and mounts route groups through apps/api/src/routes/index.ts. Environment loading and runtime configuration are centralized at apps/api/src/config/env.ts.
Stadium simulation domain
The API’s primary operational-data source is a modular simulator rather than an external live-feed system. apps/api/src/services/simulator/core.ts coordinates crowd, match, incident, transport, and sustainability state; domain stages are separated in apps/api/src/services/simulator/crowd.ts, apps/api/src/services/simulator/incidents.ts, and apps/api/src/services/simulator/transport.ts. This creates the boundary where a future real telemetry provider could replace or augment simulated inputs.
HTTP operations API
Stadium state is exposed as resource-oriented endpoints under the stadium route group: apps/api/src/routes/stadium/index.ts, with specialized handlers such as apps/api/src/routes/stadium/heatmap.ts and apps/api/src/routes/stadium/incidents.ts. Health checks reside at apps/api/src/routes/health.ts. Route handlers are the boundary between HTTP contracts and simulator/service state.
AI orchestration and Gemini boundary
AI endpoints are mounted through apps/api/src/routes/ai/index.ts and apps/api/src/routes/gemini/index.ts. The orchestration layer builds live operational context, then produces assistant responses, announcements, or recommendations through apps/api/src/services/ai/contextBuilder.ts, apps/api/src/services/ai/assistant.ts, and apps/api/src/services/ai/recommendations.ts. Gemini SDK access is isolated in packages/integrations-gemini-ai/src/client.ts; Google Generative AI is therefore an external inference dependency rather than a frontend concern.
Web operator experience and data flows
Dashboard pages compose domain-focused display components, notably apps/web/src/pages/ops-dashboard.tsx, apps/web/src/components/dashboard/HeatmapSection.tsx, and apps/web/src/components/dashboard/ActiveIncidentsTable.tsx. Data-fetching hooks mediate browser/API interaction, including apps/web/src/hooks/use-stadium-data.ts and apps/web/src/hooks/use-transport-schedule.ts. The AI chat widget and streaming behavior are isolated in apps/web/src/components/chat/ai-chat-widget.tsx and apps/web/src/hooks/use-gemini-stream.ts.
Shared contracts and persistence
The OpenAPI document is the contract source at packages/api-spec/openapi.yaml; generated React client bindings live in packages/api-client-react/src/generated/api.ts, while generated Zod types/validators are under packages/api-zod/src/generated/api.ts. Conversation persistence is modeled separately through Drizzle-oriented schemas and queries: packages/db/src/schema/conversations.ts, packages/db/src/schema/messages.ts, and packages/db/src/queries/conversations.ts. The stated database runtime is Neon Postgres; persistence is principally relevant to Gemini conversation/message history.
Main entry points: contextBuilder.ts AI orchestration · App.tsx App routes · ops-dashboard.tsx Operations dashboard · index.ts Route registry
Components 22
Web SPA
- Vercel deployment · Hosts the Vite SPA and routes API calls.
vercel.json - React entry
apps/web/src/main.tsx - App routes
apps/web/src/App.tsx - Operations dashboard
apps/web/src/pages/ops-dashboard.tsx - Stadium data hooks
apps/web/src/hooks/use-stadium-data.ts - Heatmap and incidents views
apps/web/src/components/dashboard/HeatmapSection.tsx - AI chat and stream hook
apps/web/src/components/chat/ai-chat-widget.tsx
API service
- Render deployment · Runs the separate Express API service.
render.yaml - API process
apps/api/src/index.ts - Express app
apps/api/src/app.ts - Route registry
apps/api/src/routes/index.ts - Stadium endpoints
apps/api/src/routes/stadium/index.ts - Stadium simulator · Replaceable boundary for future real telemetry.
apps/api/src/services/simulator/core.ts - Crowd, incident, transport stages
apps/api/src/services/simulator/crowd.ts - AI and Gemini endpoints
apps/api/src/routes/ai/index.ts - AI orchestration
apps/api/src/services/ai/contextBuilder.ts
Shared packages
- OpenAPI contract
packages/api-spec/openapi.yaml - Generated React client
packages/api-client-react/src/generated/api.ts - Gemini client
packages/integrations-gemini-ai/src/client.ts - Conversation persistence · Stores Gemini conversation and message history in Neon Postgres.
packages/db/src/queries/conversations.ts
Other components
- Google Generative AI
- Neon Postgres
Connections 23
- Vercel deployment → React entry: hosts
- React entry → App routes: mounts
- App routes → Operations dashboard: renders
- Operations dashboard → Stadium data hooks: uses
- Operations dashboard → Heatmap and incidents views: composes
- App routes → AI chat and stream hook: includes
- Stadium data hooks → Generated React client: calls through
- AI chat and stream hook → AI and Gemini endpoints: streams requests to
- Generated React client → Stadium endpoints: uses contract endpoints
- OpenAPI contract → Generated React client: generates
- Render deployment → API process: runs
- API process → Express app: starts
- Express app → Route registry: mounts
- Route registry → Stadium endpoints: registers
- Route registry → AI and Gemini endpoints: registers
- Stadium endpoints → Stadium simulator: reads operational state
- Stadium simulator → Crowd, incident, transport stages: coordinates
- AI and Gemini endpoints → AI orchestration: invokes
- AI orchestration → Stadium simulator: builds live context from
- AI orchestration → Gemini client: requests inference through
- Gemini client → Google Generative AI: SDK access
- AI orchestration → Conversation persistence: stores history
- Conversation persistence → Neon Postgres: persists to