The tldraw SDK is built around reactive state management and a modular architecture that separates concerns while maintaining excellent performance. This page explains the core architectural patterns that power the SDK.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tldraw/tldraw/llms.txt
Use this file to discover all available pages before exploring further.
Core packages
The tldraw SDK is organized as a monorepo with specialized packages that work together:@tldraw/editor
The foundational infinite canvas editor engine with no UI, shapes, or tools included.- Reactive state management using
@tldraw/statesignals - Shape system via
ShapeUtilclasses - Tool system via
StateNodehierarchies - Bindings system for shape relationships
- No opinions about UI or default shapes
@tldraw/tldraw
The complete “batteries included” SDK that builds on@tldraw/editor.
- Full UI with toolbar, menus, and panels
- Default shape utilities (text, draw, geo, arrow, etc.)
- Complete tool set (select, hand, eraser, etc.)
- Responsive UI system with customizable components
@tldraw/store
A reactive client-side database for managing records. Features:- Document persistence with IndexedDB
- Reactive updates using signals from
@tldraw/state - Migration system for schema changes
- Automatic change tracking and history
@tldraw/state
The reactive signals library that powers all state management in tldraw.@tldraw/tlschema
Type definitions, validators, and migrations for shapes, bindings, and records. Provides:- Shape and binding type definitions
- Validation schemas using
@tldraw/validate - Migration sequences for schema evolution
- Shared data structures
Architectural patterns
Reactive state management
All editor state is reactive and observable using the signals pattern from@tldraw/state.
- Automatic dependency tracking prevents unnecessary re-renders
- Lazy evaluation improves performance
- Predictable update patterns
- Easy to test and debug
Shape system
Each shape type has aShapeUtil class that defines its behavior:
- Geometry: Hit testing, bounds calculation, collision detection
- Rendering: Component and indicator visualization
- Interactions: Resizing, rotating, editing behavior
- Serialization: Export to SVG, JSON, or other formats
Tools as state machines
Tools are implemented asStateNode hierarchies with event-driven behavior:
- Event handlers for pointer, keyboard, and tick events
- Child states for complex tools (e.g., SelectTool has Brushing, Translating, etc.)
- Automatic state transitions based on user input
- Clean separation of tool logic
Example: Complex tool with child states
Example: Complex tool with child states
Bindings system
Bindings create relationships between shapes (like arrows connected to shapes):- Automatic updates when connected shapes change
- Cleanup on shape deletion
- Type-safe binding definitions
- Support for one-to-many and many-to-many relationships
Data flow
The tldraw architecture follows a unidirectional data flow:- User input triggers tool event handlers
- Tools call editor methods to modify state
- Editor updates the store (shapes, bindings, etc.)
- Store changes propagate through signals
- Computed values update lazily when accessed
- React components re-render based on changed signals
- UI updates reflect the new state
Performance optimizations
The architecture includes several performance optimizations:Lazy evaluation
Computed signals only recalculate when accessed and dependencies have changed:Automatic culling
Shapes outside the viewport are automatically culled from rendering:Batched updates
Multiple changes within a single transaction are batched:Next steps
State management
Deep dive into reactive signals with @tldraw/state
Performance
Learn performance optimization techniques
Custom shapes
Build custom shape utilities
Custom tools
Create custom tool state machines