CoDraft is a real-time collaborative text editor built for shared writing. Multiple users can open the same document, type simultaneously, see each other's presence and cursors, and collaborate without overwriting each other's changes.
- Frontend: https://co-draft-eight.vercel.app/
- Backend: https://codraft-2k92.onrender.com/health
- GitHub: https://github.com/rajeevroy21/CoDraft
CoDraft focuses on making collaborative document editing feel truly real-time.
Users can:
- Create and open documents
- Edit the same document from multiple browser windows
- See collaborator presence indicators
- See colored collaborator cursors
- Use rich-text formatting
- Persist documents
- Browse revision history
- Restore previous document revisions
- Collaborate without manually resolving editing conflicts
Note: CoDraft is currently a shared-workspace demo. Anyone with a document URL can open and edit it. Authentication and access control are intentionally outside the current scope.
| Requirement | Implementation |
|---|---|
| Real-time synchronization | Yjs + Hocuspocus WebSocket |
| User presence | Yjs Awareness |
| Cursor tracking | Tiptap CollaborationCursor |
| Conflict resolution | Yjs CRDT |
| Text formatting | Tiptap |
| Document persistence | MongoDB |
| Revision history | MongoDB revision snapshots |
| Revision restore | One-click restore |
- WebSocket-based real-time communication
- CRDT-based collaborative editing
- Node.js backend
- React frontend
- MongoDB persistence
- React
- TypeScript
- Vite
- Tailwind CSS
- Tiptap
- Yjs
- Hocuspocus Provider
- Node.js
- Express
- TypeScript
- Hocuspocus
- Yjs
- MongoDB
- Mongoose
- Frontend: Vercel
- Backend: Render
- Database: MongoDB Atlas
CoDraft consists of two primary applications.
The React client provides:
- Landing page
- Document dashboard
- Collaborative editor
- Presence indicators
- Cursor sharing
- Rich-text formatting
- Revision history
The editor uses Tiptap for rich-text editing and connects to the collaboration server through Yjs + Hocuspocus.
The Node.js server provides:
- REST APIs for documents
- REST APIs for revisions
- Hocuspocus WebSocket server
- MongoDB persistence
- Revision snapshot management
- A user opens a document.
- The client connects to the Hocuspocus WebSocket server.
- Yjs creates and maintains the shared document state.
- Users make edits simultaneously.
- Yjs synchronizes changes between connected clients.
- CRDT operations merge concurrent changes without traditional last-write-wins conflicts.
- Hocuspocus manages the real-time collaboration connection.
- Document state is persisted to MongoDB.
- Revision snapshots are stored separately for history and restoration.
┌─────────────────────────────────────────────────────────────┐
│ Browser │
│ │
│ React + Tiptap + Yjs + HocuspocusProvider │
│ │
└─────────────────────────────┬───────────────────────────────┘
│
HTTPS / WebSocket
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Node.js Server │
│ Render Deployment │
│ │
│ HTTP → Express REST API │
│ - Documents │
│ - Revisions │
│ │
│ WS → Hocuspocus │
│ - Yjs synchronization │
│ - Presence / Awareness │
│ - Collaborative editing │
│ │
└─────────────────────────────┬───────────────────────────────┘
│
Mongoose
│
▼
┌─────────────────────────────────────────────────────────────┐
│ MongoDB Atlas │
│ │
│ documents: │
│ - title │
│ - yjsState │
│ - timestamps │
│ │
│ revisions: │
│ - documentId │
│ - yjsState │
│ - contentPreview │
│ - timestamps │
│ │
└─────────────────────────────────────────────────────────────┘
The HTTP API and WebSocket collaboration server run on the same backend service.
Regular HTTP requests are handled by Express, while WebSocket connections are handled by Hocuspocus.
Yjs represents the collaborative document as a binary CRDT state.
When a user opens a document:
Client
↓
Hocuspocus WebSocket
↓
Load document state
↓
Yjs CRDT
↓
Collaborative editing
↓
Persist state to MongoDB
Document state is persisted in MongoDB, while revision snapshots are maintained separately for revision history.
Collaborative editing becomes difficult when multiple users modify the same document simultaneously.
A traditional Last Writer Wins (LWW) approach can cause one user's changes to overwrite another user's changes.
Imagine two users editing the same sentence:
User A → "Hello world!"
User B → "Hello CoDraft!"
With a simple last-write-wins system, one update could replace the other.
This can lead to:
- Data loss
- Lost user intent
- Race conditions
- Poor collaborative UX
CoDraft uses Yjs, a CRDT implementation designed for collaborative applications.
Yjs allows concurrent updates to be merged into a consistent shared state without requiring users to manually resolve ordinary concurrent editing conflicts.
CoDraft/
├── client/
│ ├── src/
│ ├── public/
│ ├── package.json
│ ├── vercel.json
│ └── vite.config.ts
│
└── server/
├── src/
├── package.json
├── tsconfig.json
└── ...
| Layer | Technology |
|---|---|
| Editor | Tiptap |
| CRDT | Yjs |
| WebSocket | Hocuspocus |
| Frontend | React + Vite + TypeScript |
| Styling | Tailwind CSS |
| Backend | Node.js + Express |
| Database | MongoDB + Mongoose |
| Frontend Deployment | Vercel |
| Backend Deployment | Render |
- Node.js 20+
- npm
- MongoDB Atlas account or local MongoDB
git clone https://github.com/rajeevroy21/CoDraft.git
cd CoDraftcd server
npm installCreate:
server/.env
Add:
PORT=3001
MONGODB_URI=<your_mongodb_connection_string>
CLIENT_URL=http://localhost:5173
NODE_ENV=developmentRun the backend:
npm run devThe backend will run on:
http://localhost:3001
Open another terminal:
cd client
npm installCreate:
client/.env
Add:
VITE_API_URL=http://localhost:3001
VITE_WS_URL=ws://localhost:3001Run the frontend:
npm run devThe frontend will normally be available at:
http://localhost:5173
The production frontend uses:
VITE_API_URL=https://codraft-2k92.onrender.com
VITE_WS_URL=wss://codraft-2k92.onrender.comThe wss:// protocol is used because the production frontend is served over HTTPS.
The backend uses environment variables similar to:
MONGODB_URI=<your_mongodb_connection_string>
CLIENT_URL=https://co-draft-eight.vercel.app
NODE_ENV=productionRender provides the production PORT automatically.
The backend is deployed on Render.
Root Directory
server
Build Command
npm install --include=dev && npm run buildStart Command
npm startMONGODB_URI=<your_mongodb_connection_string>
CLIENT_URL=https://co-draft-eight.vercel.app
NODE_ENV=productionhttps://codraft-2k92.onrender.com
Health check:
https://codraft-2k92.onrender.com/health
The frontend is deployed using Vercel.
Root Directory
client
Framework
Vite
Build Command
npm run buildOutput Directory
dist
Install Command
npm installVITE_API_URL=https://codraft-2k92.onrender.com
VITE_WS_URL=wss://codraft-2k92.onrender.comhttps://co-draft-eight.vercel.app/
- Live Application: https://co-draft-eight.vercel.app/
- Backend Health: https://codraft-2k92.onrender.com/health
- GitHub Repository: https://github.com/rajeevroy21/CoDraft
Every document is currently accessible to anyone who has its URL.
There are currently:
- No user accounts
- No authentication
- No document ownership
- No access-control system
This is intentional for the current collaborative-editor implementation. The focus is on real-time synchronization, CRDT-based conflict resolution, persistence, and revision management.
- No authentication or authorization
- Anyone with a document URL can edit it
- Revision restore may require a page reload to fully reflect the restored state
- Render's free infrastructure may experience cold starts after inactivity
- Mobile editor layout is functional but the toolbar is compact on smaller screens
- ChatGPT
- Claude
Claude was used for architectural guidance and debugging. ChatGPT was used for development assistance, debugging, and implementation guidance.
All integration decisions, design choices, and final implementation were reviewed and adjusted manually.
| Criterion | Implementation |
|---|---|
| Real-time synchronization | Yjs + Hocuspocus WebSocket |
| Conflict resolution | Yjs CRDT |
| Presence indicators | Yjs Awareness |
| Cursor tracking | Tiptap CollaborationCursor |
| Rich-text formatting | Bold, italic, underline, headings, lists, code |
| Persistence | MongoDB + Yjs binary state |
| Revision history | Periodic revision snapshots |
| Revision restore | Revision panel + restore functionality |
| WebSocket communication | Hocuspocus WebSocket server |
| Backend | Node.js + Express |
| Frontend | React + Vite + TypeScript |
Released under the MIT License.
See LICENSE.