# lichess-org/chessground architecture

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

- Interactive diagram: https://gitdiagram.com/lichess-org/chessground
- Repository: https://github.com/lichess-org/chessground

## Overview

Chessground is a browser-based chessboard UI library, not a chess-rules engine. The main workflow is an application creating a board, then using its API and browser interactions to change position or draw annotations; the library updates and animates the DOM and exposes callbacks. The graph also preserves documented FEN, premove, styling, and piece-rendering capabilities. Some links rely on the SOURCE INDEX’s import/reference lists rather than full excerpts; unsampled implementation details are not inferred.

Main entry points: [`src/board.ts`](https://github.com/lichess-org/chessground/blob/master/src/board.ts) (Board operations), [`src/chessground.ts`](https://github.com/lichess-org/chessground/blob/master/src/chessground.ts) (Board factory), [`src/api.ts`](https://github.com/lichess-org/chessground/blob/master/src/api.ts) (Board API), [`src/state.ts`](https://github.com/lichess-org/chessground/blob/master/src/state.ts) (Board state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Board setup"]
  node_bootstrap["Board factory<br/>[chessground.ts]"]
  node_api["Board API<br/>[api.ts]"]
  node_wrapper["DOM wrapper<br/>[wrap.ts]"]
end

subgraph group_interaction["Board interaction"]
  node_events["Input events<br/>[events.ts]"]
  node_drag["Drag handling<br/>[drag.ts]"]
  node_drop["Drop handling<br/>[drop.ts]"]
  node_board["Board operations<br/>[board.ts]"]
  node_premove["Premoves<br/>[premove.ts]"]
  node_drawing["Shape drawing<br/>[draw.ts]"]
end

subgraph group_display["Rendering and display"]
  node_sync["Shape synchronization<br/>[sync.ts]"]
  node_svg["SVG shapes<br/>[svg.ts]"]
  node_auto["Auto pieces<br/>[autoPieces.ts]"]
  node_renderer["DOM renderer<br/>[render.ts]"]
  node_animation["Piece animation<br/>[anim.ts]"]
  node_styles["Board and piece styles"]
end

subgraph group_model["Position and state"]
  node_state["Board state<br/>[state.ts]"]
  node_config["Configuration<br/>[config.ts]"]
  node_fen["FEN conversion<br/>[fen.ts]"]
  node_glyph["Piece glyphs<br/>[glyph.ts]"]
  node_types["Shared types<br/>[types.ts]"]
end

node_user(("Application user"))

node_user -->|"creates board"| node_bootstrap
node_bootstrap -->|"creates API"| node_api
node_bootstrap -->|"binds input"| node_events
node_bootstrap -->|"sets rendering"| node_renderer
node_bootstrap -->|"wraps board"| node_wrapper
node_bootstrap -->|"creates state"| node_state
node_api -->|"configures"| node_config
node_api -->|"mutates position"| node_board
node_api -->|"exports FEN"| node_fen
node_api -->|"animates changes"| node_animation
node_api -->|"exposes state"| node_state
node_events -->|"dispatches drag"| node_drag
node_events -->|"dispatches drawing"| node_drawing
node_events -->|"dispatches drop"| node_drop
node_drag -->|"uses board ops"| node_board
node_drop -->|"uses board ops"| node_board
node_board -->|"computes premoves"| node_premove
node_drawing -->|"maps pointer"| node_board
node_sync -->|"reads shapes"| node_drawing
node_svg -->|"renders shapes"| node_drawing
node_auto -->|"reads position"| node_board
node_auto -->|"uses auto shapes"| node_drawing
node_auto -->|"synchronizes"| node_sync
node_renderer -->|"reads animation"| node_animation
node_renderer -->|"uses orientation"| node_board
node_renderer -->|"renders state"| node_state
node_wrapper -->|"uses state"| node_state
node_wrapper -->|"manages SVG"| node_svg
node_state -->|"loads position"| node_fen
node_config -->|"configures state"| node_state
node_user -->|"selects styles"| node_styles

click node_bootstrap "https://github.com/lichess-org/chessground/blob/master/src/chessground.ts"
click node_api "https://github.com/lichess-org/chessground/blob/master/src/api.ts"
click node_wrapper "https://github.com/lichess-org/chessground/blob/master/src/wrap.ts"
click node_events "https://github.com/lichess-org/chessground/blob/master/src/events.ts"
click node_drag "https://github.com/lichess-org/chessground/blob/master/src/drag.ts"
click node_drop "https://github.com/lichess-org/chessground/blob/master/src/drop.ts"
click node_board "https://github.com/lichess-org/chessground/blob/master/src/board.ts"
click node_premove "https://github.com/lichess-org/chessground/blob/master/src/premove.ts"
click node_drawing "https://github.com/lichess-org/chessground/blob/master/src/draw.ts"
click node_sync "https://github.com/lichess-org/chessground/blob/master/src/sync.ts"
click node_svg "https://github.com/lichess-org/chessground/blob/master/src/svg.ts"
click node_auto "https://github.com/lichess-org/chessground/blob/master/src/autoPieces.ts"
click node_renderer "https://github.com/lichess-org/chessground/blob/master/src/render.ts"
click node_animation "https://github.com/lichess-org/chessground/blob/master/src/anim.ts"
click node_styles "https://github.com/lichess-org/chessground/tree/master/assets"
click node_state "https://github.com/lichess-org/chessground/blob/master/src/state.ts"
click node_config "https://github.com/lichess-org/chessground/blob/master/src/config.ts"
click node_fen "https://github.com/lichess-org/chessground/blob/master/src/fen.ts"
click node_glyph "https://github.com/lichess-org/chessground/blob/master/src/glyph.ts"
click node_types "https://github.com/lichess-org/chessground/blob/master/src/types.ts"

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_bootstrap,node_api,node_wrapper,node_user toneBlue
class node_events,node_drag,node_drop,node_board,node_premove,node_drawing toneAmber
class node_sync,node_svg,node_auto,node_renderer,node_animation,node_styles toneMint
class node_state,node_config,node_fen,node_glyph,node_types toneRose
```

## Components

### Board setup

- [Board factory](https://github.com/lichess-org/chessground/blob/master/src/chessground.ts): `src/chessground.ts`
- [Board API](https://github.com/lichess-org/chessground/blob/master/src/api.ts): `src/api.ts`
- [DOM wrapper](https://github.com/lichess-org/chessground/blob/master/src/wrap.ts): `src/wrap.ts`

### Board interaction

- [Input events](https://github.com/lichess-org/chessground/blob/master/src/events.ts): `src/events.ts`
- [Drag handling](https://github.com/lichess-org/chessground/blob/master/src/drag.ts): `src/drag.ts`
- [Drop handling](https://github.com/lichess-org/chessground/blob/master/src/drop.ts): `src/drop.ts`
- [Board operations](https://github.com/lichess-org/chessground/blob/master/src/board.ts): `src/board.ts`
- [Premoves](https://github.com/lichess-org/chessground/blob/master/src/premove.ts): `src/premove.ts`
- [Shape drawing](https://github.com/lichess-org/chessground/blob/master/src/draw.ts): `src/draw.ts`

### Rendering and display

- [Shape synchronization](https://github.com/lichess-org/chessground/blob/master/src/sync.ts): `src/sync.ts`
- [SVG shapes](https://github.com/lichess-org/chessground/blob/master/src/svg.ts): `src/svg.ts`
- [Auto pieces](https://github.com/lichess-org/chessground/blob/master/src/autoPieces.ts): `src/autoPieces.ts`
- [DOM renderer](https://github.com/lichess-org/chessground/blob/master/src/render.ts): `src/render.ts`
- [Piece animation](https://github.com/lichess-org/chessground/blob/master/src/anim.ts): `src/anim.ts`
- [Board and piece styles](https://github.com/lichess-org/chessground/tree/master/assets): `assets`

### Position and state

- [Board state](https://github.com/lichess-org/chessground/blob/master/src/state.ts): `src/state.ts`
- [Configuration](https://github.com/lichess-org/chessground/blob/master/src/config.ts): `src/config.ts`
- [FEN conversion](https://github.com/lichess-org/chessground/blob/master/src/fen.ts): `src/fen.ts`
- [Piece glyphs](https://github.com/lichess-org/chessground/blob/master/src/glyph.ts): `src/glyph.ts`
- [Shared types](https://github.com/lichess-org/chessground/blob/master/src/types.ts): `src/types.ts`

### Other components

- **Application user**

## Connections

- Application user → Board factory: creates board (evidence: `README.md`)
- Board factory → Board API: creates API (evidence: `src/chessground.ts`)
- Board factory → Input events: binds input (evidence: `src/chessground.ts`)
- Board factory → DOM renderer: sets rendering (evidence: `src/chessground.ts`)
- Board factory → DOM wrapper: wraps board (evidence: `src/chessground.ts`)
- Board factory → Board state: creates state (evidence: `src/chessground.ts`)
- Board API → Configuration: configures (evidence: `src/api.ts`)
- Board API → Board operations: mutates position (evidence: `src/api.ts`)
- Board API → FEN conversion: exports FEN (evidence: `src/api.ts`)
- Board API → Piece animation: animates changes (evidence: `src/api.ts`)
- Board API → Board state: exposes state (evidence: `src/api.ts`)
- Input events → Drag handling: dispatches drag (evidence: `src/events.ts`)
- Input events → Shape drawing: dispatches drawing (evidence: `src/events.ts`)
- Input events → Drop handling: dispatches drop (evidence: `src/events.ts`)
- Drag handling → Board operations: uses board ops (evidence: `src/drag.ts`)
- Drop handling → Board operations: uses board ops (evidence: `src/drop.ts`)
- Board operations → Premoves: computes premoves (evidence: `src/board.ts`)
- Shape drawing → Board operations: maps pointer (evidence: `src/draw.ts`)
- Shape synchronization → Shape drawing: reads shapes (evidence: `src/sync.ts`)
- SVG shapes → Shape drawing: renders shapes (evidence: `src/svg.ts`)
- Auto pieces → Board operations: reads position (evidence: `src/autoPieces.ts`)
- Auto pieces → Shape drawing: uses auto shapes (evidence: `src/autoPieces.ts`)
- Auto pieces → Shape synchronization: synchronizes (evidence: `src/autoPieces.ts`)
- DOM renderer → Piece animation: reads animation (evidence: `src/render.ts`)
- DOM renderer → Board operations: uses orientation (evidence: `src/render.ts`)
- DOM renderer → Board state: renders state (evidence: `src/render.ts`)
- DOM wrapper → Board state: uses state (evidence: `src/wrap.ts`)
- DOM wrapper → SVG shapes: manages SVG (evidence: `src/wrap.ts`)
- Board state → FEN conversion: loads position (evidence: `src/state.ts`)
- Configuration → Board state: configures state (evidence: `src/config.ts`)
- Application user → Board and piece styles: selects styles (evidence: `README.md`)
