Operational Transformation Algorithms
EngineeringA shared data layer built on Yjs CRDTs (Conflict-free Replicated Data Types) that powers both a collaborative text editor and a mind-map visualization interface from the same underlying document state. The project required designing reversible projection algorithms that maintain real-time bidirectional synchronization between linear text (Y.Text) and hierarchical graph (Y.Map/Y.Array) representations.
The Core Problem
The architecture addresses one of the hardest problems in collaborative software: maintaining semantic consistency between two fundamentally different data representations that are being concurrently edited by multiple users. When a user edits text in the document view, the changes must be immediately and correctly reflected in the mind-map visualization, and vice versa. A node rearrangement in the mind-map must correctly restructure the text document.
Dual Projection Model
Our solution introduces a novel "dual projection" CRDT model where text and mind-map are treated not as independent representations but as two projections of the same semantic structure. A canonical internal model captures both the linear ordering of text and the hierarchical nesting of concepts. Each user action, whether typing text or dragging a mind-map node, is first expressed as an operation on this canonical model, then projected to both views through commutative projection functions that guarantee convergence under concurrent edits.
The implementation includes:
- Stable ID anchoring for reliable cross-reference between representations
- Real-time conflict resolution with visual indicators for concurrent edits
- Comprehensive undo/redo that works correctly across both views and multiple users using selective operation inversion
Offline-First Architecture
The system supports fully offline-first operation with seamless merges when clients reconnect, ensuring consistency, intent preservation, and low-latency synchronization across all connected clients. A 16 ms operation coalescing window batches rapid keystrokes into single CRDT operations, reducing both network traffic and merge computation. Lazy materialization computes mind-map nodes only for visible regions, while incremental projection reduces update latency from O(n) to O(log n) for most operations.
An awareness protocol extension shows real-time cursor positions, selections, and activity indicators across both views with sub-50 ms latency.