# xyloheat/baduk architecture

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

- Interactive diagram: https://gitdiagram.com/xyloheat/baduk
- Repository: https://github.com/xyloheat/baduk

## Overview

This is a dependency-free browser Go app for learning and playing. The main workflow is a player interacting with the UI, which uses the rules engine for moves and scoring; play can be hot-seat, lesson-based, or routed to a bot. Medium play uses a Monte Carlo worker, while stronger tiers use a lazy-loaded KataGo neural worker and model assets. The README documents additional UI capabilities including multilingual themes, keyboard controls, and mascot expressions. Neural-worker internals were not sampled, so its model and TensorFlow.js links reflect documented dependencies; deployment links reflect the documented Pages/R2 setup.

Main entry points: [`ui.js`](https://github.com/xyloheat/baduk/blob/main/ui.js) (Game UI), [`neural-worker.js`](https://github.com/xyloheat/baduk/blob/main/neural-worker.js) (KataGo worker), [`worker.js`](https://github.com/xyloheat/baduk/blob/main/worker.js) (Monte Carlo bot), [`engine.js`](https://github.com/xyloheat/baduk/blob/main/engine.js) (Go rules engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Browser interface"]
  node_page["App page<br/>[index.html]"]
  node_styles["Themes and layout<br/>[styles.css]"]
  node_ui["Game UI<br/>[ui.js]"]
  node_mascot["Stone artwork"]
end

subgraph group_gameplay["Rules and learning"]
  node_engine["Go rules engine<br/>[engine.js]"]
  node_lessons["Interactive lessons<br/>[lessons.js]"]
end

subgraph group_bots["Bot play"]
  node_mcworker["Monte Carlo bot<br/>[worker.js]"]
  node_neuralworker["KataGo worker<br/>[neural-worker.js]"]
  node_tfjs["TensorFlow.js WASM"]
end

subgraph group_models["Neural model delivery"]
  node_compactmodel["Compact model"]
  node_modelroute["Model streaming function<br/>[&#91;&#91;path&#93;&#93;.js]"]
  node_r2[("R2 model bucket")]
end

node_player(("Player"))

node_player -->|"plays through"| node_ui
node_page -->|"loads app code"| node_ui
node_page -->|"loads styles"| node_styles
node_ui -->|"applies moves, scores"| node_engine
node_engine -->|"returns game state"| node_ui
node_ui -->|"reads lesson content"| node_lessons
node_ui -->|"displays artwork"| node_mascot
node_ui -->|"dispatches medium bot"| node_mcworker
node_mcworker -->|"uses rules"| node_engine
node_mcworker -->|"returns move"| node_ui
node_ui -->|"dispatches neural bot"| node_neuralworker
node_neuralworker -->|"runs inference"| node_tfjs
node_neuralworker -->|"loads compact net"| node_compactmodel
node_neuralworker -.->|"fetches dan net"| node_modelroute
node_modelroute -->|"reads model object"| node_r2

click node_page "https://github.com/xyloheat/baduk/blob/main/index.html"
click node_styles "https://github.com/xyloheat/baduk/blob/main/styles.css"
click node_ui "https://github.com/xyloheat/baduk/blob/main/ui.js"
click node_mascot "https://github.com/xyloheat/baduk/tree/main/assets/mascot"
click node_engine "https://github.com/xyloheat/baduk/blob/main/engine.js"
click node_lessons "https://github.com/xyloheat/baduk/blob/main/lessons.js"
click node_mcworker "https://github.com/xyloheat/baduk/blob/main/worker.js"
click node_neuralworker "https://github.com/xyloheat/baduk/blob/main/neural-worker.js"
click node_tfjs "https://github.com/xyloheat/baduk/tree/main/tfjs"
click node_compactmodel "https://github.com/xyloheat/baduk/blob/main/assets/models/kata-small-b6c96.bin.gz"
click node_modelroute "https://github.com/xyloheat/baduk/blob/main/functions/models/%5B%5Bpath%5D%5D.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_page,node_styles,node_ui,node_mascot toneBlue
class node_engine,node_lessons toneAmber
class node_mcworker,node_neuralworker,node_tfjs toneMint
class node_compactmodel,node_modelroute,node_r2 toneRose
class node_player toneIndigo
```

## Components

### Browser interface

- [App page](https://github.com/xyloheat/baduk/blob/main/index.html): `index.html`
- [Themes and layout](https://github.com/xyloheat/baduk/blob/main/styles.css): `styles.css`
- [Game UI](https://github.com/xyloheat/baduk/blob/main/ui.js): `ui.js`
- [Stone artwork](https://github.com/xyloheat/baduk/tree/main/assets/mascot): `assets/mascot`

### Rules and learning

- [Go rules engine](https://github.com/xyloheat/baduk/blob/main/engine.js): `engine.js`
- [Interactive lessons](https://github.com/xyloheat/baduk/blob/main/lessons.js): `lessons.js`

### Bot play

- [Monte Carlo bot](https://github.com/xyloheat/baduk/blob/main/worker.js): `worker.js`
- [KataGo worker](https://github.com/xyloheat/baduk/blob/main/neural-worker.js): `neural-worker.js`
- [TensorFlow.js WASM](https://github.com/xyloheat/baduk/tree/main/tfjs): `tfjs`

### Neural model delivery

- [Compact model](https://github.com/xyloheat/baduk/blob/main/assets/models/kata-small-b6c96.bin.gz): `assets/models/kata-small-b6c96.bin.gz`
- [Model streaming function](https://github.com/xyloheat/baduk/blob/main/functions/models/%5B%5Bpath%5D%5D.js): `functions/models/[[path]].js`
- **R2 model bucket**

### Other components

- **Player**

## Connections

- Player → Game UI: plays through
- App page → Game UI: loads app code
- App page → Themes and layout: loads styles
- Game UI → Go rules engine: applies moves, scores
- Go rules engine → Game UI: returns game state
- Game UI → Interactive lessons: reads lesson content
- Game UI → Stone artwork: displays artwork
- Game UI → Monte Carlo bot: dispatches medium bot
- Monte Carlo bot → Go rules engine: uses rules
- Monte Carlo bot → Game UI: returns move
- Game UI → KataGo worker: dispatches neural bot
- KataGo worker → TensorFlow.js WASM: runs inference
- KataGo worker → Compact model: loads compact net
- KataGo worker → Model streaming function: fetches dan net
- Model streaming function → R2 model bucket: reads model object
