# gbghost17/kenken architecture

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

- Interactive diagram: https://gitdiagram.com/gbghost17/kenken
- Repository: https://github.com/gbghost17/kenken

## Overview

KenKen is a command-line puzzle generator and multi-stage solver. The documented workflow accepts a board size, generates a Latin-square solution and arithmetic cages, selects a solver by size, then exports the solving process or result as an animated GIF. The single Python file combines these responsibilities; the sampled excerpts show the solver and renderer, while README statements support the overall workflow and capabilities. OR-Tools is optional, with a documented fallback for larger boards.

Main entry points: [`kenken2.py`](https://github.com/gbghost17/kenken/blob/main/kenken2.py) (Solver controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Puzzle generation"]
  node_latin["Latin square<br/>[kenken2.py]"]
  node_cages["Cage construction<br/>[kenken2.py]"]
end

subgraph group_solving["Solving"]
  node_controller["Solver controller<br/>[kenken2.py]"]
  node_basic["Basic backtracking<br/>[kenken2.py]"]
  node_mrv["MRV forward checking<br/>[kenken2.py]"]
  node_cpsat["CP-SAT solver<br/>[kenken2.py]"]
  node_history[("Action history<br/>[kenken2.py]")]
end

subgraph group_output["Visualization"]
  node_renderer["GIF renderer<br/>[kenken2.py]"]
  node_gif["Solution GIF"]
end

node_user(("CLI user"))
node_entry["CLI workflow<br/>[kenken2.py]"]
node_ortools["OR-Tools"]

node_user -->|"enters size"| node_entry
node_entry -->|"generates solution"| node_latin
node_entry -->|"builds cages"| node_cages
node_entry -->|"starts solving"| node_controller
node_controller -->|"selects n ≤ 6"| node_basic
node_controller -->|"selects n = 7–8"| node_mrv
node_controller -->|"selects n ≥ 9"| node_cpsat
node_cpsat -.->|"uses when available"| node_ortools
node_basic -->|"records steps"| node_history
node_mrv -->|"records steps"| node_history
node_controller -->|"renders solution"| node_renderer
node_history -->|"supplies steps"| node_renderer
node_renderer -->|"exports GIF"| node_gif

click node_entry "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_latin "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_cages "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_controller "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_basic "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_mrv "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_cpsat "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_history "https://github.com/gbghost17/kenken/blob/main/kenken2.py"
click node_renderer "https://github.com/gbghost17/kenken/blob/main/kenken2.py"

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_latin,node_cages,node_user toneBlue
class node_controller,node_basic,node_mrv,node_cpsat,node_history toneAmber
class node_renderer,node_gif toneMint
class node_entry toneTeal
class node_ortools toneIndigo
```

## Components

### Puzzle generation

- [Latin square](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- [Cage construction](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`

### Solving

- [Solver controller](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- [Basic backtracking](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- [MRV forward checking](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- [CP-SAT solver](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- [Action history](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`

### Visualization

- [GIF renderer](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- **Solution GIF**

### Other components

- **CLI user**
- [CLI workflow](https://github.com/gbghost17/kenken/blob/main/kenken2.py): `kenken2.py`
- **OR-Tools**

## Connections

- CLI user → CLI workflow: enters size (evidence: `README.md`)
- CLI workflow → Latin square: generates solution (evidence: `kenken2.py`)
- CLI workflow → Cage construction: builds cages (evidence: `kenken2.py`)
- CLI workflow → Solver controller: starts solving (evidence: `kenken2.py`)
- Solver controller → Basic backtracking: selects n ≤ 6 (evidence: `README.md`)
- Solver controller → MRV forward checking: selects n = 7–8 (evidence: `README.md`)
- Solver controller → CP-SAT solver: selects n ≥ 9 (evidence: `kenken2.py`)
- CP-SAT solver → OR-Tools: uses when available (evidence: `kenken2.py`)
- Basic backtracking → Action history: records steps (evidence: `kenken2.py`)
- MRV forward checking → Action history: records steps (evidence: `kenken2.py`)
- Solver controller → GIF renderer: renders solution (evidence: `kenken2.py`)
- Action history → GIF renderer: supplies steps (evidence: `kenken2.py`)
- GIF renderer → Solution GIF: exports GIF (evidence: `README.md`)
