← Back to Course

Project 08: Collaborative Document Editor

Phase 2: Intermediate Complexity
Why This Project?

Collaborative editing is one of the hardest problems in web development. Think about Google Docs - multiple people typing at the same time, and everyone sees changes instantly. This is advanced but valuable knowledge.

You'll learn operational transformation or CRDTs, which are algorithms that handle conflicts when two people edit the same text at the same time. These concepts are used in many collaboration tools.

This project teaches you how to handle complex state synchronization. Version history, conflict resolution, and autosave are all challenging features that will push your skills to the next level.

Why This Project?

Collaborative editing is complex but powerful. Think Google Docs, Notion, or Figma - multiple people editing the same thing at the same time. This is advanced but impressive when you can build it.

This project teaches conflict resolution. When two people type at the same time, the system needs to merge their changes without losing data. This is called operational transformation or CRDTs.

You'll learn about version history, which lets users undo changes or see what changed over time. These skills apply to any collaborative software, not just document editors.

Overview

Create a collaborative document editor similar to Google Docs where multiple users can edit the same document simultaneously. This project introduces operational transformation, conflict resolution, version history, and complex state synchronization across multiple clients.

Learning Objectives

Implement real-time collaborative editing

Handle conflict resolution when multiple users edit simultaneously

Build version history and revision tracking

Create autosave functionality

Manage cursor positions across clients

Implement operational transformation or CRDTs

Core Requirements

Rich text editor with formatting (bold, italic, underline, headings)

Real-time synchronization using WebSockets

Show active users editing the document

Display cursor positions of other users

Autosave every 30 seconds

Version history showing all document revisions

Ability to restore previous versions

Conflict resolution for simultaneous edits

Document sharing with view/edit permissions

Offline mode with sync when reconnected

Data Models

Document: id, title, content (JSON or plain text), ownerId, createdAt, updatedAt

Version: id, documentId, content, author, timestamp, changeDescription

Permission: documentId, userId, role (owner/editor/viewer)

ActiveUser: documentId, userId, cursorPosition, lastSeen

WebSocket Events

join_document - User opens document for editing

leave_document - User closes document

text_change - User makes an edit (send operation)

cursor_move - User moves cursor

save_document - Manual save triggered

user_joined - Notify others when new user joins

user_left - Notify others when user leaves

API Endpoints

POST /api/documents - Create new document

GET /api/documents - Get user's documents

GET /api/documents/:id - Get document content

PUT /api/documents/:id - Update document (autosave)

DELETE /api/documents/:id - Delete document

GET /api/documents/:id/versions - Get version history

POST /api/documents/:id/restore - Restore specific version

POST /api/documents/:id/share - Share with user

GET /api/documents/:id/collaborators - Get all collaborators

Frontend Features

Document list page showing all accessible documents

Rich text editor using Draft.js, Slate, or Quill

Formatting toolbar (bold, italic, headings, lists)

Active users indicator with avatars

Colored cursors showing where others are typing

Save status indicator (saved, saving, unsaved changes)

Version history sidebar with timestamps and authors

Share modal with email input and permission selector

Conflict notification when simultaneous edits occur

Technical Challenges

Implement operational transformation to handle concurrent edits

Broadcast changes to all connected clients efficiently

Track cursor positions and transform them with content changes

Implement debounced autosave to reduce database writes

Store document state in memory for active editing sessions

Handle network disconnections gracefully

Queue operations while offline and replay on reconnect

Create snapshots periodically to prevent long replay chains

Conflict Resolution Strategy

Each edit operation includes position and content

Transform incoming operations based on pending operations

Use vector clocks or timestamps to order operations

Last write wins for same position (with user notification)

Maintain operation history for debugging conflicts

Bonus Features

Add comments and suggestions mode

Implement text highlighting and annotations

Add document templates

Create presentation mode for documents

Implement document export to PDF or Markdown

Add table support in editor

Implement image insertion and management

Add change tracking with accept/reject workflow

Helpful Resources

Operational Transformation: Search for "operational transformation explained" to understand the concept.

Yjs: Yjs library makes collaborative editing easier. Read their docs and examples.

CRDTs: Look up "CRDT explained" for an alternative to operational transformation.

Rich Text Editors: Check out Slate.js, Draft.js, or Quill documentation.

WebSocket State: Learn patterns for managing WebSocket connections in React.

Conflict Resolution: Read about "concurrent editing conflicts" and resolution strategies.

Helpful Resources

Yjs: Yjs library documentation. It handles operational transformation for you.

Slate: Slate editor framework docs. It's a customizable rich text editor for React.

Quill: Quill rich text editor. Simpler than Slate, good for getting started.

Operational Transformation: Search for "operational transformation explained" to understand the concept.

WebRTC or WebSockets: For real-time sync. You already learned WebSockets in project 2.

Autosave Pattern: Search for "debounced autosave" to learn how to save changes efficiently.

Success Criteria

Multiple users can edit simultaneously without data loss

Changes appear in real-time for all users

Cursor positions update correctly

Autosave works reliably every 30 seconds

Version history accurately tracks all changes

Restoring previous versions works correctly

Offline mode queues changes and syncs on reconnect

No conflicts result in lost edits

Learning Resources

Study operational transformation algorithms

Research CRDT (Conflict-free Replicated Data Types)

Explore Yjs or Automerge libraries

Learn about rich text editor libraries (Slate, Draft.js, Quill)

Look into ShareDB for real-time collaboration

Hint: Start simple - build a basic text editor that saves to a database, then add real-time sync, then add conflict resolution. Trying to build everything at once will be overwhelming.

Consider using an existing library like Yjs for operational transformation instead of implementing it from scratch. This is a complex algorithm and using a battle-tested library will save you days of debugging.

Submit Your Project

Once you've completed this project, submit your GitHub repository link below: