# yahel150/nimgame architecture

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

- Interactive diagram: https://gitdiagram.com/yahel150/nimgame
- Repository: https://github.com/yahel150/nimgame

## Overview

NimGame is a browser-based Nim game for human-vs-computer or same-device play. The user chooses an opponent, a preset or custom variant, and a piece style; the browser then renders the board and sends selections and confirmed moves to the WebAssembly game engine. The engine manages sessions, validates rules, applies moves, and chooses computer moves; the browser displays the resulting state and outcome. The README documents misère, poisoned-pile, take-away, and custom games. The excerpts show the browser/Wasm boundary and core engine logic, but not the Wasm bindings, so that connection is shown only at the boundary.

Main entry points: [`src/engine/game_service.cpp`](https://github.com/yahel150/nimgame/blob/main/src/engine/game_service.cpp) (Session service), [`src/web/app.js`](https://github.com/yahel150/nimgame/blob/main/src/web/app.js) (Game interface), [`src/engine/rules.cpp`](https://github.com/yahel150/nimgame/blob/main/src/engine/rules.cpp) (Move rules), [`src/engine/strategies.cpp`](https://github.com/yahel150/nimgame/blob/main/src/engine/strategies.cpp) (Computer strategy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser experience"]
  node_webapp["Game interface<br/>[app.js]"]
  node_pieceassets["Piece imagery"]
end

subgraph group_engine["Game engine"]
  node_service["Session service<br/>[game_service.cpp]"]
  node_config["Game configuration<br/>[game_config.cpp]"]
  node_state["Game state<br/>[game_state.cpp]"]
  node_history["Undo history<br/>[history.cpp]"]
  node_serialization["JSON serialization<br/>[serialization.cpp]"]
end

subgraph group_logic["Rules and strategy"]
  node_rules["Move rules<br/>[rules.cpp]"]
  node_strategy["Computer strategy<br/>[strategies.cpp]"]
end

node_player(("Player"))

node_player -->|"chooses and plays"| node_webapp
node_webapp -->|"requests via Wasm"| node_service
node_webapp -->|"loads piece art"| node_pieceassets
node_service -->|"builds preset config"| node_config
node_service -->|"creates and updates"| node_state
node_service -->|"records and restores"| node_history
node_service -->|"validates and applies"| node_rules
node_service -->|"requests computer move"| node_strategy
node_rules -->|"checks winning position"| node_strategy
node_service --> node_serialization

click node_webapp "https://github.com/yahel150/nimgame/blob/main/src/web/app.js"
click node_pieceassets "https://github.com/yahel150/nimgame/tree/main/assets/images"
click node_service "https://github.com/yahel150/nimgame/blob/main/src/engine/game_service.cpp"
click node_config "https://github.com/yahel150/nimgame/blob/main/src/engine/game_config.cpp"
click node_state "https://github.com/yahel150/nimgame/blob/main/src/engine/game_state.cpp"
click node_history "https://github.com/yahel150/nimgame/blob/main/src/engine/history.cpp"
click node_serialization "https://github.com/yahel150/nimgame/blob/main/src/engine/serialization.cpp"
click node_rules "https://github.com/yahel150/nimgame/blob/main/src/engine/rules.cpp"
click node_strategy "https://github.com/yahel150/nimgame/blob/main/src/engine/strategies.cpp"

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_webapp,node_pieceassets toneBlue
class node_service,node_config,node_state,node_history,node_serialization toneAmber
class node_rules,node_strategy toneMint
class node_player toneIndigo
```

## Components

### Browser experience

- [Game interface](https://github.com/yahel150/nimgame/blob/main/src/web/app.js): `src/web/app.js`
- [Piece imagery](https://github.com/yahel150/nimgame/tree/main/assets/images): `assets/images`

### Game engine

- [Session service](https://github.com/yahel150/nimgame/blob/main/src/engine/game_service.cpp): `src/engine/game_service.cpp`
- [Game configuration](https://github.com/yahel150/nimgame/blob/main/src/engine/game_config.cpp): `src/engine/game_config.cpp`
- [Game state](https://github.com/yahel150/nimgame/blob/main/src/engine/game_state.cpp): `src/engine/game_state.cpp`
- [Undo history](https://github.com/yahel150/nimgame/blob/main/src/engine/history.cpp): `src/engine/history.cpp`
- [JSON serialization](https://github.com/yahel150/nimgame/blob/main/src/engine/serialization.cpp): `src/engine/serialization.cpp`

### Rules and strategy

- [Move rules](https://github.com/yahel150/nimgame/blob/main/src/engine/rules.cpp): `src/engine/rules.cpp`
- [Computer strategy](https://github.com/yahel150/nimgame/blob/main/src/engine/strategies.cpp): `src/engine/strategies.cpp`

### Other components

- **Player**

## Connections

- Player → Game interface: chooses and plays
- Game interface → Session service: requests via Wasm
- Game interface → Piece imagery: loads piece art
- Session service → Game configuration: builds preset config
- Session service → Game state: creates and updates
- Session service → Undo history: records and restores
- Session service → Move rules: validates and applies
- Session service → Computer strategy: requests computer move
- Move rules → Computer strategy: checks winning position
- Session service → JSON serialization
