# peotrannnn/bloc architecture

> Architecture diagram of the GitHub repository peotrannnn/bloc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/peotrannnn/bloc
- Repository: https://github.com/peotrannnn/bloc

## Overview

Bloc is a Vietnamese-language, browser-based 3D Quoridor variant. A player selects a move or wall through the game interface; the app validates and applies turns, schedules AI when appropriate, and refreshes the board and review display. The repository also contains an online server path for room creation, matchmaking, and authoritative multiplayer turns. The graph preserves the documented AI, rendering, evaluation, and server capabilities; some connections are omitted where the sampled excerpts do not establish them.

Main entry points: [`js/app.js`](https://github.com/peotrannnn/bloc/blob/main/js/app.js) (Game coordinator), [`server/src/index.js`](https://github.com/peotrannnn/bloc/blob/main/server/src/index.js) (HTTP and WebSocket entry), [`server/src/room.js`](https://github.com/peotrannnn/bloc/blob/main/server/src/room.js) (Room Durable Object), [`server/src/lobby.js`](https://github.com/peotrannnn/bloc/blob/main/server/src/lobby.js) (Matchmaking lobby)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_play["Browser game"]
  node_app["Game coordinator<br/>[app.js]"]
  node_input["Input handling<br/>[input.js]"]
  node_ui["Game interface<br/>[ui.js]"]
  node_stage["3D board stage<br/>[stage.js]"]
  node_pawns["Pawn rendering<br/>[pawns.js]"]
  node_walls["Wall rendering<br/>[walls.js]"]
  node_camera["Camera controls<br/>[camera.js]"]
  node_badges["Board badges<br/>[badges.js]"]
  node_fireworks["Win effects<br/>[fireworks.js]"]
  node_menu["Game menu<br/>[menu.js]"]
end

subgraph group_agents["AI opponents"]
  node_ai["AI strategy collection"]
  node_aiworker["AI worker<br/>[worker.js]"]
  node_workerbundle["Worker AI source<br/>[worker-src.js]"]
end

subgraph group_rules["Game logic"]
  node_core["Shared rules engine<br/>[core.js]"]
  node_rules["Client rules adapter<br/>[rules.js]"]
  node_state["Game state<br/>[state.js]"]
end

subgraph group_online["Online play"]
  node_onlineclient["Online client<br/>[online-client.js]"]
  node_entry["HTTP and WebSocket entry<br/>[index.js]"]
  node_codes["Room codes<br/>[codes.js]"]
  node_limiter["Request limiter<br/>[limiter.js]"]
  node_lobby[("Matchmaking lobby<br/>[lobby.js]")]
  node_lobbylogic["Lobby matching logic<br/>[lobby-logic.js]"]
  node_room[("Room Durable Object<br/>[room.js]")]
  node_roomlogic["Room game authority<br/>[room-logic.js]"]
end

subgraph group_analysis["Review and evaluation"]
  node_eval["Position evaluation<br/>[eval.js]"]
  node_review["Move review<br/>[review.js]"]
end

node_player(("Player"))
node_browser(("Browser client"))
node_worker(("Cloudflare Worker"))

node_player -->|"provides actions"| node_input
node_input -->|"dispatches input"| node_app
node_app -->|"selects strategy"| node_ai
node_app -->|"requests decisions"| node_aiworker
node_app -->|"renders interface"| node_ui
node_app -->|"updates board"| node_stage
node_app -->|"updates walls"| node_walls
node_app -->|"updates pawns"| node_pawns
node_app -->|"controls view"| node_camera
node_app -->|"updates badges"| node_badges
node_app -->|"plays win effects"| node_fireworks
node_app -->|"updates review"| node_review
node_menu -.->|"starts game"| node_app
node_rules -->|"adapts rules"| node_core
node_app -.->|"uses client rules"| node_rules
node_app -.->|"updates state"| node_state
node_aiworker -.->|"runs worker source"| node_workerbundle
node_review -.->|"evaluates positions"| node_eval
node_browser -.->|"uses online play"| node_onlineclient
node_worker -->|"routes requests"| node_entry
node_entry -->|"validates codes"| node_codes
node_entry -->|"limits requests"| node_limiter
node_entry -->|"forwards WebSockets"| node_room
node_entry -->|"requests matchmaking"| node_lobby
node_lobby -->|"uses matching functions"| node_lobbylogic
node_lobby -->|"creates rooms"| node_room
node_room -->|"delegates room logic"| node_roomlogic
node_roomlogic -->|"checks game rules"| node_core
node_room -->|"updates lobby"| node_lobby
node_onlineclient -.->|"sends player actions"| node_room

click node_app "https://github.com/peotrannnn/bloc/blob/main/js/app.js"
click node_input "https://github.com/peotrannnn/bloc/blob/main/js/input.js"
click node_ui "https://github.com/peotrannnn/bloc/blob/main/js/ui.js"
click node_stage "https://github.com/peotrannnn/bloc/blob/main/js/view/stage.js"
click node_pawns "https://github.com/peotrannnn/bloc/blob/main/js/view/pawns.js"
click node_walls "https://github.com/peotrannnn/bloc/blob/main/js/view/walls.js"
click node_camera "https://github.com/peotrannnn/bloc/blob/main/js/view/camera.js"
click node_badges "https://github.com/peotrannnn/bloc/blob/main/js/view/badges.js"
click node_fireworks "https://github.com/peotrannnn/bloc/blob/main/js/view/fireworks.js"
click node_menu "https://github.com/peotrannnn/bloc/blob/main/js/menu.js"
click node_core "https://github.com/peotrannnn/bloc/blob/main/js/core.js"
click node_rules "https://github.com/peotrannnn/bloc/blob/main/js/rules.js"
click node_state "https://github.com/peotrannnn/bloc/blob/main/js/state.js"
click node_ai "https://github.com/peotrannnn/bloc/tree/main/js/ai"
click node_aiworker "https://github.com/peotrannnn/bloc/blob/main/js/ai/worker.js"
click node_workerbundle "https://github.com/peotrannnn/bloc/blob/main/js/ai/worker-src.js"
click node_eval "https://github.com/peotrannnn/bloc/blob/main/js/eval.js"
click node_review "https://github.com/peotrannnn/bloc/blob/main/js/review.js"
click node_onlineclient "https://github.com/peotrannnn/bloc/blob/main/js/online-client.js"
click node_entry "https://github.com/peotrannnn/bloc/blob/main/server/src/index.js"
click node_codes "https://github.com/peotrannnn/bloc/blob/main/server/src/codes.js"
click node_limiter "https://github.com/peotrannnn/bloc/blob/main/server/src/limiter.js"
click node_lobby "https://github.com/peotrannnn/bloc/blob/main/server/src/lobby.js"
click node_lobbylogic "https://github.com/peotrannnn/bloc/blob/main/server/src/lobby-logic.js"
click node_room "https://github.com/peotrannnn/bloc/blob/main/server/src/room.js"
click node_roomlogic "https://github.com/peotrannnn/bloc/blob/main/server/src/room-logic.js"

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_app,node_input,node_ui,node_stage,node_pawns,node_walls,node_camera,node_badges,node_fireworks,node_menu,node_browser toneBlue
class node_ai,node_aiworker,node_workerbundle toneAmber
class node_core,node_rules,node_state toneMint
class node_onlineclient,node_entry,node_codes,node_limiter,node_lobby,node_lobbylogic,node_room,node_roomlogic,node_worker toneRose
class node_eval,node_review,node_player toneIndigo
```

## Components

### Browser game

- [Game coordinator](https://github.com/peotrannnn/bloc/blob/main/js/app.js): `js/app.js`
- [Input handling](https://github.com/peotrannnn/bloc/blob/main/js/input.js): `js/input.js`
- [Game interface](https://github.com/peotrannnn/bloc/blob/main/js/ui.js): `js/ui.js`
- [3D board stage](https://github.com/peotrannnn/bloc/blob/main/js/view/stage.js): `js/view/stage.js`
- [Pawn rendering](https://github.com/peotrannnn/bloc/blob/main/js/view/pawns.js): `js/view/pawns.js`
- [Wall rendering](https://github.com/peotrannnn/bloc/blob/main/js/view/walls.js): `js/view/walls.js`
- [Camera controls](https://github.com/peotrannnn/bloc/blob/main/js/view/camera.js): `js/view/camera.js`
- [Board badges](https://github.com/peotrannnn/bloc/blob/main/js/view/badges.js): `js/view/badges.js`
- [Win effects](https://github.com/peotrannnn/bloc/blob/main/js/view/fireworks.js): `js/view/fireworks.js`
- [Game menu](https://github.com/peotrannnn/bloc/blob/main/js/menu.js): `js/menu.js`

### AI opponents

- [AI strategy collection](https://github.com/peotrannnn/bloc/tree/main/js/ai): `js/ai`
- [AI worker](https://github.com/peotrannnn/bloc/blob/main/js/ai/worker.js): `js/ai/worker.js`
- [Worker AI source](https://github.com/peotrannnn/bloc/blob/main/js/ai/worker-src.js): `js/ai/worker-src.js`

### Game logic

- [Shared rules engine](https://github.com/peotrannnn/bloc/blob/main/js/core.js): `js/core.js`
- [Client rules adapter](https://github.com/peotrannnn/bloc/blob/main/js/rules.js): `js/rules.js`
- [Game state](https://github.com/peotrannnn/bloc/blob/main/js/state.js): `js/state.js`

### Online play

- [Online client](https://github.com/peotrannnn/bloc/blob/main/js/online-client.js): `js/online-client.js`
- [HTTP and WebSocket entry](https://github.com/peotrannnn/bloc/blob/main/server/src/index.js): `server/src/index.js`
- [Room codes](https://github.com/peotrannnn/bloc/blob/main/server/src/codes.js): `server/src/codes.js`
- [Request limiter](https://github.com/peotrannnn/bloc/blob/main/server/src/limiter.js): `server/src/limiter.js`
- [Matchmaking lobby](https://github.com/peotrannnn/bloc/blob/main/server/src/lobby.js): `server/src/lobby.js`
- [Lobby matching logic](https://github.com/peotrannnn/bloc/blob/main/server/src/lobby-logic.js): `server/src/lobby-logic.js`
- [Room Durable Object](https://github.com/peotrannnn/bloc/blob/main/server/src/room.js): `server/src/room.js`
- [Room game authority](https://github.com/peotrannnn/bloc/blob/main/server/src/room-logic.js): `server/src/room-logic.js`

### Review and evaluation

- [Position evaluation](https://github.com/peotrannnn/bloc/blob/main/js/eval.js): `js/eval.js`
- [Move review](https://github.com/peotrannnn/bloc/blob/main/js/review.js): `js/review.js`

### Other components

- **Player**
- **Browser client**
- **Cloudflare Worker**

## Connections

- Player → Input handling: provides actions
- Input handling → Game coordinator: dispatches input (evidence: `js/app.js`)
- Game coordinator → AI strategy collection: selects strategy (evidence: `js/app.js`)
- Game coordinator → AI worker: requests decisions (evidence: `js/app.js`)
- Game coordinator → Game interface: renders interface (evidence: `js/app.js`)
- Game coordinator → 3D board stage: updates board (evidence: `js/app.js`)
- Game coordinator → Wall rendering: updates walls (evidence: `js/app.js`)
- Game coordinator → Pawn rendering: updates pawns (evidence: `js/app.js`)
- Game coordinator → Camera controls: controls view (evidence: `js/app.js`)
- Game coordinator → Board badges: updates badges (evidence: `js/app.js`)
- Game coordinator → Win effects: plays win effects (evidence: `js/app.js`)
- Game coordinator → Move review: updates review (evidence: `js/app.js`)
- Game menu → Game coordinator: starts game
- Client rules adapter → Shared rules engine: adapts rules (evidence: `README.md`)
- Game coordinator → Client rules adapter: uses client rules
- Game coordinator → Game state: updates state
- AI worker → Worker AI source: runs worker source
- Move review → Position evaluation: evaluates positions
- Browser client → Online client: uses online play
- Cloudflare Worker → HTTP and WebSocket entry: routes requests (evidence: `server/src/index.js`)
- HTTP and WebSocket entry → Room codes: validates codes (evidence: `server/src/index.js`)
- HTTP and WebSocket entry → Request limiter: limits requests (evidence: `server/src/index.js`)
- HTTP and WebSocket entry → Room Durable Object: forwards WebSockets (evidence: `server/src/index.js`)
- HTTP and WebSocket entry → Matchmaking lobby: requests matchmaking (evidence: `server/src/index.js`)
- Matchmaking lobby → Lobby matching logic: uses matching functions (evidence: `server/src/lobby.js`)
- Matchmaking lobby → Room Durable Object: creates rooms (evidence: `server/src/lobby.js`)
- Room Durable Object → Room game authority: delegates room logic (evidence: `server/src/room.js`)
- Room game authority → Shared rules engine: checks game rules (evidence: `server/src/room-logic.js`)
- Room Durable Object → Matchmaking lobby: updates lobby (evidence: `server/src/room.js`)
- Online client → Room Durable Object: sends player actions
