- Infinite canvas (pan + zoom)
- Add shapes (rectangle, text, lines)
- Drag, resize, and move elements
- Multi-select and grouping
- Real-time collaboration
- How do you manage canvas coordinates?
- How do you handle zoom and pan?
- How do you store elements efficiently?
- How do you sync changes across users?
- How do you optimize rendering?
- UI Layer
- Data Model
- Coordinate System
- Interaction System
- Rendering Strategy
- Real-time Sync
- Performance
- Edge Cases
- Canvas (main drawing area)
- Toolbar (shapes, tools)
- Selection box
- Layers panel (optional)
- Drag elements
- Resize with handles
- Select multiple elements
- Pan canvas
- Zoom in/out

{
id: "1",
type: "rectangle",
x: 100,
y: 200,
width: 150,
height: 100,
rotation: 0
}- elements map (id → element)
- order array (z-index)
- Canvas coordinates (logical)
- Screen coordinates (viewport)
screenX = canvasX * zoom + offsetX
screenY = canvasY * zoom + offsetY
- Track mouse down
- Calculate delta
- Update position
- Use corner handles
- Update width/height
- Draw selection box
- Detect intersecting elements

- Change offsetX, offsetY
- Scale canvas
- Zoom around cursor position (not center)
- Simple
- Limited performance
- Better performance
- Manual rendering
- For large scale
- Mention Canvas for performance
- User moves element
- Send update (operation)
- Server broadcasts
- Other clients update
- Last write wins (simple)
- OT/CRDT (advanced)
- elements
- selectedElements
- zoomLevel
- offset (pan)
- interaction state (dragging/resizing)
- Only re-render changed elements
- Use requestAnimationFrame
- Throttle mouse events
- Virtualize offscreen elements
- Use spatial indexing (quad tree)
- Very large canvas
- Thousands of elements
- Zoom precision issues
- Multi-user conflicts
- Undo/Redo
- User adds shape
- Element stored in state
- Render on canvas
- User interacts
- Update state
- Sync with server
- Spatial thinking
- UI interaction design
- Performance awareness
- Real-time sync
- Data modeling















