CollabDocs β Real-Time Collaborative Document Editor
Real-Time Collaboration β Multiple users editing simultaneously with live sync
Rich Text Editor β TipTap-powered with bold, italic, headings, lists, code blocks, links, and more
Live Presence β See who's in the document with colored user indicators
Auto Save β Documents auto-save every 5 seconds via WebSocket
Version History β Full history with restore capability
Comments System β Inline comments with replies and resolve/unresolve
Document Sharing β Invite collaborators by email with viewer/editor roles
Dark Mode β Full dark/light theme support
JWT Auth β Secure signup/login with bcrypt password hashing
Protected Routes β Frontend and backend route protection
Tech
Purpose
React 18 + Vite
UI framework
TailwindCSS
Styling
Zustand
Client state management
TanStack React Query
Server state + caching
TipTap
Rich text editor
Socket.io Client
Real-time events
React Router v6
Routing
React Hot Toast
Notifications
Lucide React
Icons
Tech
Purpose
Node.js + Express
HTTP server
MongoDB + Mongoose
Database
Socket.io
WebSocket server
JWT
Authentication tokens
bcryptjs
Password hashing
helmet + cors
Security middleware
express-rate-limit
Rate limiting
express-validator
Input validation
dompurify + jsdom
HTML sanitization
collab-docs/
βββ backend/
β βββ config/
β β βββ database.js # MongoDB connection
β βββ controllers/
β β βββ authController.js # signup, login, getMe
β β βββ documentController.js # CRUD + share
β β βββ commentController.js # comments + replies
β β βββ versionController.js # version history
β β βββ userController.js # user search
β βββ middleware/
β β βββ auth.js # JWT middleware
β β βββ errorHandler.js # Global error handler
β β βββ validate.js # express-validator helper
β βββ models/
β β βββ User.js
β β βββ Document.js
β β βββ Comment.js
β β βββ Version.js
β βββ routes/
β β βββ auth.js
β β βββ documents.js
β β βββ comments.js
β β βββ versions.js
β β βββ users.js
β βββ sockets/
β β βββ socketHandlers.js # All Socket.io logic
β βββ utils/
β β βββ sanitize.js # DOMPurify HTML sanitizer
β βββ .env.example
β βββ package.json
β βββ server.js # Entry point
β
βββ frontend/
βββ src/
β βββ components/
β β βββ comments/
β β β βββ CommentsPanel.jsx
β β βββ cursors/
β β β βββ ActiveUsers.jsx
β β βββ editor/
β β β βββ CollaborativeEditor.jsx
β β β βββ SaveStatus.jsx
β β β βββ ShareModal.jsx
β β β βββ VersionHistory.jsx
β β βββ toolbar/
β β β βββ Toolbar.jsx
β β βββ ui/
β β βββ Avatar.jsx
β β βββ Modal.jsx
β β βββ PageLoader.jsx
β β βββ ProtectedRoute.jsx
β β βββ Skeleton.jsx
β βββ hooks/
β β βββ useAutoSave.js
β β βββ useComments.js
β β βββ useDocument.js
β β βββ useSocket.js
β βββ pages/
β β βββ Dashboard/index.jsx
β β βββ EditorPage/index.jsx
β β βββ Login/index.jsx
β β βββ Signup/index.jsx
β βββ services/
β β βββ api.js # Axios instance + all API calls
β β βββ socket.js # Socket.io client
β βββ store/
β β βββ authStore.js # Zustand auth state
β β βββ editorStore.js # Zustand editor state
β β βββ themeStore.js # Zustand theme state
β βββ utils/
β β βββ debounce.js
β βββ App.jsx
β βββ index.css
β βββ main.jsx
βββ index.html
βββ package.json
βββ tailwind.config.js
βββ vite.config.js
Node.js >= 18.x
MongoDB (local or MongoDB Atlas)
npm or yarn
git clone < repo-url>
cd collab-docs
cd backend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your values (see Environment Variables section)
# Start development server
npm run dev
cd frontend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your values
# Start development server
npm run dev
π Environment Variables
NODE_ENV = development
PORT = 5000
# MongoDB
MONGODB_URI = mongodb://localhost:27017/collab-docs
# Or MongoDB Atlas:
# MONGODB_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/collab-docs
# JWT (use a strong random string in production)
JWT_SECRET = your_super_secret_jwt_key_change_this_in_production_min_32_chars
JWT_EXPIRES_IN = 7d
# Frontend URL (for CORS)
CLIENT_URL = http://localhost:5173
# Rate Limiting
RATE_LIMIT_WINDOW_MS = 900000
RATE_LIMIT_MAX = 100
VITE_API_URL = http://localhost:5000/api
VITE_SOCKET_URL = http://localhost:5000
Method
Endpoint
Description
Auth Required
POST
/api/auth/signup
Register new user
β
POST
/api/auth/login
Login user
β
GET
/api/auth/me
Get current user
β
PUT
/api/auth/profile
Update profile
β
Method
Endpoint
Description
Auth Required
GET
/api/documents
List documents
β
POST
/api/documents
Create document
β
GET
/api/documents/:id
Get document
β
PUT
/api/documents/:id
Update document
β
DELETE
/api/documents/:id
Delete document
β
POST
/api/documents/:id/share
Share document
β
DELETE
/api/documents/:id/collaborators/:userId
Remove collaborator
β
Comments
Method
Endpoint
Description
GET
/api/comments/:documentId
Get comments
POST
/api/comments
Create comment
POST
/api/comments/:id/replies
Add reply
PUT
/api/comments/:id/resolve
Toggle resolve
DELETE
/api/comments/:id
Delete comment
Method
Endpoint
Description
GET
/api/versions/:documentId
Get version history
POST
/api/versions/:documentId/restore/:versionId
Restore version
Event
Payload
Description
JOIN_DOCUMENT
{ documentId }
Join document room
LEAVE_DOCUMENT
{ documentId }
Leave document room
DOCUMENT_CHANGE
{ documentId, content }
Broadcast content change
CURSOR_POSITION
{ documentId, position, selection }
Broadcast cursor
TITLE_CHANGE
{ documentId, title }
Broadcast title change
SAVE_DOCUMENT
{ documentId, content, title }
Trigger server save
Event
Payload
Description
USER_JOINED
{ user, documentId }
User joined notification
USER_LEFT
{ socketId, userId, name }
User left notification
ACTIVE_USERS
{ users }
Current users in room
DOCUMENT_CHANGE
{ content, userId, timestamp }
Content from other user
CURSOR_POSITION
{ userId, socketId, name, color, position }
Cursor from other user
TITLE_CHANGE
{ title, userId }
Title from other user
DOCUMENT_SAVED
{ documentId, savedAt }
Save confirmation
SAVE_ERROR
{ message }
Save error
Password hashing : bcryptjs with 12 salt rounds
JWT tokens : Expire in 7 days, verified on every request
HTML sanitization : DOMPurify on all user-generated content
Rate limiting : 100 requests per 15 minutes per IP
Helmet.js : HTTP security headers
CORS : Configured for specific frontend origin
Input validation : express-validator on all endpoints
Socket auth : JWT verified on WebSocket connection
π’ Production Deployment
Set NODE_ENV=production
Use a strong JWT_SECRET
Use MongoDB Atlas or a managed MongoDB service
Consider Redis for Socket.io scaling across multiple instances
Use PM2 for process management: pm2 start server.js
cd frontend
npm run build
# Serve the dist/ folder with nginx or any static file server
Consider containerizing both services with Docker Compose for easier deployment.
The backend uses nodemon for hot reload
The frontend uses Vite's HMR for instant updates
Socket.io requests are proxied through Vite in development (see vite.config.js)
Use MongoDB Compass for visual database inspection
Use the browser's DevTools Network tab to monitor WebSocket frames
MIT