Skip to content

AI-native design editor. Open-source Figma alternative.

Update AGENTS.md and REFACTOR.md with editor architecture docs

Danila Poyarkov6379217692ea
diff --git a/AGENTS.md b/AGENTS.md
index 8a05da32b..0658d3c9a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -34,9 +34,35 @@ The root app (`src/`) is the Tauri/Vite desktop editor. Its `src/engine/` files
| `@open-pencil/core/color` | parseColor, colorToHex, etc. | — |
| `@open-pencil/core/render-image` | renderNodesToImage | — |
| `@open-pencil/core/profiler` | render profiling | — |
+| `@open-pencil/core/editor` | createEditor, Editor, EditorState | — |
Runtime `canvaskit-wasm` import exists only in `canvaskit.ts` — all other files use `import type`. CanvasKit instance is passed as a parameter everywhere.
+### Editor architecture
+
+`packages/core/src/editor/` is the framework-agnostic editor core — 13 modules sharing an `EditorContext` interface:
+
+| Module | What |
+|---|---|
+| `types.ts` | EditorState, EditorOptions, Tool, EditorToolDef, EditorContext |
+| `create.ts` | `createEditor()` assembler — wires context + all modules |
+| `viewport.ts` | screenToCanvas, applyZoom, pan, zoomToFit/100/Selection |
+| `selection.ts` | select, clearSelection, marquee, snap, hover, entered container |
+| `pages.ts` | switchPage, addPage, deletePage, renamePage |
+| `shapes.ts` | createShape, pen tool, adoptNodesIntoSection |
+| `structure.ts` | group, ungroup, wrapInAutoLayout, reorder, reparent, z-order |
+| `components.ts` | component/instance/detach/componentSet |
+| `clipboard.ts` | duplicate, copy, paste, delete, storeImage |
+| `undo.ts` | commitMove/Resize/Rotation, snapshot/restore |
+| `text.ts` | startTextEditing, commitTextEdit |
+| `nodes.ts` | updateNode, updateNodeWithUndo, setLayoutMode |
+
+Each module exports a factory: `createXxxActions(ctx: EditorContext) => { ... }`.
+`create.ts` assembles context + all modules, spreads into a flat return object.
+`Editor` type = `ReturnType<typeof createEditor>`.
+
+The app store (`src/stores/editor.ts`) is a thin Vue wrapper: creates `shallowReactive` state, calls `createEditor()`, adds Vue-specific concerns (computed refs, file I/O, autosave, export, image placement, mobile clipboard).
+
## Commands
- `bun run check` — type-aware lint + typecheck via oxlint + tsgo (run before committing)
diff --git a/REFACTOR.md b/REFACTOR.md
index 229238044..758140134 100644
--- a/REFACTOR.md
+++ b/REFACTOR.md
@@ -8,9 +8,9 @@ Comprehensive audit of vibe-coding leftovers and structural debt.
One closure captures ~30 mutable `let` variables and exposes ~80 methods covering: file I/O, undo, pen tool, layout, selection, export, import, clipboard, images, paging, zooming, autosave, file watching, component ops, text editing.
-**Refactoring:** Extract `createEditor()` to `packages/core/src/editor/` folder with domain modules sharing an `EditorContext` interface. App store becomes a thin Vue wrapper. See "Editor Folder Split" section below.
+**Refactoring:** Extract `createEditor()` to `packages/core/src/editor/` folder with domain modules sharing an `EditorContext` interface. App store becomes a thin Vue wrapper.
-**Status:** 🔧 In progress
+**Status:** ✅ Done — 13 modules, largest 394 lines. App store: 747 lines.
### 2. `src/composables/use-canvas-input.ts` — 1,501 lines, the Input Monolith