# jirattong/xor-bomb-game architecture

> Architecture diagram of the GitHub repository jirattong/xor-bomb-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jirattong/xor-bomb-game
- Repository: https://github.com/jirattong/xor-bomb-game

## Overview

XOR Bomb Defusal Workshop is a browser-based, two-role game: an operator configures a secret and key, creates a room, and a defuser joins to solve the XOR cipher under a timer. The main client syncs room state through Firebase Realtime Database and presents gameplay and results. A separate room API route implements its own room actions using an in-memory fallback and a remote relay; the sampled client excerpt does not show it being used. The page is a large, partially excerpted module, so its internal stages are grouped by evidenced responsibilities.

Main entry points: [`app/page.tsx`](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx) (Game screens), [`lib/firebase.ts`](https://github.com/jirattong/xor-bomb-game/blob/main/lib/firebase.ts) (Firebase client), [`app/api/room/route.ts`](https://github.com/jirattong/xor-bomb-game/blob/main/app/api/room/route.ts) (Room endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Game client"]
  node_game_ui["Game screens<br/>[page.tsx]"]
  node_operator["Operator setup<br/>[page.tsx]"]
  node_room_create["Room creation<br/>[page.tsx]"]
  node_room_join["Room joining<br/>[page.tsx]"]
  node_cipher_setup["Cipher setup<br/>[page.tsx]"]
  node_defuser["Defuser controls<br/>[page.tsx]"]
  node_cipher_decode["Bit decoding<br/>[page.tsx]"]
  node_game_state["Game state<br/>[page.tsx]"]
  node_timer_result["Timer and results<br/>[page.tsx]"]
  node_sound["Sound effects<br/>[page.tsx]"]
end

subgraph group_sync["Room synchronization"]
  node_firebase_client["Firebase client<br/>[firebase.ts]"]
  node_firebase_db[("Realtime Database")]
end

subgraph group_api["Room API"]
  node_room_endpoint["Room endpoint<br/>[route.ts]"]
  node_room_cache[("Room cache<br/>[route.ts]")]
end

node_player(("Players"))
node_global_relay["Global relay"]

node_player -->|"uses"| node_game_ui
node_game_ui -->|"shows"| node_operator
node_game_ui -->|"shows"| node_defuser
node_operator -->|"configures"| node_cipher_setup
node_operator -->|"creates"| node_room_create
node_room_create -->|"writes room"| node_firebase_client
node_room_join -->|"updates room"| node_firebase_client
node_defuser -->|"joins room"| node_room_join
node_defuser -->|"edits bits"| node_cipher_decode
node_cipher_decode -->|"submits word"| node_game_state
node_game_state -->|"updates status"| node_firebase_client
node_firebase_client -->|"reads and writes"| node_firebase_db
node_firebase_db -->|"streams updates"| node_game_state
node_game_state -->|"drives results"| node_timer_result
node_game_ui -->|"plays effects"| node_sound
node_player -->|"requests room"| node_room_endpoint
node_room_endpoint -->|"falls back to"| node_room_cache
node_room_endpoint -->|"fetches and saves"| node_global_relay

click node_game_ui "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_operator "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_room_create "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_room_join "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_cipher_setup "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_defuser "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_cipher_decode "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_game_state "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_timer_result "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_sound "https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx"
click node_firebase_client "https://github.com/jirattong/xor-bomb-game/blob/main/lib/firebase.ts"
click node_room_endpoint "https://github.com/jirattong/xor-bomb-game/blob/main/app/api/room/route.ts"
click node_room_cache "https://github.com/jirattong/xor-bomb-game/blob/main/app/api/room/route.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_game_ui,node_operator,node_room_create,node_room_join,node_cipher_setup,node_defuser,node_cipher_decode,node_game_state,node_timer_result,node_sound toneBlue
class node_firebase_client,node_firebase_db toneAmber
class node_room_endpoint,node_room_cache toneMint
class node_player,node_global_relay toneIndigo
```

## Components

### Game client

- [Game screens](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Operator setup](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Room creation](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Room joining](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Cipher setup](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Defuser controls](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Bit decoding](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Game state](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Timer and results](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`
- [Sound effects](https://github.com/jirattong/xor-bomb-game/blob/main/app/page.tsx): `app/page.tsx`

### Room synchronization

- [Firebase client](https://github.com/jirattong/xor-bomb-game/blob/main/lib/firebase.ts): `lib/firebase.ts`
- **Realtime Database**

### Room API

- [Room endpoint](https://github.com/jirattong/xor-bomb-game/blob/main/app/api/room/route.ts): `app/api/room/route.ts`
- [Room cache](https://github.com/jirattong/xor-bomb-game/blob/main/app/api/room/route.ts): `app/api/room/route.ts`

### Other components

- **Players**
- **Global relay**

## Connections

- Players → Game screens: uses (evidence: `app/page.tsx`)
- Game screens → Operator setup: shows (evidence: `app/page.tsx`)
- Game screens → Defuser controls: shows (evidence: `app/page.tsx`)
- Operator setup → Cipher setup: configures (evidence: `app/page.tsx`)
- Operator setup → Room creation: creates (evidence: `app/page.tsx`)
- Room creation → Firebase client: writes room (evidence: `app/page.tsx`)
- Room joining → Firebase client: updates room (evidence: `app/page.tsx`)
- Defuser controls → Room joining: joins room (evidence: `app/page.tsx`)
- Defuser controls → Bit decoding: edits bits (evidence: `app/page.tsx`)
- Bit decoding → Game state: submits word (evidence: `app/page.tsx`)
- Game state → Firebase client: updates status (evidence: `app/page.tsx`)
- Firebase client → Realtime Database: reads and writes
- Realtime Database → Game state: streams updates (evidence: `app/page.tsx`)
- Game state → Timer and results: drives results (evidence: `app/page.tsx`)
- Game screens → Sound effects: plays effects (evidence: `app/page.tsx`)
- Players → Room endpoint: requests room (evidence: `app/api/room/route.ts`)
- Room endpoint → Room cache: falls back to (evidence: `app/api/room/route.ts`)
- Room endpoint → Global relay: fetches and saves (evidence: `app/api/room/route.ts`)
