# maybe25/project-quiz-arena architecture

> Architecture diagram of the GitHub repository maybe25/project-quiz-arena, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maybe25/project-quiz-arena
- Repository: https://github.com/maybe25/project-quiz-arena

## Overview

This repository is a serverless multiplayer quiz backend. The visible implementation is Python-based AWS Lambda functions, even though the README says “web sockets in GO,” so the architecture diagram should follow the Terraform and Lambda layout rather than the README language.

The primary client-facing boundary is an API Gateway WebSocket API. Incoming socket lifecycle and messages are split across three edge Lambdas: `ws-connect`, `ws-disconnect`, and `ws-message`. These form the ingress layer for player sessions, connection tracking, and command handling.

The core game logic is decomposed into domain Lambdas rather than one monolith:
- `room-manager` handles room/session membership and room state.
- `quiz-engine` owns quiz progression and question selection.
- `round-ender` closes a round and likely triggers the next game phase.
- `broadcaster` sends game events back to connected clients.
- `stats-recorder` persists outcome/analytics data.

State is persisted in DynamoDB, with separate table definitions for `game`, `room`, and `stats`. The shared Dynamo layer under `shared/dynamo` suggests a clear model boundary between ephemeral websocket traffic and durable game state.

Outbound real-time messaging uses the API Gateway Management API through `shared/wsapi/post.py`. That means the broadcaster is not just publishing events internally; it is responsible for pushing updates back to specific websocket connections.

The repo also has asynchronous workflow infrastructure: SQS, Step Functions, and EventBridge are all provisioned in Terraform. That indicates the game flow is not purely request/response; round transitions and background actions are coordinated through event-driven handoffs and queue-based processing.

Question content is separated from code. The `questions/general.json` file and `s3_questions.tf` imply the question bank is packaged into S3 and consumed by the quiz engine from there, rather than being embedded in the Lambda code.

The `shared/events/types.py` module suggests an internal event contract shared across Lambdas. That is important for an architecture diagram because it marks the boundary between typed domain events and transport-specific websocket messages.

Infrastructure is managed entirely with Terraform under `infrastructure/terraform`. It provisions the API Gateway, Lambdas, DynamoDB, SQS, Step Functions, EventBridge, S3, and IAM. In other words, the operational architecture is “infrastructure as code” with AWS as the runtime platform.

CI/CD is also explicit: `.github/workflows/ci.yml` and `deploy.yml` indicate automated build/test and deployment pipelines. The `scripts/build.sh` / `build.bat` and `bootstrap.bat` files are packaging helpers for assembling Lambda artifacts locally or in CI.

For a diagram, the most important flow is: client connects over WebSocket -> connection is stored -> messages hit `ws-message` -> domain Lambdas mutate DynamoDB and/or enqueue events -> broadcaster pushes updates back over the websocket management API -> stats and round state are persisted asynchronously.

Main entry points: [`lambdas/ws-message/handler.py`](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-message/handler.py) (Message), [`infrastructure/terraform/apigateway.tf`](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/apigateway.tf) (WebSocket API), [`lambdas/quiz-engine/handler.py`](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/quiz-engine/handler.py) (Quiz engine), [`lambdas/round-ender/handler.py`](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/round-ender/handler.py) (Round ender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client boundary"]
  node_player(("Player client"))
  node_apigw["WebSocket API<br/>gateway<br/>[apigateway.tf]"]
end

subgraph group_ingress["Ingress lambdas"]
  node_ws_connect["Connect<br/>lambda<br/>[handler.py]"]
  node_ws_disconnect["Disconnect<br/>lambda<br/>[handler.py]"]
  node_ws_message["Message<br/>lambda<br/>[handler.py]"]
end

subgraph group_domain["Game domain"]
  node_room_manager["Room manager<br/>lambda<br/>[handler.py]"]
  node_quiz_engine["Quiz engine<br/>lambda<br/>[handler.py]"]
  node_round_ender["Round ender<br/>lambda<br/>[handler.py]"]
  node_broadcaster["Broadcaster<br/>lambda<br/>[handler.py]"]
  node_stats_recorder["Stats recorder<br/>lambda<br/>[handler.py]"]
end

subgraph group_storage["State and content"]
  node_game_table[("Game table<br/>dynamodb table<br/>[dynamodb.tf]")]
  node_room_table[("Room table<br/>dynamodb table<br/>[dynamodb.tf]")]
  node_stats_table[("Stats table<br/>dynamodb table<br/>[dynamodb.tf]")]
  node_questions_s3["Question bank<br/>s3 content<br/>[s3_questions.tf]"]
end

subgraph group_platform["AWS plumbing"]
  node_eventbridge{{"EventBridge<br/>event bus<br/>[eventbridge.tf]"}}
  node_sqs["SQS queues<br/>queueing<br/>[sqs.tf]"]
  node_stepfunctions{{"Step Functions<br/>orchestration<br/>[stepfunctions.tf]"}}
end

subgraph group_shared["Shared code"]
  node_wsapi_post["WS management<br/>ws api client<br/>[post.py]"]
  node_dynamo_shared["Dynamo helpers<br/>shared lib<br/>[game.py]"]
  node_event_types["Event types<br/>shared contract<br/>[types.py]"]
end

subgraph group_delivery["Delivery"]
  node_ci_cd["CI/CD<br/>pipeline<br/>[deploy.yml]"]
end

node_player -->|"connects"| node_apigw
node_apigw -->|"$connect"| node_ws_connect
node_apigw -->|"$disconnect"| node_ws_disconnect
node_apigw -->|"messages"| node_ws_message
node_ws_connect -->|"registers"| node_room_table
node_ws_disconnect -->|"cleans up"| node_room_table
node_ws_message -->|"emits"| node_event_types
node_ws_message -->|"routes"| node_room_manager
node_ws_message -->|"routes"| node_quiz_engine
node_ws_message -->|"routes"| node_round_ender
node_room_manager -->|"uses"| node_dynamo_shared
node_room_manager -->|"reads/writes"| node_room_table
node_room_manager -->|"reads/writes"| node_game_table
node_quiz_engine -->|"loads"| node_questions_s3
node_quiz_engine -->|"reads/writes"| node_game_table
node_quiz_engine -->|"publishes"| node_eventbridge
node_round_ender -->|"enqueues"| node_sqs
node_round_ender -->|"starts"| node_stepfunctions
node_round_ender -->|"updates"| node_game_table
node_broadcaster -->|"pushes"| node_wsapi_post
node_wsapi_post -->|"delivers"| node_apigw
node_broadcaster -->|"consumes"| node_event_types
node_stats_recorder -->|"persists"| node_stats_table
node_stats_recorder -->|"subscribes"| node_eventbridge
node_eventbridge -->|"fanout"| node_sqs
node_sqs -->|"triggers"| node_round_ender
node_stepfunctions -->|"orchestrates"| node_quiz_engine
node_ci_cd -->|"deploys"| node_apigw
node_ci_cd -->|"packages"| node_ws_message

click node_apigw "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/apigateway.tf"
click node_ws_connect "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-connect/handler.py"
click node_ws_disconnect "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-disconnect/handler.py"
click node_ws_message "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-message/handler.py"
click node_room_manager "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/room-manager/handler.py"
click node_quiz_engine "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/quiz-engine/handler.py"
click node_round_ender "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/round-ender/handler.py"
click node_broadcaster "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/broadcaster/handler.py"
click node_stats_recorder "https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/stats-recorder/handler.py"
click node_game_table "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf"
click node_room_table "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf"
click node_stats_table "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf"
click node_questions_s3 "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/s3_questions.tf"
click node_eventbridge "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/eventbridge.tf"
click node_sqs "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/sqs.tf"
click node_stepfunctions "https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/stepfunctions.tf"
click node_wsapi_post "https://github.com/maybe25/project-quiz-arena/blob/main/shared/wsapi/post.py"
click node_dynamo_shared "https://github.com/maybe25/project-quiz-arena/blob/main/shared/dynamo/game.py"
click node_event_types "https://github.com/maybe25/project-quiz-arena/blob/main/shared/events/types.py"
click node_ci_cd "https://github.com/maybe25/project-quiz-arena/blob/main/.github/workflows/deploy.yml"

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_player,node_apigw,node_ci_cd toneBlue
class node_ws_connect,node_ws_disconnect,node_ws_message toneAmber
class node_room_manager,node_quiz_engine,node_round_ender,node_broadcaster,node_stats_recorder toneMint
class node_game_table,node_room_table,node_stats_table,node_questions_s3 toneRose
class node_eventbridge,node_sqs,node_stepfunctions toneIndigo
class node_wsapi_post,node_dynamo_shared,node_event_types toneTeal
```

## Components

### Client boundary

WebSocket players and the API Gateway edge

- **Player client**: client · WebSocket-connected quiz participant
- [WebSocket API](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/apigateway.tf): gateway · API Gateway WebSocket front door · `infrastructure/terraform/apigateway.tf`

### Ingress lambdas

Connection lifecycle and message entrypoints

- [Connect](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-connect/handler.py): lambda · Handles new socket connections · `lambdas/ws-connect/handler.py`
- [Disconnect](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-disconnect/handler.py): lambda · Handles socket disconnects · `lambdas/ws-disconnect/handler.py`
- [Message](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/ws-message/handler.py): lambda · Routes incoming websocket commands · `lambdas/ws-message/handler.py`

### Game domain

Core quiz and room processing lambdas

- [Room manager](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/room-manager/handler.py): lambda · Room membership and session state · `lambdas/room-manager/handler.py`
- [Quiz engine](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/quiz-engine/handler.py): lambda · Question selection and round progression · `lambdas/quiz-engine/handler.py`
- [Round ender](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/round-ender/handler.py): lambda · Closes rounds and advances flow · `lambdas/round-ender/handler.py`
- [Broadcaster](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/broadcaster/handler.py): lambda · Pushes game events to sockets · `lambdas/broadcaster/handler.py`
- [Stats recorder](https://github.com/maybe25/project-quiz-arena/blob/main/lambdas/stats-recorder/handler.py): lambda · Persists outcomes and analytics · `lambdas/stats-recorder/handler.py`

### State and content

Durable data stores and question content

- [Game table](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf): dynamodb table · Primary game state store · `infrastructure/terraform/dynamodb.tf`
- [Room table](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf): dynamodb table · Room and connection state store · `infrastructure/terraform/dynamodb.tf`
- [Stats table](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/dynamodb.tf): dynamodb table · Persistent results and analytics store · `infrastructure/terraform/dynamodb.tf`
- [Question bank](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/s3_questions.tf): s3 content · Packaged quiz questions · `infrastructure/terraform/s3_questions.tf`

### AWS plumbing

Eventing, orchestration, and websocket push infrastructure

- [EventBridge](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/eventbridge.tf): event bus · Event routing for async game flow · `infrastructure/terraform/eventbridge.tf`
- [SQS queues](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/sqs.tf): queueing · Queued handoffs between stages · `infrastructure/terraform/sqs.tf`
- [Step Functions](https://github.com/maybe25/project-quiz-arena/blob/main/infrastructure/terraform/stepfunctions.tf): orchestration · Stateful workflow coordination · `infrastructure/terraform/stepfunctions.tf`

### Shared code

Reusable contracts and persistence helpers

- [WS management](https://github.com/maybe25/project-quiz-arena/blob/main/shared/wsapi/post.py): ws api client · API Gateway Management API sender · `shared/wsapi/post.py`
- [Dynamo helpers](https://github.com/maybe25/project-quiz-arena/blob/main/shared/dynamo/game.py): shared lib · Shared DynamoDB access model · `shared/dynamo/game.py`
- [Event types](https://github.com/maybe25/project-quiz-arena/blob/main/shared/events/types.py): shared contract · Typed internal event definitions · `shared/events/types.py`

### Delivery

Build and deployment automation

- [CI/CD](https://github.com/maybe25/project-quiz-arena/blob/main/.github/workflows/deploy.yml): pipeline · Build and deployment automation · `.github/workflows/deploy.yml`

## Connections

- Player client → WebSocket API: connects · Players open websocket sessions
- WebSocket API → Connect: $connect · Connection lifecycle routes
- WebSocket API → Disconnect: $disconnect · Connection lifecycle routes
- WebSocket API → Message: messages · Incoming websocket commands
- Connect → Room table: registers · Stores connection and room membership
- Disconnect → Room table: cleans up · Removes disconnected session state
- Message → Event types: emits · Normalizes commands into domain events
- Message → Room manager: routes · Session and room commands
- Message → Quiz engine: routes · Quiz progression commands
- Message → Round ender: routes · Round control commands
- Room manager → Dynamo helpers: uses · Shared persistence model
- Room manager → Room table: reads/writes · Maintains room state
- Room manager → Game table: reads/writes · Updates game session state
- Quiz engine → Question bank: loads · Fetches question content
- Quiz engine → Game table: reads/writes · Advances quiz state
- Quiz engine → EventBridge: publishes · Hands off phase changes
- Round ender → SQS queues: enqueues · Schedules async follow-up work
- Round ender → Step Functions: starts · Coordinates round transitions
- Round ender → Game table: updates · Closes round state
- Broadcaster → WS management: pushes · Sends updates to connected clients
- WS management → WebSocket API: delivers · Uses API Gateway Management API
- Broadcaster → Event types: consumes · Maps domain events to messages
- Stats recorder → Stats table: persists · Stores results and analytics
- Stats recorder → EventBridge: subscribes · Consumes async outcome events
- EventBridge → SQS queues: fanout · Routes events to queues
- SQS queues → Round ender: triggers · Deferred processing and phase changes
- Step Functions → Quiz engine: orchestrates · Drives multi-step quiz flow
- CI/CD → WebSocket API: deploys · Infrastructure and service deployment
- CI/CD → Message: packages · Builds Lambda artifacts
