# scribble-rs/scribble.rs architecture

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

- Interactive diagram: https://gitdiagram.com/scribble-rs/scribble.rs
- Repository: https://github.com/scribble-rs/scribble.rs

## Overview

Scribble.rs is a browser-based, account-free Pictionary game. Players create or join lobbies, configure game options, and play drawing-and-guessing rounds; the server handles lobby state and real-time events. The graph separates HTTP/API handling, game rules and state, and the browser experience, with configuration, translations, and metrics as supporting services. The principal runtime and several cross-module references are shown in sampled source or the source index; unsampled frontend wiring is left out rather than inferred.

Main entry points: [`internal/state/lobbies.go`](https://github.com/scribble-rs/scribble.rs/blob/master/internal/state/lobbies.go) (Lobby Registry), [`internal/game/lobby.go`](https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/lobby.go) (Game Lifecycle), [`cmd/scribblers/main.go`](https://github.com/scribble-rs/scribble.rs/blob/master/cmd/scribblers/main.go) (Server Runtime), [`internal/frontend/index.go`](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/index.go) (Lobby Creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server Entry"]
  node_main["Server Runtime<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_metrics["Metrics<br/>[metrics.go]"]
end

subgraph group_interfaces["HTTP Interfaces"]
  node_api_http["API Routes<br/>[http.go]"]
  node_api_v1["Lobby API<br/>[v1.go]"]
  node_api_parse["Input Validation<br/>[createparse.go]"]
  node_websocket["WebSocket Handler<br/>[ws.go]"]
  node_frontend_http["Frontend Routes<br/>[http.go]"]
  node_home["Lobby Creation<br/>[index.go]"]
  node_lobby_page["Lobby Entry<br/>[lobby.go]"]
end

subgraph group_game["Game Domain"]
  node_lobby_state[("Lobby Registry<br/>[lobbies.go]")]
  node_game_lobby["Game Lifecycle<br/>[lobby.go]"]
  node_game_data["Game Data<br/>[data.go]"]
  node_game_shared["Shared Rules<br/>[shared.go]"]
  node_word_lists["Word Lists<br/>[words.go]"]
  node_sanitizer["Text Sanitization<br/>[sanitize.go]"]
end

subgraph group_web["Browser Experience"]
  node_translations["Translations<br/>[translations.go]"]
  node_lobby_client["Lobby Client<br/>[lobby.js]"]
  node_drawing_client["Drawing Tools<br/>[draw.js]"]
  node_keyboard["Keyboard Controls<br/>[keyboardManager.js]"]
end

node_browser(("Players"))

node_main -->|"loads settings"| node_config
node_main -->|"registers routes"| node_api_http
node_main -->|"registers routes"| node_frontend_http
node_main -->|"starts cleanup"| node_lobby_state
node_api_http -->|"serves metrics"| node_metrics
node_api_v1 -->|"creates lobbies"| node_game_lobby
node_api_v1 -->|"stores and looks up"| node_lobby_state
node_api_v1 -->|"validates settings"| node_api_parse
node_api_parse -->|"reads bounds"| node_config
node_api_parse -->|"uses game types"| node_game_shared
node_websocket -->|"finds lobby"| node_lobby_state
node_websocket -->|"dispatches events"| node_game_lobby
node_websocket -->|"tracks connections"| node_metrics
node_game_lobby -->|"sanitizes text"| node_sanitizer
node_lobby_state -->|"stores lobbies"| node_game_lobby
node_lobby_state -->|"uses cleanup settings"| node_config
node_home -->|"validates options"| node_api_parse
node_home -->|"creates lobby"| node_game_lobby
node_home -->|"uses lobby state"| node_lobby_state
node_home -->|"uses translations"| node_translations
node_lobby_page -->|"looks up lobby"| node_lobby_state
node_lobby_page -->|"joins player"| node_game_lobby
node_lobby_page -->|"uses lobby data"| node_api_v1
node_lobby_page -->|"selects language"| node_translations
node_frontend_http -->|"uses translations"| node_translations
node_lobby_client -->|"uses controls"| node_keyboard
node_browser -.->|"plays game"| node_main
node_browser -.->|"uses client"| node_lobby_client

click node_main "https://github.com/scribble-rs/scribble.rs/blob/master/cmd/scribblers/main.go"
click node_config "https://github.com/scribble-rs/scribble.rs/blob/master/internal/config/config.go"
click node_api_http "https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/http.go"
click node_api_v1 "https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/v1.go"
click node_api_parse "https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/createparse.go"
click node_websocket "https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/ws.go"
click node_frontend_http "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/http.go"
click node_home "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/index.go"
click node_lobby_page "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/lobby.go"
click node_lobby_state "https://github.com/scribble-rs/scribble.rs/blob/master/internal/state/lobbies.go"
click node_game_lobby "https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/lobby.go"
click node_game_data "https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/data.go"
click node_game_shared "https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/shared.go"
click node_word_lists "https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/words.go"
click node_sanitizer "https://github.com/scribble-rs/scribble.rs/blob/master/internal/sanitize/sanitize.go"
click node_metrics "https://github.com/scribble-rs/scribble.rs/blob/master/internal/metrics/metrics.go"
click node_translations "https://github.com/scribble-rs/scribble.rs/blob/master/internal/translations/translations.go"
click node_lobby_client "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/lobby.js"
click node_drawing_client "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/resources/draw.js"
click node_keyboard "https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/resources/keyboardManager.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_main,node_config,node_metrics toneBlue
class node_api_http,node_api_v1,node_api_parse,node_websocket,node_frontend_http,node_home,node_lobby_page toneAmber
class node_lobby_state,node_game_lobby,node_game_data,node_game_shared,node_word_lists,node_sanitizer toneMint
class node_translations,node_lobby_client,node_drawing_client,node_keyboard toneRose
class node_browser toneIndigo
```

## Components

### Server Entry

- [Server Runtime](https://github.com/scribble-rs/scribble.rs/blob/master/cmd/scribblers/main.go): `cmd/scribblers/main.go`
- [Configuration](https://github.com/scribble-rs/scribble.rs/blob/master/internal/config/config.go): `internal/config/config.go`
- [Metrics](https://github.com/scribble-rs/scribble.rs/blob/master/internal/metrics/metrics.go): `internal/metrics/metrics.go`

### HTTP Interfaces

- [API Routes](https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/http.go): `internal/api/http.go`
- [Lobby API](https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/v1.go): `internal/api/v1.go`
- [Input Validation](https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/createparse.go): `internal/api/createparse.go`
- [WebSocket Handler](https://github.com/scribble-rs/scribble.rs/blob/master/internal/api/ws.go): `internal/api/ws.go`
- [Frontend Routes](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/http.go): `internal/frontend/http.go`
- [Lobby Creation](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/index.go): `internal/frontend/index.go`
- [Lobby Entry](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/lobby.go): `internal/frontend/lobby.go`

### Game Domain

- [Lobby Registry](https://github.com/scribble-rs/scribble.rs/blob/master/internal/state/lobbies.go): `internal/state/lobbies.go`
- [Game Lifecycle](https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/lobby.go): `internal/game/lobby.go`
- [Game Data](https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/data.go): `internal/game/data.go`
- [Shared Rules](https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/shared.go): `internal/game/shared.go`
- [Word Lists](https://github.com/scribble-rs/scribble.rs/blob/master/internal/game/words.go): `internal/game/words.go`
- [Text Sanitization](https://github.com/scribble-rs/scribble.rs/blob/master/internal/sanitize/sanitize.go): `internal/sanitize/sanitize.go`

### Browser Experience

- [Translations](https://github.com/scribble-rs/scribble.rs/blob/master/internal/translations/translations.go): `internal/translations/translations.go`
- [Lobby Client](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/lobby.js): `internal/frontend/lobby.js`
- [Drawing Tools](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/resources/draw.js): `internal/frontend/resources/draw.js`
- [Keyboard Controls](https://github.com/scribble-rs/scribble.rs/blob/master/internal/frontend/resources/keyboardManager.js): `internal/frontend/resources/keyboardManager.js`

### Other components

- **Players**

## Connections

- Server Runtime → Configuration: loads settings (evidence: `cmd/scribblers/main.go`)
- Server Runtime → API Routes: registers routes (evidence: `cmd/scribblers/main.go`)
- Server Runtime → Frontend Routes: registers routes (evidence: `cmd/scribblers/main.go`)
- Server Runtime → Lobby Registry: starts cleanup (evidence: `cmd/scribblers/main.go`)
- API Routes → Metrics: serves metrics (evidence: `internal/api/http.go`)
- Lobby API → Game Lifecycle: creates lobbies (evidence: `internal/api/v1.go`)
- Lobby API → Lobby Registry: stores and looks up (evidence: `internal/api/v1.go`)
- Lobby API → Input Validation: validates settings (evidence: `internal/api/v1.go`)
- Input Validation → Configuration: reads bounds (evidence: `internal/api/createparse.go`)
- Input Validation → Shared Rules: uses game types (evidence: `internal/api/createparse.go`)
- WebSocket Handler → Lobby Registry: finds lobby (evidence: `internal/api/ws.go`)
- WebSocket Handler → Game Lifecycle: dispatches events (evidence: `internal/api/ws.go`)
- WebSocket Handler → Metrics: tracks connections (evidence: `internal/api/ws.go`)
- Game Lifecycle → Text Sanitization: sanitizes text (evidence: `internal/game/lobby.go`)
- Lobby Registry → Game Lifecycle: stores lobbies (evidence: `internal/state/lobbies.go`)
- Lobby Registry → Configuration: uses cleanup settings (evidence: `internal/state/lobbies.go`)
- Lobby Creation → Input Validation: validates options (evidence: `internal/frontend/index.go`)
- Lobby Creation → Game Lifecycle: creates lobby (evidence: `internal/frontend/index.go`)
- Lobby Creation → Lobby Registry: uses lobby state (evidence: `internal/frontend/index.go`)
- Lobby Creation → Translations: uses translations (evidence: `internal/frontend/index.go`)
- Lobby Entry → Lobby Registry: looks up lobby (evidence: `internal/frontend/lobby.go`)
- Lobby Entry → Game Lifecycle: joins player (evidence: `internal/frontend/lobby.go`)
- Lobby Entry → Lobby API: uses lobby data (evidence: `internal/frontend/lobby.go`)
- Lobby Entry → Translations: selects language (evidence: `internal/frontend/lobby.go`)
- Frontend Routes → Translations: uses translations (evidence: `internal/frontend/http.go`)
- Lobby Client → Keyboard Controls: uses controls (evidence: `internal/frontend/lobby.js`)
- Players → Server Runtime: plays game (evidence: `README.md`)
- Players → Lobby Client: uses client
