ArchitectureModule Roles Blueprint

Module Roles Blueprint

The src/ codebase divides responsibilities among specialized modules. Each module owns a clear, single responsibility.

Module Map

src/
β”œβ”€β”€ types.ts        β†’ Canonical Types & Primitives
β”œβ”€β”€ matrix.ts       β†’ Stateless Coordinate Math
β”œβ”€β”€ shadow-mount.ts β†’ Shadow DOM Director
β”œβ”€β”€ tree.ts         β†’ Hierarchical Tree Model
β”œβ”€β”€ layout.ts       β†’ CSS Introspective Analyzer
β”œβ”€β”€ renderer.ts     β†’ 2D Canvas Painter
β”œβ”€β”€ drop-zone.ts    β†’ DnD Slot Detector
β”œβ”€β”€ workspace.ts    β†’ Central Orchestrator
└── index.ts        β†’ Public API Barrel Exports

Module Details

types.ts β€” Canonical Types & Primitives

Contains structural definitions for vectors (Vec2), rectangles (Rect), transform matrices (ViewportMatrix), operation payloads (Operation), and drag state machine states. This is the single source of truth for all shared data models.

matrix.ts β€” Stateless Coordinate Math

Translates vectors and rects between Screen space (DOM client pixels) and Canvas space (scale-and-translate coordinates). Handles hit testing, pan accumulation, and zoom anchoring to prevent cursor drift. All functions are pure and stateless.

shadow-mount.ts β€” Shadow DOM Director

Injects and destroys wrapper elements, mounts styles, suppresses resize observer feedback loops, and isolates CSS. Houses the Flat String Bridge (extractHTML) to export clean, SDK-free HTML fragments. The largest module, managing the entire DOM lifecycle.

tree.ts β€” Hierarchical Tree Model

Manages the logical NodeTree structure (parentId, childIds, depth). Coordinates sibling sequences and performs ancestor-walk cycle detection to prevent circular references during reparenting.

layout.ts β€” CSS Introspective Analyzer

Evaluates getComputedStyle() values of content elements. Determines container display modes (flex, grid, block), parses direction axes (row vs. column), checks wrapping bounds, grid configurations, and gaps.

renderer.ts β€” 2D Canvas Painter

Draws selection frames, resize anchors, spacing adjusters, alignment snap guidelines, grid tracks, layout status badges, and marquee drag borders on the HTML5 Canvas overlay.

drop-zone.ts β€” DnD Slot Detector

Calculates placement indices inside Flex/Grid layout tracks and Block flows based on current pointer locations, returning insertion coordinates for drag-and-drop operations.

workspace.ts β€” Central Orchestrator

Integrates all subsystems, binds event handlers (pointer, key, wheel, window), runs the main state machine, and triggers throttled repaints. This is the public entry point for consumer integrations.

index.ts β€” Public API Barrel Exports

Re-exports all public types, classes, and functions from the other modules. Consumers import from this single entry point.


Dependency Flow

workspace.ts (orchestrator)
β”œβ”€β”€ shadow-mount.ts (DOM layer)
β”‚   └── types.ts
β”œβ”€β”€ renderer.ts (canvas layer)
β”‚   └── types.ts
β”œβ”€β”€ tree.ts (data model)
β”‚   └── types.ts
β”œβ”€β”€ layout.ts (CSS introspection)
β”‚   └── types.ts
β”œβ”€β”€ drop-zone.ts (DnD logic)
β”‚   β”œβ”€β”€ layout.ts
β”‚   └── types.ts
└── matrix.ts (coordinate math)
    └── types.ts

All modules depend on types.ts for shared data structures. No module directly depends on workspace.ts β€” the orchestrator imports and coordinates everything else.