Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

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

What you will learn

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

On your resume

Learn on Codify