# khdoex/flat-planner architecture

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

- Interactive diagram: https://gitdiagram.com/khdoex/flat-planner
- Repository: https://github.com/khdoex/flat-planner

## Overview

flat-planner turns evidence-tagged flat measurements into a geometric model, then supports room-by-room furniture planning through a live-synced browser editor and agent-assisted workflows. Users can survey missing measurements, check layouts against spatial rules, optimise arrangements, and render plan images. The graph includes the documented agent workflow and CLI capabilities; some subsystem links rely on README statements because their implementation was not sampled.

Main entry points: [`src/main.ts`](https://github.com/khdoex/flat-planner/blob/main/src/main.ts) (Planner browser), [`bin/cli.ts`](https://github.com/khdoex/flat-planner/blob/main/bin/cli.ts) (CLI entry), [`scripts/optimise.ts`](https://github.com/khdoex/flat-planner/blob/main/scripts/optimise.ts) (Optimise command), [`src/rules/rules.ts`](https://github.com/khdoex/flat-planner/blob/main/src/rules/rules.ts) (Layout rule checks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Agent workflow"]
  node_skills["Agent skills<br/>[skills]"]
end

subgraph group_commands["Planner commands"]
  node_cli["CLI entry<br/>[cli.ts]"]
  node_survey["Measurement survey<br/>[survey.ts]"]
  node_snapshot["Plan snapshots<br/>[snap.ts]"]
  node_checkcmd["Check command<br/>[check.ts]"]
  node_optcmd["Optimise command<br/>[optimise.ts]"]
  node_snapshot_output["Rendered images"]
end

subgraph group_model["Flat model"]
  node_flatfile["Flat measurements"]
  node_layoutfiles["Furniture layouts"]
  node_geometry["Flat geometry<br/>[flat.ts]"]
  node_polygons["Polygon operations<br/>[poly.ts]"]
end

subgraph group_editor["Browser editor"]
  node_browser["Planner browser<br/>[main.ts]"]
  node_interaction["Drag controls<br/>[drag.ts]"]
  node_panel["Editing panels<br/>[panel.ts]"]
  node_scene["3D scene<br/>[scene.ts]"]
  node_persistence["File sync<br/>[sync.ts]"]
  node_file_server["Data file server<br/>[plugin.ts]"]
end

subgraph group_analysis["Layout analysis"]
  node_rules["Layout rule checks<br/>[rules.ts]"]
  node_optimiser["Arrangement optimiser<br/>[optimise.ts]"]
end

node_resident(("Resident / agent"))

node_resident -->|"uses workflow"| node_skills
node_skills -->|"builds model"| node_flatfile
node_skills -->|"edits layouts"| node_layoutfiles
node_resident -->|"runs commands"| node_cli
node_cli -->|"dispatches survey"| node_survey
node_cli -->|"dispatches check"| node_checkcmd
node_cli -->|"dispatches optimise"| node_optcmd
node_cli -->|"dispatches snap"| node_snapshot
node_survey -->|"reads measurements"| node_flatfile
node_checkcmd -->|"loads flat"| node_flatfile
node_checkcmd -->|"checks layout"| node_rules
node_optcmd -->|"searches arrangements"| node_optimiser
node_optcmd -->|"loads flat"| node_flatfile
node_optcmd -->|"writes candidates"| node_layoutfiles
node_snapshot -->|"renders images"| node_snapshot_output
node_browser -->|"resolves flat"| node_geometry
node_geometry -.->|"resolves measurements"| node_flatfile
node_browser -->|"renders plan"| node_scene
node_browser -->|"attaches controls"| node_interaction
node_interaction -->|"picks objects"| node_scene
node_browser -->|"renders panels"| node_panel
node_browser -->|"draws rule results"| node_rules
node_browser -->|"reads and writes"| node_persistence
node_persistence -.->|"syncs files"| node_file_server
node_file_server -->|"serves JSON"| node_flatfile
node_file_server -->|"serves layouts"| node_layoutfiles
node_rules -->|"uses footprints"| node_polygons
node_optimiser -->|"scores layouts"| node_rules
node_optimiser -->|"tests placement"| node_polygons

click node_skills "https://github.com/khdoex/flat-planner/tree/main/.claude/skills"
click node_cli "https://github.com/khdoex/flat-planner/blob/main/bin/cli.ts"
click node_survey "https://github.com/khdoex/flat-planner/blob/main/scripts/survey.ts"
click node_snapshot "https://github.com/khdoex/flat-planner/blob/main/scripts/snap.ts"
click node_geometry "https://github.com/khdoex/flat-planner/blob/main/src/geometry/flat.ts"
click node_polygons "https://github.com/khdoex/flat-planner/blob/main/src/geometry/poly.ts"
click node_browser "https://github.com/khdoex/flat-planner/blob/main/src/main.ts"
click node_interaction "https://github.com/khdoex/flat-planner/blob/main/src/interaction/drag.ts"
click node_panel "https://github.com/khdoex/flat-planner/blob/main/src/ui/panel.ts"
click node_scene "https://github.com/khdoex/flat-planner/blob/main/src/render/scene.ts"
click node_persistence "https://github.com/khdoex/flat-planner/blob/main/src/persistence/sync.ts"
click node_file_server "https://github.com/khdoex/flat-planner/blob/main/server/plugin.ts"
click node_rules "https://github.com/khdoex/flat-planner/blob/main/src/rules/rules.ts"
click node_optimiser "https://github.com/khdoex/flat-planner/blob/main/src/optimise/optimise.ts"
click node_checkcmd "https://github.com/khdoex/flat-planner/blob/main/scripts/check.ts"
click node_optcmd "https://github.com/khdoex/flat-planner/blob/main/scripts/optimise.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_skills toneBlue
class node_cli,node_survey,node_snapshot,node_checkcmd,node_optcmd,node_snapshot_output toneAmber
class node_flatfile,node_layoutfiles,node_geometry,node_polygons toneMint
class node_browser,node_interaction,node_panel,node_scene,node_persistence,node_file_server toneRose
class node_rules,node_optimiser,node_resident toneIndigo
```

## Components

### Agent workflow

- [Agent skills](https://github.com/khdoex/flat-planner/tree/main/.claude/skills): `.claude/skills`

### Planner commands

- [CLI entry](https://github.com/khdoex/flat-planner/blob/main/bin/cli.ts): `bin/cli.ts`
- [Measurement survey](https://github.com/khdoex/flat-planner/blob/main/scripts/survey.ts): `scripts/survey.ts`
- [Plan snapshots](https://github.com/khdoex/flat-planner/blob/main/scripts/snap.ts): `scripts/snap.ts`
- [Check command](https://github.com/khdoex/flat-planner/blob/main/scripts/check.ts): `scripts/check.ts`
- [Optimise command](https://github.com/khdoex/flat-planner/blob/main/scripts/optimise.ts): `scripts/optimise.ts`
- **Rendered images**

### Flat model

- **Flat measurements**
- **Furniture layouts**
- [Flat geometry](https://github.com/khdoex/flat-planner/blob/main/src/geometry/flat.ts): `src/geometry/flat.ts`
- [Polygon operations](https://github.com/khdoex/flat-planner/blob/main/src/geometry/poly.ts): `src/geometry/poly.ts`

### Browser editor

- [Planner browser](https://github.com/khdoex/flat-planner/blob/main/src/main.ts): `src/main.ts`
- [Drag controls](https://github.com/khdoex/flat-planner/blob/main/src/interaction/drag.ts): `src/interaction/drag.ts`
- [Editing panels](https://github.com/khdoex/flat-planner/blob/main/src/ui/panel.ts): `src/ui/panel.ts`
- [3D scene](https://github.com/khdoex/flat-planner/blob/main/src/render/scene.ts): `src/render/scene.ts`
- [File sync](https://github.com/khdoex/flat-planner/blob/main/src/persistence/sync.ts): `src/persistence/sync.ts`
- [Data file server](https://github.com/khdoex/flat-planner/blob/main/server/plugin.ts): `server/plugin.ts`

### Layout analysis

- [Layout rule checks](https://github.com/khdoex/flat-planner/blob/main/src/rules/rules.ts): `src/rules/rules.ts`
- [Arrangement optimiser](https://github.com/khdoex/flat-planner/blob/main/src/optimise/optimise.ts): `src/optimise/optimise.ts`

### Other components

- **Resident / agent**

## Connections

- Resident / agent → Agent skills: uses workflow (evidence: `README.md`)
- Agent skills → Flat measurements: builds model (evidence: `README.md`)
- Agent skills → Furniture layouts: edits layouts (evidence: `README.md`)
- Resident / agent → CLI entry: runs commands (evidence: `README.md`)
- CLI entry → Measurement survey: dispatches survey (evidence: `bin/cli.ts`)
- CLI entry → Check command: dispatches check (evidence: `bin/cli.ts`)
- CLI entry → Optimise command: dispatches optimise (evidence: `bin/cli.ts`)
- CLI entry → Plan snapshots: dispatches snap (evidence: `bin/cli.ts`)
- Measurement survey → Flat measurements: reads measurements (evidence: `scripts/survey.ts`)
- Check command → Flat measurements: loads flat (evidence: `scripts/check.ts`)
- Check command → Layout rule checks: checks layout (evidence: `scripts/check.ts`)
- Optimise command → Arrangement optimiser: searches arrangements (evidence: `scripts/optimise.ts`)
- Optimise command → Flat measurements: loads flat (evidence: `scripts/optimise.ts`)
- Optimise command → Furniture layouts: writes candidates (evidence: `README.md`)
- Plan snapshots → Rendered images: renders images (evidence: `README.md`)
- Planner browser → Flat geometry: resolves flat (evidence: `src/main.ts`)
- Flat geometry → Flat measurements: resolves measurements
- Planner browser → 3D scene: renders plan (evidence: `src/main.ts`)
- Planner browser → Drag controls: attaches controls (evidence: `src/main.ts`)
- Drag controls → 3D scene: picks objects (evidence: `src/interaction/drag.ts`)
- Planner browser → Editing panels: renders panels (evidence: `src/main.ts`)
- Planner browser → Layout rule checks: draws rule results (evidence: `src/main.ts`)
- Planner browser → File sync: reads and writes (evidence: `src/main.ts`)
- File sync → Data file server: syncs files
- Data file server → Flat measurements: serves JSON (evidence: `server/plugin.ts`)
- Data file server → Furniture layouts: serves layouts (evidence: `server/plugin.ts`)
- Layout rule checks → Polygon operations: uses footprints (evidence: `src/rules/rules.ts`)
- Arrangement optimiser → Layout rule checks: scores layouts (evidence: `src/optimise/optimise.ts`)
- Arrangement optimiser → Polygon operations: tests placement (evidence: `src/optimise/optimise.ts`)
