Skip to content

saishmungase/RealTime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Collaborative Code Editor

A real-time collaborative code editor that enables multiple developers to code together seamlessly with WebSocket-based synchronization, live cursor tracking, and integrated code execution capabilities.

TypeScript React Node.js PostgreSQL


πŸ“‹ Table of Contents


🎯 Overview

The Collaborative Code Editor is a modern web application designed for real-time collaborative programming. It leverages cutting-edge technologies like Yjs for CRDT-based data synchronization, Monaco Editor for professional code editing, and WebSockets for instant communication between clients and the server.

Perfect for:

  • Pair Programming - Two developers coding together in real-time
  • Code Reviews - Live code review sessions with multiple participants
  • Educational Coding - Students and instructors collaborating on assignments
  • Remote Interviews - Technical interview platforms
  • Team Coding Sessions - Distributed team development

✨ Key Features

πŸ”„ Real-Time Collaboration

  • Instant Code Synchronization - Changes propagate across all connected clients in milliseconds
  • Multi-User Support - Multiple developers can work on the same file simultaneously
  • Conflict Resolution - CRDT (Conflict-free Replicated Data Types) ensures consistency without conflicts
  • User Awareness - See who's connected and editing in real-time

πŸ’» Professional Code Editing

  • Monaco Editor Integration - Industry-standard code editor from VS Code
  • Multi-Language Support - JavaScript, TypeScript, Python, Java, Rust, and more
  • Syntax Highlighting - Beautiful, language-specific syntax coloring
  • Code Formatting - Auto-formatting and code intelligence
  • Dark/Light Themes - Customizable editor themes

⚑ Code Execution

  • Built-in Terminal - Execute code directly from the editor
  • Multiple Language Support - Run code in various programming languages
  • Real-Time Output - See execution results instantly
  • Error Handling - Detailed error messages and debugging information
  • Powered by Code-Executor - Integrated with Code-Executor for secure, sandboxed code execution

πŸ“š History & Persistence

  • Coding History - Save and retrieve past coding sessions
  • LocalStorage Support - Client-side history tracking
  • Session Management - Automatically save coding progress
  • History Browser - Review and restore previous code versions

πŸ“Š Room Management

  • Dynamic Room Creation - Create isolated collaborative spaces
  • Room Persistence - Track active rooms and participant counts
  • Database Integration - PostgreSQL backend for persistent storage
  • Room Statistics - Monitor room activity and user engagement

🎨 Modern UI/UX

  • Responsive Design - Works seamlessly on desktop and tablet
  • Tailwind CSS - Beautiful, utility-first styling
  • Framer Motion - Smooth animations and transitions
  • Lucide Icons - Clean, modern icon set
  • Accessibility - WCAG-compliant interface

πŸ› οΈ Technology Stack

Backend

Technology Version Purpose
Node.js v18+ JavaScript runtime environment
Express.js ^5.1.0 HTTP server framework
TypeScript ^5.8.3 Type-safe JavaScript
WebSocket (ws) ^8.18.1 Real-time bidirectional communication
Yjs ^13.6.26 CRDT library for conflict-free sync
Prisma ^6.11.1 ORM for database management
MediaSoup ^3.19.12 Media server for peer-to-peer media
PostgreSQL - Relational database

Frontend

Technology Version Purpose
React ^19.0.0 UI library
TypeScript ~5.7.2 Type-safe development
Vite ^6.3.3 Fast build tool & dev server
Monaco Editor ^0.52.2 Professional code editor
y-monaco ^0.1.6 Yjs binding for Monaco Editor
React Router ^7.6.2 Client-side routing
Tailwind CSS ^3.4.17 Utility-first CSS framework
Framer Motion ^12.18.1 Animation library
y-websocket ^3.0.0 Yjs WebSocket provider
react-syntax-highlighter ^15.6.1 Code highlighting component
Vercel Analytics ^1.5.0 Usage analytics

πŸ“ Project Structure

COLLAB/
β”œβ”€β”€ README.md                          # This file
β”œβ”€β”€ backend/                           # Node.js/Express server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts                  # Main server entry point
β”‚   β”‚   β”œβ”€β”€ roomManager.ts            # Room management logic
β”‚   β”‚   β”œβ”€β”€ room.ts                   # Room and File classes
β”‚   β”‚   β”œβ”€β”€ count.ts                  # Room counting utilities
β”‚   β”‚   └── generated/
β”‚   β”‚       └── prisma/               # Prisma client (auto-generated)
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma             # Database schema
β”‚   β”‚   └── migrations/               # Database migration files
β”‚   β”œβ”€β”€ package.json                  # Backend dependencies
β”‚   β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
β”‚   └── dist/                         # Compiled JavaScript (generated)
β”‚
└── frontend/                          # React/Vite SPA
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ App.tsx                   # Root component with routing
    β”‚   β”œβ”€β”€ main.tsx                  # Application entry point
    β”‚   β”œβ”€β”€ index.css                 # Global styles
    β”‚   β”œβ”€β”€ component/
    β”‚   β”‚   β”œβ”€β”€ room.tsx              # Main collaborative editor
    β”‚   β”‚   β”œβ”€β”€ landing.tsx           # Landing/home page
    β”‚   β”‚   β”œβ”€β”€ navbar.tsx            # Navigation component
    β”‚   β”‚   β”œβ”€β”€ history.tsx           # History/past sessions page
    β”‚   β”‚   └── code-block.tsx        # Code display component
    β”‚   β”œβ”€β”€ types/
    β”‚   β”‚   └── react-syntax-highlight.d.ts  # Type definitions
    β”‚   β”œβ”€β”€ public/                   # Static assets
    β”‚   └── assets/                   # Images and media
    β”œβ”€β”€ package.json                  # Frontend dependencies
    β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
    β”œβ”€β”€ vite.config.ts                # Vite build configuration
    β”œβ”€β”€ tailwind.config.js            # Tailwind CSS configuration
    β”œβ”€β”€ postcss.config.js             # PostCSS configuration
    β”œβ”€β”€ eslint.config.js              # ESLint rules
    β”œβ”€β”€ vercel.json                   # Vercel deployment config
    └── index.html                    # HTML entry point

πŸš€ Installation & Setup

Prerequisites

Ensure you have the following installed:

  • Node.js (v18 or higher) - Download
  • npm or yarn - Comes with Node.js
  • PostgreSQL (v12 or higher) - Download
  • Git - Download

Step 1: Clone the Repository

git clone <repository-url>
cd COLLAB

Step 2: Setup Backend

cd backend

# Install dependencies
npm install

# Configure environment variables
# Copy the example environment file
cp .env.example .env

# Edit .env with your actual database credentials and user ID

# Setup Prisma (create database and tables)
npx prisma migrate dev --name initial

# Generate Prisma Client
npx prisma generate

# Build TypeScript
npm run build

# Start the server
npm run dev

Server will run on: http://localhost:8080

Step 3: Setup Frontend

cd ../frontend

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will run on: http://localhost:5173 (or as shown in terminal)

Step 4: Connect Frontend to Backend

Update the WebSocket connection URL in frontend/src/component/room.tsx:

// Change the WebSocket connection string if needed
const ws = new WebSocket('ws://localhost:8080');

πŸ—οΈ Architecture

System Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Collaborative Code Editor                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚               β”‚               β”‚
      β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”
      β”‚ Frontend β”‚   β”‚  WebSocket β”‚   β”‚ Analytics
      β”‚  (React) β”‚   β”‚   Server   β”‚   β”‚(Vercel)
      β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚              β”‚
           β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   RoomManager     β”‚
        β”‚  (Room + File)    β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚  Yjs (CRDT)           β”‚
      β”‚  Synchronization      β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   PostgreSQL DB    β”‚
        β”‚  (Room Statistics) β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. User Joins Room:

    • Client connects via WebSocket
    • Server creates/retrieves room
    • Sends initial document state (Yjs snapshot)
  2. User Edits Code:

    • Monaco Editor captures changes
    • Yjs creates CRDT update
    • WebSocket sends update to server
    • Server broadcasts to all other users
  3. Code Execution:

    • User clicks "Run" button
    • Code sent to Code-Executor
    • Results returned and displayed
  4. History Saving:

    • Code saved to localStorage every 20 seconds
    • User can browse history anytime

🌐 API Documentation

WebSocket Messages

Client β†’ Server

Message Format:

{
  "userName": "string",
  "type": "init|update",
  "fileName": "string",
  "fileExtension": "string",
  "update": "Uint8Array"
}

Types:

Type Description Required Fields
init Initialize room connection userName, fileName, fileExtension
update Send document update (CRDT) userName, update

Server β†’ Client

{
  "type": "init|update|error|welcome",
  "file": "string",
  "extension": "string",
  "update": "number[]",
  "message": "string"
}

Types:

Type Description Fields
welcome Connection established message
init Initial document state file, extension, update
update Document update from peer update
error Error occurred message

HTTP Endpoints

Health Check

GET /health

Response:

{
  "count": 42
}

Description: Returns the total number of active rooms/sessions.


πŸ’‘ Usage Guide

Starting a Collaborative Session

  1. Open the application in your browser
  2. Go to the Landing page (home)
  3. Click "Create Room" or "Join Room"
  4. Enter your username and choose a programming language
  5. Start coding - Your changes sync in real-time!

Editing Code

  • Editor Features:
    • Syntax highlighting for 50+ languages
    • Code completion and intelligence
    • Multi-cursor support
    • Find & Replace
    • Indentation guides
    • Line numbers

Running Code

  1. Click the "Play" button in the toolbar
  2. See real-time execution output in the terminal
  3. Handle errors gracefully with detailed error messages

Managing History

  1. Enable history in settings
  2. Code is auto-saved every 20 seconds
  3. Visit History page to review past sessions
  4. Click to restore any previous code

βš™οΈ Code Execution

This project integrates with Code-Executor for secure, sandboxed code execution.

Supported Languages

  • JavaScript / TypeScript
  • Python
  • Java
  • Rust
  • C / C++

How It Works

  1. User clicks "Run" button in the editor
  2. Code is sent to the Code-Executor backend
  3. Code runs in an isolated sandbox environment
  4. Output is captured and returned
  5. Results displayed in the terminal panel
  6. Errors and exceptions are properly handled

Integration

The Code-Executor is integrated through the frontend's room component. The execution endpoint can be configured in environment variables.


πŸ—„οΈ Database Schema

Prisma Schema

model RoomCount {
  id     String  @unique
  name   String
  rooms  Int
}

Table Description

Field Type Purpose
id String Unique identifier
name String User/Account name
rooms Int Total count of sessions created

Database Migrations

All schema changes are tracked in backend/prisma/migrations/. Each migration is versioned with a timestamp.

# View migration status
npx prisma migrate status

# Create new migration
npx prisma migrate dev --name description

# Reset database (development only!)
npx prisma migrate reset

πŸ‘₯ Contributing

We welcome contributions! Here's how to get started:

Development Workflow

  1. Fork the repository

    git clone https://github.com/yourusername/COLLAB.git
  2. Create a feature branch

    git checkout -b feature/awesome-feature
  3. Make your changes

    • Follow the existing code style
    • Write clear commit messages
    • Add tests for new features
  4. Test thoroughly

    # Backend
    cd backend && npm run build
    
    # Frontend
    cd frontend && npm run lint && npm run build
  5. Submit a Pull Request

    • Describe your changes clearly
    • Link any related issues
    • Ensure all tests pass

Code Style

  • TypeScript: Use strict mode, proper types
  • React: Functional components, hooks
  • CSS: Use Tailwind utilities
  • Commits: Follow conventional commit format

Issues & Bug Reports

  • Check existing issues first
  • Provide detailed reproduction steps
  • Include error messages and screenshots
  • Suggest potential solutions

πŸ“ License

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


πŸ”— External Resources

Key Dependencies

Related Projects


πŸ“§ Contact & Support


πŸŽ‰ Acknowledgments

  • Thanks to the Yjs team for the amazing CRDT library
  • Microsoft for Monaco Editor
  • The open-source community for excellent tools and libraries
  • All contributors and users supporting this project

Made with ❀️ by the Saish

Last Updated: January 2026


Quick Reference

Command Purpose
npm install Install dependencies
npm run dev Start development server
npm run build Build for production
npx prisma studio Open database GUI
npx prisma migrate dev Create database migration

Happy Coding! πŸš€

About

The RealTime Coding Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published