Skip to content

raghul017/CodeCollab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ CodeCollab - Real-Time Collaborative Code Editor

A production-quality collaborative code editor that enables multiple users to write, edit, and execute code together in real-time.

MIT License Node.js TypeScript React

Live Demo | Documentation | Deployment Guide


✨ Features

🀝 Real-Time Collaboration

  • Multi-user editing - Multiple users can code together simultaneously
  • Live synchronization - See changes as they happen (< 100ms latency)
  • User presence - See who's online with color-coded indicators
  • Room-based sessions - Private collaboration spaces with unique IDs

πŸ’» Code Editor

  • VS Code-powered - Built on Monaco Editor (same as VS Code)
  • 9+ Languages - JavaScript, TypeScript, Python, Java, C++, Go, Rust, HTML, CSS
  • Syntax highlighting - Full language support with IntelliSense
  • Theme toggle - Light and dark modes with persistent preferences

⚑ Code Execution

  • Run JavaScript & Python - Execute code directly in the browser
  • Real-time output sync - See execution results across all users
  • Resizable console - Drag-to-resize output panel
  • Error handling - Clear error messages and execution feedback

πŸ’Ύ Document Persistence

  • Auto-save - Automatically saves every 10 seconds
  • Version history - Track all changes with timestamps
  • One-click restore - Revert to any previous version
  • PostgreSQL storage - Reliable database persistence

🎨 Modern UI/UX

  • Beautiful design - Gradient backgrounds, smooth animations
  • Responsive layout - Works on desktop and tablet
  • Toast notifications - Real-time feedback for all actions
  • Accessibility - ARIA labels, keyboard shortcuts, screen reader support

πŸ”’ Security & Performance

  • Rate limiting - Prevent API abuse (100 req/15min)
  • Input validation - Zod schemas for all endpoints
  • Helmet.js - Security headers configured
  • Redis caching - Fast document retrieval
  • Gzip compression - Optimized data transfer

πŸ—οΈ Tech Stack

Frontend

  • React 18 - UI library with hooks
  • TypeScript - Type-safe JavaScript
  • Vite - Lightning-fast build tool
  • Monaco Editor - VS Code's editor component
  • Socket.io Client - Real-time communication
  • Tailwind CSS - Utility-first styling
  • React Hot Toast - Beautiful notifications

Backend

  • Node.js - Runtime environment
  • Express - Web framework
  • Socket.io - WebSocket server
  • TypeScript - Type safety
  • Prisma - Type-safe ORM
  • PostgreSQL - Relational database
  • Redis - Caching layer
  • Winston - Logging
  • Zod - Schema validation
  • Helmet - Security middleware

DevOps

  • Docker - Containerization
  • Railway - Backend hosting
  • Vercel - Frontend hosting
  • GitHub Actions - CI/CD (planned)

πŸ“Έ Screenshots

Main Editor Interface

Main Interface Real-time collaborative editing with syntax highlighting

Version History

Version History Track and restore previous versions

Code Execution

Code Execution Run code and see output in real-time

Multi-User Collaboration

Multi-User Multiple users editing simultaneously


πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • PostgreSQL 15+
  • Redis 7+
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/Real_time_colab.git
    cd Real_time_colab
  2. Set up the database

    # Start Docker containers
    docker-compose up -d
  3. Install dependencies

    # Install server dependencies
    cd server
    npm install
    
    # Install client dependencies
    cd ../client
    npm install
  4. Configure environment variables

    # Server (.env)
    cd server
    cp .env.example .env
    
    # Edit .env with your configuration
    DATABASE_URL="postgresql://postgres:password@localhost:5432/codeeditor"
    REDIS_URL="redis://localhost:6379"
    CORS_ORIGIN="http://localhost:5173"
  5. Run database migrations

    cd server
    npx prisma migrate dev
    npx prisma generate
  6. Start development servers

    # Terminal 1: Start backend
    cd server
    npm run dev
    
    # Terminal 2: Start frontend
    cd client
    npm run dev
  7. Open your browser

    http://localhost:5173
    

πŸ“– Usage

Creating a Room

  1. Enter a username
  2. Click "Create Room"
  3. Share the room ID with collaborators

Joining a Room

  1. Enter your username
  2. Enter the room ID
  3. Click "Join Room"

Writing Code

  1. Select your programming language
  2. Start typing in the editor
  3. Changes sync automatically to all users

Running Code

  1. Write JavaScript or Python code
  2. Click the "Run" button
  3. View output in the console below

Saving Documents

  1. Documents auto-save every 10 seconds
  2. Or press Cmd+S / Ctrl+S to save manually
  3. Changes persist across sessions

Version History

  1. Click "Version History" in the sidebar
  2. Browse previous versions with timestamps
  3. Preview any version
  4. Click "Restore" to revert

πŸ›οΈ Architecture

High-Level Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Vercel    β”‚         β”‚   Railway   β”‚
β”‚  (Frontend) │────────▢│  (Backend)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚                     β”‚
              β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
              β”‚   PostgreSQL β”‚          β”‚   Redis β”‚
              β”‚ (Documents)  β”‚          β”‚  (Cache)β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

1. User Joins Room:

Client β†’ Socket.io β†’ Server β†’ Database β†’ Cache β†’ Broadcast to Room

2. Code Changes:

User types β†’ Debounce (300ms) β†’ Socket β†’ Server β†’ Broadcast β†’ Other Users

3. Document Save:

Auto-save (10s) β†’ REST API β†’ Database β†’ Redis Cache β†’ Version Created

Database Schema

-- Documents table
Document {
  id          String    @id @uuid
  title       String
  content     Text
  language    String
  roomId      String    @unique
  createdAt   DateTime
  updatedAt   DateTime
  versions    DocumentVersion[]
}

-- Version history
DocumentVersion {
  id            String    @id @uuid
  documentId    String
  content       Text
  versionNumber Int
  createdAt     DateTime
}

πŸ”§ Configuration

Environment Variables

Backend

NODE_ENV=development
PORT=3001
DATABASE_URL=postgresql://user:pass@localhost:5432/db
REDIS_URL=redis://localhost:6379
CORS_ORIGIN=http://localhost:5173
LOG_LEVEL=info

Frontend

VITE_API_URL=http://localhost:3001
VITE_SOCKET_URL=http://localhost:3001

πŸ“¦ Deployment

See DEPLOYMENT.md for detailed deployment instructions.

Quick Deploy

Backend (Railway):

  1. Connect GitHub repository
  2. Add PostgreSQL and Redis databases
  3. Configure environment variables
  4. Deploy automatically

Frontend (Vercel):

  1. Connect GitHub repository
  2. Set build configuration
  3. Add environment variables
  4. Deploy with one click

πŸ§ͺ Testing

Manual Testing Checklist

  • Create and join rooms
  • Multi-user real-time sync
  • Code execution (JS & Python)
  • Document auto-save
  • Version history and restore
  • Reconnection after disconnect
  • Theme switching
  • Language switching

Load Testing

# Test with multiple concurrent users
# Open 5+ browser tabs and test real-time sync

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style

  • Use TypeScript strict mode
  • Follow ESLint configuration
  • Add comments for complex logic
  • Write meaningful commit messages

πŸ“ Project Structure

Real_time_colab/
β”œβ”€β”€ client/                  # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom hooks
β”‚   β”‚   β”œβ”€β”€ services/        # API services
β”‚   β”‚   └── App.tsx          # Main app component
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”‚
β”œβ”€β”€ server/                  # Node.js backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/          # Configuration files
β”‚   β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”‚   β”œβ”€β”€ services/        # Business logic
β”‚   β”‚   β”œβ”€β”€ models/          # Database models
β”‚   β”‚   └── index.ts         # Server entry point
β”‚   β”œβ”€β”€ prisma/              # Database schema
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ docker-compose.yml       # Docker configuration
β”œβ”€β”€ DEPLOYMENT.md            # Deployment guide
└── README.md                # This file

πŸ› Known Issues & Limitations

  1. Code Execution: Only JavaScript and Python are supported
  2. File Size: Document content limited to 1MB
  3. Concurrent Users: Optimized for 2-10 users per room
  4. Cursor Tracking: Remote cursor positions not yet implemented
  5. Offline Mode: Requires active internet connection

πŸ—ΊοΈ Roadmap

  • Remote cursor tracking
  • Chat functionality
  • File upload/download
  • Collaborative whiteboard
  • Admin dashboard
  • User authentication
  • Private rooms with passwords
  • Mobile app (React Native)
  • VSCode extension

πŸ“„ License

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


πŸ™ Acknowledgments

  • Monaco Editor - VS Code's amazing editor
  • Socket.io - Real-time engine
  • Tailwind CSS - Beautiful styling
  • Railway & Vercel - Hosting platforms


⭐ Show Your Support

If you found this project helpful, please give it a ⭐ star!


Built with ❀️ using React, TypeScript, and Socket.io

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages