A real-time collaborative whiteboard built with the MERN stack, featuring live drawing synchronization and cursor tracking.
- Real-time Collaboration: Draw with multiple users simultaneously
- Live Cursor Tracking: See other users' cursor positions in real-time
- Room-based Sessions: Join rooms with simple 6-8 character codes
- Drawing Tools: Pen tool with adjustable stroke width and colors
- Canvas Management: Clear canvas functionality
- Responsive Design: Works on desktop and tablet devices
- No Authentication Required: Jump straight into collaboration
- Frontend: React 18 + Vite + Tailwind CSS
- Backend: Node.js + Express.js
- Database: MongoDB with Mongoose
- Real-time Communication: Socket.IO
- Styling: Tailwind CSS
collaborative-whiteboard/
βββ client/ # React frontend
β βββ src/
β β βββ components/
β β β βββ RoomJoin.jsx
β β β βββ Whiteboard.jsx
β β β βββ DrawingCanvas.jsx
β β β βββ Toolbar.jsx
β β β βββ UserCursors.jsx
β β βββ hooks/
β β β βββ useSocket.js
β β βββ App.jsx
β β βββ main.jsx
β β βββ index.css
β βββ index.html
β βββ package.json
β βββ vite.config.js
β βββ tailwind.config.js
βββ server/ # Node.js backend
β βββ models/
β β βββ Room.js
β βββ routes/
β β βββ rooms.js
β βββ socket/
β β βββ socketHandlers.js
β βββ server.js
β βββ package.json
βββ README.md
- Node.js (v18 or higher)
- MongoDB (local installation or MongoDB Atlas)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd collaborative-whiteboard
-
Set up the server
# Navigate to server directory cd server # Install dependencies npm install # Create .env file cp .env.example .env # Edit .env with your configuration nano .env
-
Configure environment variables (server/.env)
PORT=5000 MONGODB_URI=mongodb://localhost:27017/collaborative-whiteboard NODE_ENV=development CLIENT_URL=http://localhost:3000
-
Set up the client
# Navigate to client directory (from project root) cd client # Install dependencies npm install
-
Start MongoDB
# If using local MongoDB mongod --dbpath /path/to/your/db # Or use MongoDB Atlas (update MONGODB_URI in .env)
-
Run the application
Option 1: Run both client and server together (recommended)
# From server directory cd server npm run dev
Option 2: Run separately
# Terminal 1 - Server cd server npm start # Terminal 2 - Client cd client npm run dev
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- API Health Check: http://localhost:5000/api/health
-
Create a new room:
- Click "Generate Random Room Code"
- Share the generated code with others
-
Join an existing room:
- Enter the 6-8 character room code
- Click "Join Room"
- Pen Tool: Click and drag to draw
- Colors: Choose from 6 predefined colors
- Stroke Width: Adjust with predefined sizes or custom slider
- Clear Canvas: Clear the entire canvas (affects all users)
- Real-time Drawing: See others draw as they create strokes
- Live Cursors: View other users' cursor positions
- User Count: See how many people are in the room
- Persistent Canvas: Drawing data is saved and restored when joining
Join or create a room.
Request:
{
"roomId": "ABC123"
}Response:
{
"success": true,
"roomId": "ABC123",
"drawingData": [],
"activeUsers": 1,
"message": "New room created"
}Get room information.
Response:
{
"success": true,
"roomId": "ABC123",
"drawingData": [...],
"activeUsers": 2,
"createdAt": "2025-09-13T...",
"lastActivity": "2025-09-13T..."
}join-room: Join a roomleave-room: Leave current roomcursor-move: Send cursor positiondraw-start: Start drawing strokedraw-move: Drawing movement datadraw-end: Complete drawing strokeclear-canvas: Clear the canvas
room-joined: Confirm room joinuser-count-update: User count changeddrawing-data: Initial canvas datacursor-update: Other user's cursor positiondraw-start: Other user started drawingdraw-move: Other user's drawing movementdraw-end: Other user's complete strokeclear-canvas: Canvas was cleareduser-joined: New user joineduser-left: User left room
- React Components: Modular component structure
- Socket.IO Client: Real-time communication
- Canvas API: HTML5 Canvas for drawing
- Tailwind CSS: Utility-first styling
- Vite: Fast development and build tool
- Express.js: RESTful API server
- Socket.IO Server: WebSocket communication
- MongoDB: Document-based data storage
- Mongoose: ODM for MongoDB
- User joins room via REST API
- Socket connection established
- Drawing events broadcast via WebSocket
- Canvas data persisted to MongoDB
- Real-time updates to all connected clients
- Local Development:
# Server cd server && npm start # Client cd client && npm run dev
-
Build the client:
cd client npm run build -
Environment Setup:
# Production .env NODE_ENV=production PORT=5000 MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/whiteboard CLIENT_URL=https://your-frontend-domain.com
-
Deploy Options:
- Vercel/Netlify: For client deployment
- DigitalOcean/AWS: For full-stack deploymet
- Room creation and joining
- Real-time drawing synchronization
- Cursor tracking between users
- Canvas clearing functionality
- User connection/disconnection handling
- Mobile responsiveness
- Error handling and recovery
# Add testing framework
npm install --save-dev jest @testing-library/react
npm install --save-dev supertest # for API testing- Input Validation: Room IDs are sanitized
- Rate Limiting: Cursor updates throttled
- CORS: Configured for specific origins
- Data Sanitization: Drawing data validated
- Memory Management: Old rooms cleaned up automatically
-
MongoDB Connection Error:
Solution: Check MongoDB service and connection string -
Socket Connection Failed:
Solution: Verify server is running and CORS settings -
Canvas Not Updating:
Solution: Check browser console for JavaScript errors -
Build Errors:
Solution: Clear node_modules and reinstall dependencies
Enable debug logging:
# Server
DEBUG=socket.io:* npm run dev
# Client
# Open browser dev tools and check console- Cursor Throttling: 60fps limit for cursor updates
- Drawing Batching: Efficient path data transmission
- Memory Cleanup: Automatic old room deletion
- Canvas Optimization: Proper context management
- Socket Optimization: Event listener cleanup
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Socket.IO team for real-time communication
- React team for the frontend framework
- MongoDB team for the database solution
- Tailwind CSS for styling utilities
Happy Collaborating! π¨