# vr22124/world-cup-planner architecture

> Architecture diagram of the GitHub repository vr22124/world-cup-planner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vr22124/world-cup-planner
- Repository: https://github.com/vr22124/world-cup-planner

## Overview

#### 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: [`apps/api/src/services/ai/contextBuilder.ts`](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/ai/contextBuilder.ts) (AI orchestration), [`apps/web/src/App.tsx`](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/App.tsx) (App routes), [`apps/web/src/pages/ops-dashboard.tsx`](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/pages/ops-dashboard.tsx) (Operations dashboard), [`apps/api/src/routes/index.ts`](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/index.ts) (Route registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web SPA"]
  node_vercel{{"Vercel deployment<br/>hosting<br/>[vercel.json]"}}
  node_web_entry["React entry<br/>Vite runtime<br/>[main.tsx]"]
  node_web_app["App routes<br/>React composition<br/>[App.tsx]"]
  node_ops_dashboard["Operations dashboard<br/>React page<br/>[ops-dashboard.tsx]"]
  node_stadium_hooks["Stadium data hooks<br/>browser data access"]
  node_dashboard_views["Heatmap and incidents views<br/>dashboard components<br/>[HeatmapSection.tsx]"]
  node_chat["AI chat and stream hook<br/>React chat client<br/>[ai-chat-widget.tsx]"]
end

subgraph group_api["API service"]
  node_render{{"Render deployment<br/>hosting<br/>[render.yaml]"}}
  node_api_entry["API process<br/>Express bootstrap<br/>[index.ts]"]
  node_express_app["Express app<br/>HTTP application<br/>[app.ts]"]
  node_routes["Route registry<br/>route mounting<br/>[index.ts]"]
  node_stadium_routes["Stadium endpoints<br/>HTTP handlers<br/>[index.ts]"]
  node_simulator["Stadium simulator<br/>operational state coordinator<br/>[core.ts]"]
  node_simulator_domains["Crowd, incident, transport stages<br/>simulation domains<br/>[crowd.ts]"]
  node_ai_routes["AI and Gemini endpoints<br/>HTTP handlers<br/>[index.ts]"]
  node_ai_orchestration["AI orchestration<br/>context and recommendations<br/>[contextBuilder.ts]"]
end

subgraph group_shared["Shared packages"]
  node_openapi["OpenAPI contract<br/>API specification<br/>[openapi.yaml]"]
  node_react_client["Generated React client<br/>API bindings<br/>[api.ts]"]
  node_gemini_client["Gemini client<br/>SDK integration<br/>[client.ts]"]
  node_conversations[("Conversation persistence<br/>Drizzle queries and schema<br/>[conversations.ts]")]
end

node_gemini{{"Google Generative AI<br/>external inference"}}
node_neon[("Neon Postgres<br/>external database")]

node_vercel -->|"hosts"| node_web_entry
node_web_entry -->|"mounts"| node_web_app
node_web_app -->|"renders"| node_ops_dashboard
node_ops_dashboard -->|"uses"| node_stadium_hooks
node_ops_dashboard -->|"composes"| node_dashboard_views
node_web_app -->|"includes"| node_chat
node_stadium_hooks -->|"calls through"| node_react_client
node_chat -->|"streams requests to"| node_ai_routes
node_react_client -->|"uses contract endpoints"| node_stadium_routes
node_openapi -->|"generates"| node_react_client
node_render -->|"runs"| node_api_entry
node_api_entry -->|"starts"| node_express_app
node_express_app -->|"mounts"| node_routes
node_routes -->|"registers"| node_stadium_routes
node_routes -->|"registers"| node_ai_routes
node_stadium_routes -->|"reads operational state"| node_simulator
node_simulator -->|"coordinates"| node_simulator_domains
node_ai_routes -->|"invokes"| node_ai_orchestration
node_ai_orchestration -->|"builds live context from"| node_simulator
node_ai_orchestration -->|"requests inference through"| node_gemini_client
node_gemini_client -->|"SDK access"| node_gemini
node_ai_orchestration -->|"stores history"| node_conversations
node_conversations -->|"persists to"| node_neon

click node_vercel "https://github.com/vr22124/world-cup-planner/blob/main/vercel.json"
click node_web_entry "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/main.tsx"
click node_web_app "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/App.tsx"
click node_ops_dashboard "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/pages/ops-dashboard.tsx"
click node_stadium_hooks "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/hooks/use-stadium-data.ts"
click node_dashboard_views "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/components/dashboard/HeatmapSection.tsx"
click node_chat "https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/components/chat/ai-chat-widget.tsx"
click node_render "https://github.com/vr22124/world-cup-planner/blob/main/render.yaml"
click node_api_entry "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/index.ts"
click node_express_app "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/app.ts"
click node_routes "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/index.ts"
click node_stadium_routes "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/stadium/index.ts"
click node_simulator "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/simulator/core.ts"
click node_simulator_domains "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/simulator/crowd.ts"
click node_ai_routes "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/ai/index.ts"
click node_ai_orchestration "https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/ai/contextBuilder.ts"
click node_openapi "https://github.com/vr22124/world-cup-planner/blob/main/packages/api-spec/openapi.yaml"
click node_react_client "https://github.com/vr22124/world-cup-planner/blob/main/packages/api-client-react/src/generated/api.ts"
click node_gemini_client "https://github.com/vr22124/world-cup-planner/blob/main/packages/integrations-gemini-ai/src/client.ts"
click node_conversations "https://github.com/vr22124/world-cup-planner/blob/main/packages/db/src/queries/conversations.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vercel,node_web_entry,node_web_app,node_ops_dashboard,node_stadium_hooks,node_dashboard_views,node_chat toneBlue
class node_render,node_api_entry,node_express_app,node_routes,node_stadium_routes,node_simulator,node_simulator_domains,node_ai_routes,node_ai_orchestration toneAmber
class node_openapi,node_react_client,node_gemini_client,node_conversations toneMint
class node_gemini,node_neon toneNeutral
```

## Components

### Web SPA

- [Vercel deployment](https://github.com/vr22124/world-cup-planner/blob/main/vercel.json): hosting · Hosts the Vite SPA and routes API calls. · `vercel.json`
- [React entry](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/main.tsx): Vite runtime · `apps/web/src/main.tsx`
- [App routes](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/App.tsx): React composition · `apps/web/src/App.tsx`
- [Operations dashboard](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/pages/ops-dashboard.tsx): React page · `apps/web/src/pages/ops-dashboard.tsx`
- [Stadium data hooks](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/hooks/use-stadium-data.ts): browser data access · `apps/web/src/hooks/use-stadium-data.ts`
- [Heatmap and incidents views](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/components/dashboard/HeatmapSection.tsx): dashboard components · `apps/web/src/components/dashboard/HeatmapSection.tsx`
- [AI chat and stream hook](https://github.com/vr22124/world-cup-planner/blob/main/apps/web/src/components/chat/ai-chat-widget.tsx): React chat client · `apps/web/src/components/chat/ai-chat-widget.tsx`

### API service

- [Render deployment](https://github.com/vr22124/world-cup-planner/blob/main/render.yaml): hosting · Runs the separate Express API service. · `render.yaml`
- [API process](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/index.ts): Express bootstrap · `apps/api/src/index.ts`
- [Express app](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/app.ts): HTTP application · `apps/api/src/app.ts`
- [Route registry](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/index.ts): route mounting · `apps/api/src/routes/index.ts`
- [Stadium endpoints](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/stadium/index.ts): HTTP handlers · `apps/api/src/routes/stadium/index.ts`
- [Stadium simulator](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/simulator/core.ts): operational state coordinator · Replaceable boundary for future real telemetry. · `apps/api/src/services/simulator/core.ts`
- [Crowd, incident, transport stages](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/simulator/crowd.ts): simulation domains · `apps/api/src/services/simulator/crowd.ts`
- [AI and Gemini endpoints](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/routes/ai/index.ts): HTTP handlers · `apps/api/src/routes/ai/index.ts`
- [AI orchestration](https://github.com/vr22124/world-cup-planner/blob/main/apps/api/src/services/ai/contextBuilder.ts): context and recommendations · `apps/api/src/services/ai/contextBuilder.ts`

### Shared packages

- [OpenAPI contract](https://github.com/vr22124/world-cup-planner/blob/main/packages/api-spec/openapi.yaml): API specification · `packages/api-spec/openapi.yaml`
- [Generated React client](https://github.com/vr22124/world-cup-planner/blob/main/packages/api-client-react/src/generated/api.ts): API bindings · `packages/api-client-react/src/generated/api.ts`
- [Gemini client](https://github.com/vr22124/world-cup-planner/blob/main/packages/integrations-gemini-ai/src/client.ts): SDK integration · `packages/integrations-gemini-ai/src/client.ts`
- [Conversation persistence](https://github.com/vr22124/world-cup-planner/blob/main/packages/db/src/queries/conversations.ts): Drizzle queries and schema · Stores Gemini conversation and message history in Neon Postgres. · `packages/db/src/queries/conversations.ts`

### Other components

- **Google Generative AI**: external inference
- **Neon Postgres**: external database

## Connections

- 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
