# 45ngc/boardsnap architecture

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

- Interactive diagram: https://gitdiagram.com/45ngc/boardsnap
- Repository: https://github.com/45ngc/boardsnap

## Overview

BoardSnap is a Python chessboard image-recognition package with a JSON CLI for digital-board profiles and an experimental book-diagram profile. The main workflow accepts a local image, detects and normalizes its board, splits squares, resolves orientation, classifies pieces, and returns FEN-style piece placement; CLI adapts results and errors. Separate repository tools support annotated capture, frozen position plans, square-dataset preparation, and an optional PyTorch classifier. Edges follow the sampled pipeline and explicit README capabilities; capture/data-tool internals are represented conservatively where implementation was not fully sampled.

Main entry points: [`src/boardsnap/pipeline.py`](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/pipeline.py) (Recognition pipeline), [`src/boardsnap/neural.py`](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/neural.py) (Optional neural inference), [`tools/capture_lichess.py`](https://github.com/45ngc/boardsnap/blob/main/tools/capture_lichess.py) (Annotated capture), [`src/boardsnap/orientation.py`](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/orientation.py) (Orientation reading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interface"]
  node_cli["JSON CLI<br/>[cli.py]"]
  node_pipeline["Recognition pipeline<br/>[pipeline.py]"]
end

subgraph group_recognition["Recognition stages"]
  node_input["Image decoding<br/>[image_input.py]"]
  node_detect["Board detection<br/>[detection.py]"]
  node_normalize["Board normalization<br/>[normalization.py]"]
  node_segment["Square segmentation<br/>[segmentation.py]"]
  node_orientation["Orientation reading<br/>[orientation.py]"]
  node_output["Placement encoding<br/>[output.py]"]
end

subgraph group_assets["Profiles and classifiers"]
  node_classification["Template recognition<br/>[classification.py]"]
  node_profiles["Recognition profiles<br/>[profiles.py]"]
  node_templates["Shipped templates"]
  node_neural["Optional neural inference<br/>[neural.py]"]
end

subgraph group_data["Dataset workflows"]
  node_capture["Annotated capture<br/>[capture_lichess.py]"]
  node_captureconfig["Configurable capture<br/>[capture_batch.py]"]
  node_positions["Position planning"]
  node_squaredata["Square dataset"]
  node_neuraldata["Neural dataset<br/>[neural_data.py]"]
  node_corpus["Clean corpus"]
end

node_user(("Image user"))
node_web(("Lichess editor"))

node_user -->|"submits image"| node_cli
node_cli -->|"invokes"| node_pipeline
node_pipeline -->|"reads image"| node_input
node_pipeline -->|"detects board"| node_detect
node_pipeline -->|"normalizes bounds"| node_normalize
node_pipeline -->|"splits squares"| node_segment
node_pipeline -->|"resolves view"| node_orientation
node_pipeline -->|"classifies squares"| node_classification
node_pipeline -->|"encodes placement"| node_output
node_classification -->|"loads profile"| node_profiles
node_orientation -->|"loads profile"| node_profiles
node_classification -->|"loads piece assets"| node_templates
node_orientation -->|"loads glyph assets"| node_templates
node_neural -->|"reads image"| node_input
node_neural -->|"detects board"| node_detect
node_neural -->|"normalizes bounds"| node_normalize
node_neural -->|"splits squares"| node_segment
node_neural -->|"encodes placement"| node_output
node_web -.->|"provides board"| node_capture
node_capture -.->|"validates plan"| node_positions
node_captureconfig -->|"uses plan"| node_positions
node_captureconfig -->|"collects captures"| node_capture
node_capture -.->|"supplies captures"| node_corpus
node_corpus -->|"prepares crops"| node_squaredata
node_positions -->|"validates sources"| node_squaredata
node_squaredata -.->|"provides squares"| node_neuraldata
node_neuraldata -.->|"supports training"| node_neural

click node_cli "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/adapters/cli.py"
click node_pipeline "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/pipeline.py"
click node_input "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/image_input.py"
click node_detect "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/detection.py"
click node_normalize "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/normalization.py"
click node_segment "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/segmentation.py"
click node_orientation "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/orientation.py"
click node_classification "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/classification.py"
click node_profiles "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/profiles.py"
click node_templates "https://github.com/45ngc/boardsnap/tree/main/src/boardsnap/assets"
click node_output "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/output.py"
click node_neural "https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/neural.py"
click node_capture "https://github.com/45ngc/boardsnap/blob/main/tools/capture_lichess.py"
click node_captureconfig "https://github.com/45ngc/boardsnap/blob/main/tools/capture_batch.py"
click node_positions "https://github.com/45ngc/boardsnap/blob/main/tools/position_dataset.py"
click node_squaredata "https://github.com/45ngc/boardsnap/blob/main/tools/build_square_dataset.py"
click node_neuraldata "https://github.com/45ngc/boardsnap/blob/main/tools/neural_data.py"
click node_corpus "https://github.com/45ngc/boardsnap/blob/main/tools/collect_clean_corpus.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_cli,node_pipeline,node_user toneBlue
class node_input,node_detect,node_normalize,node_segment,node_orientation,node_output toneAmber
class node_classification,node_profiles,node_templates,node_neural toneMint
class node_capture,node_captureconfig,node_positions,node_squaredata,node_neuraldata,node_corpus toneRose
class node_web toneIndigo
```

## Components

### User interface

- [JSON CLI](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/adapters/cli.py): `src/boardsnap/adapters/cli.py`
- [Recognition pipeline](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/pipeline.py): `src/boardsnap/pipeline.py`

### Recognition stages

- [Image decoding](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/image_input.py): `src/boardsnap/image_input.py`
- [Board detection](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/detection.py): `src/boardsnap/detection.py`
- [Board normalization](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/normalization.py): `src/boardsnap/normalization.py`
- [Square segmentation](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/segmentation.py): `src/boardsnap/segmentation.py`
- [Orientation reading](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/orientation.py): `src/boardsnap/orientation.py`
- [Placement encoding](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/output.py): `src/boardsnap/output.py`

### Profiles and classifiers

- [Template recognition](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/classification.py): `src/boardsnap/classification.py`
- [Recognition profiles](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/profiles.py): `src/boardsnap/profiles.py`
- [Shipped templates](https://github.com/45ngc/boardsnap/tree/main/src/boardsnap/assets): `src/boardsnap/assets`
- [Optional neural inference](https://github.com/45ngc/boardsnap/blob/main/src/boardsnap/neural.py): `src/boardsnap/neural.py`

### Dataset workflows

- [Annotated capture](https://github.com/45ngc/boardsnap/blob/main/tools/capture_lichess.py): `tools/capture_lichess.py`
- [Configurable capture](https://github.com/45ngc/boardsnap/blob/main/tools/capture_batch.py): `tools/capture_batch.py`
- [Position planning](https://github.com/45ngc/boardsnap/blob/main/tools/position_dataset.py): `tools/position_dataset.py`
- [Square dataset](https://github.com/45ngc/boardsnap/blob/main/tools/build_square_dataset.py): `tools/build_square_dataset.py`
- [Neural dataset](https://github.com/45ngc/boardsnap/blob/main/tools/neural_data.py): `tools/neural_data.py`
- [Clean corpus](https://github.com/45ngc/boardsnap/blob/main/tools/collect_clean_corpus.py): `tools/collect_clean_corpus.py`

### Other components

- **Image user**
- **Lichess editor**

## Connections

- Image user → JSON CLI: submits image (evidence: `README.md`)
- JSON CLI → Recognition pipeline: invokes (evidence: `src/boardsnap/adapters/cli.py`)
- Recognition pipeline → Image decoding: reads image (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Board detection: detects board (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Board normalization: normalizes bounds (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Square segmentation: splits squares (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Orientation reading: resolves view (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Template recognition: classifies squares (evidence: `src/boardsnap/pipeline.py`)
- Recognition pipeline → Placement encoding: encodes placement (evidence: `src/boardsnap/pipeline.py`)
- Template recognition → Recognition profiles: loads profile (evidence: `src/boardsnap/classification.py`)
- Orientation reading → Recognition profiles: loads profile (evidence: `src/boardsnap/orientation.py`)
- Template recognition → Shipped templates: loads piece assets (evidence: `src/boardsnap/classification.py`)
- Orientation reading → Shipped templates: loads glyph assets (evidence: `src/boardsnap/orientation.py`)
- Optional neural inference → Image decoding: reads image (evidence: `src/boardsnap/neural.py`)
- Optional neural inference → Board detection: detects board (evidence: `src/boardsnap/neural.py`)
- Optional neural inference → Board normalization: normalizes bounds (evidence: `src/boardsnap/neural.py`)
- Optional neural inference → Square segmentation: splits squares (evidence: `src/boardsnap/neural.py`)
- Optional neural inference → Placement encoding: encodes placement (evidence: `src/boardsnap/neural.py`)
- Lichess editor → Annotated capture: provides board (evidence: `README.md`)
- Annotated capture → Position planning: validates plan (evidence: `tools/capture_lichess.py`)
- Configurable capture → Position planning: uses plan (evidence: `tools/capture_batch.py`)
- Configurable capture → Annotated capture: collects captures (evidence: `tools/capture_batch.py`)
- Annotated capture → Clean corpus: supplies captures (evidence: `README.md`)
- Clean corpus → Square dataset: prepares crops (evidence: `tools/build_square_dataset.py`)
- Position planning → Square dataset: validates sources (evidence: `tools/build_square_dataset.py`)
- Square dataset → Neural dataset: provides squares (evidence: `tools/neural_data.py`)
- Neural dataset → Optional neural inference: supports training (evidence: `README.md`)
