Overview
Ganimede uses Yjs, a high-performance CRDT (Conflict-free Replicated Data Type) library, to enable real-time collaborative editing of notebooks. Multiple users can work on the same notebook simultaneously without conflicts.Architecture
Ganimede’s collaboration system is built on a robust WebSocket-based architecture:WebSocket Server
The collaboration server is implemented usingypy-websocket and runs on port 1234:
api/ganimede/main.py:38-43
WebSocket Provider
Clients connect to the collaboration room via WebSocket:api/ganimede/main.py:58-61
Shared Data Structures
The Yjs document synchronizes multiple data structures across all connected clients:Notebook Elements
- Cells Array (
ydoc.get_array("cells")): The list of cell IDs in the notebook - Cell Maps: Each cell is stored as a shared map with properties:
id: Unique cell identifiertype: Cell type (code, markdown)source: Cell content asY.YText(collaborative text editing)execution_count: Number of times the cell has been executedoutputs: Cell execution outputs asY.YArraytop,left,width,height: Canvas positioningcollapsed: Collapse statestate: Execution state (idle, running, queued, done)
Graph Structures
- np_graph (
ydoc.get_map("np_graph")): Next-previous directed graph for cell flow - pc_graph (
ydoc.get_map("pc_graph")): Parent-children directed graph for hierarchical structure
Other Shared State
- run_queue (
ydoc.get_array("run_queue")): Queue of cells waiting to execute - nb_path (
ydoc.get_text("nb_path")): Path to the notebook file
Frontend Integration
The frontend uses Yjs bindings for real-time synchronization:Dependencies
Fromui/package.json:
Editor Bindings
- y-monaco: Collaborative editing for code cells (Monaco editor)
- y-prosemirror: Collaborative editing for markdown cells
How It Works
- Document Initialization: When a notebook is opened, the Yjs document is initialized with the notebook’s content
-
WebSocket Connection: The client connects to the collaboration server at
ws://localhost:1234/g-y-room - Synchronization: Yjs automatically synchronizes all changes between connected clients using efficient delta updates
- Conflict Resolution: CRDTs ensure that concurrent edits are merged without conflicts
- Persistent State: Changes are saved to the notebook file via the checkpoint system
Benefits of CRDT-Based Collaboration
No Conflicts
CRDTs mathematically guarantee that all users see the same final state
Offline Support
Continue working offline and sync when reconnected
Low Latency
Changes appear instantly without server round-trips
Scalable
Yjs efficiently handles large documents and many users
Current Status
From the Ganimede roadmap:- Infrastructure: ✅ Implemented (Yjs, WebSocket server, data structures)
- Feature: ⏳ In development (RTC Demo from Sep 23)
The collaboration infrastructure is fully implemented in the codebase. The feature is being refined for production readiness.
Try It Out (When Available)
Once collaboration is enabled, multiple users will be able to:- Edit cells simultaneously with cursor awareness
- See real-time updates to cell outputs
- Move and resize cells on the canvas together
- Queue and run cells collaboratively
- Work on different parts of the notebook without conflicts