Projects › Advanced
Collaborative Code Editor
A Google-Docs-style code editor where several people edit the same file live, see each other's cursors and run the code.
Level: Advanced · Time: 2–3 weeks · Tech stack: React, Monaco, WebSockets, Yjs (CRDT), Node.js
Features to build
- Rooms with a share link
- Live editing with conflict-free merging
- Coloured cursors and names of collaborators
- Language switch and "Run" button
- Chat panel and room history
What you will learn
- CRDTs and real-time sync
- WebSocket servers
- Presence
- Integrating an editor (Monaco)
Step-by-step guide
1. Why not just send the text?
If two people type at once, "last write wins" loses someone's changes. CRDTs (like Yjs) merge edits so everyone ends up with the same text.
2. Client
const doc = new Y.Doc();
const provider = new WebsocketProvider(WS_URL, roomId, doc);
const ytext = doc.getText('code');
new MonacoBinding(ytext, editor.getModel(), new Set([editor]), provider.awareness);
provider.awareness.setLocalStateField('user', { name, color });
y-monaco binds the shared text to Monaco; awareness carries cursors and names.
3. Server
Run y-websocket's server (or your own with ws), and persist each room's document in MongoDB or LevelDB so it survives restarts.
4. Rooms and permissions
POST /api/rooms creates a room id; optionally a password or "view only" link.
5. Running code
Send the current code to a sandboxed runner (Judge0, Wandbox or your own Docker-based runner). Never run user code directly on your server.
6. Chat and presence
A small chat panel over the same WebSocket; show who is online from awareness states.
Level it up
- Voice/video with WebRTC
- Interview mode with a timer and problem statement
- Replay the session keystroke by keystroke
On your resume
- Built a real-time collaborative code editor using Yjs CRDTs over WebSockets with Monaco, live cursors, persistent rooms and sandboxed code execution.