Skip to content

Anish-Yadav-git/Colab-Editor-

Repository files navigation

๐Ÿš€ Realtime Collaborative Document Editor

A production-ready, real-time collaborative document editor built with modern web technologies. Multiple users can edit documents simultaneously with live cursor tracking, presence indicators, and conflict-free synchronization.

License Node TypeScript

โœจ Key Features

๐Ÿค Real-Time Collaboration

  • Live Editing: See changes from other users instantly as they type
  • Cursor Presence: View where other users are editing with colored cursors and labels
  • User Presence: See who's online, typing, idle, or away
  • Conflict-Free Sync: CRDT-based synchronization ensures no data loss

๐Ÿ“ Document Management

  • Create & Share: Create documents and share with specific users
  • Permission Levels: Owner, Editor, and Viewer roles
  • Document History: View and restore previous versions
  • Search & Filter: Find documents quickly

๐Ÿ”’ Security & Authentication

  • JWT Authentication: Secure user authentication
  • Role-Based Access: Fine-grained permission control
  • Input Sanitization: Protection against XSS and injection attacks
  • Rate Limiting: API and WebSocket rate limiting

๐Ÿ“ฑ Modern UX

  • Responsive Design: Works on desktop, tablet, and mobile
  • Offline Support: Edit offline and sync when reconnected
  • Accessibility: WCAG 2.1 AA compliant with keyboard navigation
  • Dark Mode Ready: Consistent theming with CSS variables

โšก Performance

  • Optimized Bundle: Code splitting and lazy loading
  • Fast Sync: Sub-100ms latency for real-time updates
  • Scalable: Redis-backed session management
  • Efficient: Throttled updates and optimized rendering

๐ŸŽฏ What Makes This Special?

This is a production-ready collaborative editor that demonstrates:

  1. CRDT Technology: Uses Yjs for conflict-free replicated data types
  2. WebSocket Architecture: Real-time bidirectional communication
  3. Offline-First: Works without internet, syncs when back online
  4. Enterprise Features: History, permissions, monitoring, and more
  5. Best Practices: TypeScript, testing, security, accessibility

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Client    โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   Server    โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  Database   โ”‚
โ”‚  (React)    โ”‚ WebSocketโ”‚  (Node.js)  โ”‚         โ”‚ (PostgreSQL)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      โ”‚                        โ”‚                        
      โ”‚                        โ–ผ                        
      โ”‚                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                
      โ”‚                 โ”‚    Redis    โ”‚                
      โ”‚                 โ”‚  (Sessions) โ”‚                
      โ”‚                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                
      โ”‚                                                 
      โ–ผ                                                 
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                        
โ”‚  Monaco     โ”‚                                        
โ”‚  Editor     โ”‚                                        
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                        

Tech Stack

Frontend:

  • React 18 with TypeScript
  • Monaco Editor (VS Code's editor)
  • Yjs (CRDT library)
  • React Router for navigation
  • Vite for build tooling

Backend:

  • Node.js with Express
  • TypeScript
  • PostgreSQL for data persistence
  • Redis for session management
  • WebSocket for real-time communication

Testing:

  • Vitest for unit tests
  • Playwright for E2E tests
  • 90%+ code coverage

๐Ÿ“‹ Prerequisites

Before you begin, ensure you have:

  • Node.js 18.0.0 or higher
  • PostgreSQL 14 or higher
  • Redis 6 or higher
  • npm or yarn

๐Ÿš€ Quick Start

1. Clone the Repository

git clone <repository-url>
cd realtime-collaborative-editor

2. Install Dependencies

# Install root dependencies
npm install

# Install client dependencies
cd client
npm install

# Install server dependencies
cd ../server
npm install

3. Set Up Environment Variables

# Server environment (.env in server directory)
cd server
cp .env.example .env

Edit server/.env:

# Database
DATABASE_URL=postgresql://postgres:password@localhost:5432/collab_editor
DB_HOST=localhost
DB_PORT=5432
DB_NAME=collab_editor
DB_USER=postgres
DB_PASSWORD=password

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production

# Server
PORT=3000
WS_PORT=3001
NODE_ENV=development

4. Set Up Database

# Create database
createdb collab_editor

# Run migrations (from server directory)
cd server
npm run migrate

5. Start Services

Option A: Using Docker (Recommended)

# Start PostgreSQL and Redis
docker-compose up -d postgres redis

Option B: Local Installation

Start PostgreSQL and Redis using your system's service manager.

6. Start the Application

Open three terminal windows:

Terminal 1 - Server:

cd server
npm run dev

Terminal 2 - WebSocket Server:

cd server
npm run dev:ws

Terminal 3 - Client:

cd client
npm run dev

7. Access the Application

Open your browser and navigate to:

http://localhost:5173

๐ŸŽฎ How to Use

First Time Setup

  1. Register an Account

    • Click "Sign Up" on the login page
    • Enter your name, email, and password
    • You'll be automatically logged in
  2. Create Your First Document

    • Click "Create Document" button
    • Enter a document title
    • Start editing!

Collaborative Editing

  1. Invite Collaborators

    • Click the "Share" button in the document
    • Enter collaborator's email
    • Choose permission level (Editor or Viewer)
    • Click "Share"
  2. See Real-Time Changes

    • Open the same document in another browser/tab
    • Type in one window and watch it appear in the other
    • See colored cursors showing where others are editing
    • View presence indicators showing who's online
  3. Work Offline

    • Disconnect from internet
    • Continue editing (changes are queued)
    • Reconnect and changes sync automatically

Document Management

  • View History: Click history icon to see previous versions
  • Restore Version: Select a version and click "Restore"
  • Change Settings: Update document title and permissions
  • Delete Document: Only owners can delete documents

๐Ÿงช Testing

Run Unit Tests

# Client tests
cd client
npm test

# Server tests
cd server
npm test

Run E2E Tests

cd client
npm run test:e2e

Run with Coverage

# Client
cd client
npm run test:coverage

# Server
cd server
npm run test:coverage

๐Ÿ“š Documentation

Comprehensive documentation is available in the docs/ directory:

๐ŸŽจ Demo Scenarios

Scenario 1: Two Users Editing

  1. Open the app in two browser windows (or use incognito)
  2. Register two different accounts
  3. Create a document with User 1
  4. Share it with User 2 (Editor permission)
  5. Both users start typing simultaneously
  6. Watch real-time synchronization with no conflicts!

Scenario 2: Offline Editing

  1. Open a document
  2. Disconnect from internet (turn off WiFi)
  3. Continue editing (see "Offline" indicator)
  4. Reconnect to internet
  5. Watch changes sync automatically

Scenario 3: Document History

  1. Create a document and type some content
  2. Wait a few minutes (snapshots are created periodically)
  3. Make more changes
  4. Click "History" to view previous versions
  5. Restore an older version if needed

๐Ÿ”ง Configuration

Client Configuration

Edit client/vite.config.ts for build settings:

  • Code splitting configuration
  • Proxy settings for API
  • Build optimization

Server Configuration

Edit server/src/config/:

  • database.ts - Database connection
  • redis.ts - Redis configuration
  • logger.ts - Logging settings

๐Ÿšข Deployment

Quick Deployment Options

Easiest: Deploy to Heroku (free tier available)

heroku create my-collab-editor
heroku addons:create heroku-postgresql:mini
heroku addons:create heroku-redis:mini
git push heroku main

Modern: Deploy to Railway or Render (one-click deploy)

Full Control: Deploy to DigitalOcean with Docker

Deployment Guides

What is Deployment?

Deployment means putting your app on the internet so others can use it:

  • Before: Runs on localhost:5173 (only you can access)
  • After: Runs on yourdomain.com (everyone can access)

See DEPLOYMENT_QUICKSTART.md for step-by-step instructions.

๐Ÿ“Š Performance Metrics

  • Initial Load: < 3 seconds
  • Time to Interactive: < 5 seconds
  • Typing Latency: < 50ms
  • Sync Latency: < 200ms
  • Bundle Size: ~1.5 MB (400 KB gzipped)

๐Ÿ” Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • Input sanitization
  • XSS protection
  • CSRF protection
  • Rate limiting
  • SQL injection prevention
  • Secure WebSocket connections

โ™ฟ Accessibility

  • WCAG 2.1 AA compliant
  • Keyboard navigation support
  • Screen reader compatible
  • High contrast mode support
  • Focus indicators
  • ARIA labels and roles

๐Ÿค Contributing

Contributions are welcome! Please read our contributing guidelines before submitting PRs.

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Yjs - CRDT library for conflict-free synchronization
  • Monaco Editor - VS Code's editor component
  • React - UI framework
  • Express - Web framework
  • PostgreSQL - Database
  • Redis - Session management

๐Ÿ“ž Support

For issues and questions:

  • Open an issue on GitHub
  • Check the documentation in docs/
  • Review the E2E testing guide

๐Ÿ—บ๏ธ Roadmap

  • Rich text formatting
  • Comments and annotations
  • File attachments
  • Export to PDF/Word
  • Mobile apps (React Native)
  • Video/audio chat integration
  • AI-powered suggestions

Built with โค๏ธ using modern web technologies

About

A production-ready, real-time collaborative document editor built with modern web technologies. Multiple users can edit documents simultaneously with live cursor tracking, presence indicators, and conflict-free synchronization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages