Skip to content

Parth-12pm/Code_Collab

Repository files navigation

CodeCollab

A real-time collaborative code editor built for teams

Live Demo Next.js TypeScript MongoDB


Overview

CodeCollab is a feature-rich, real-time collaborative coding platform that enables developers to write, run, and review code together β€” from anywhere. Built with Next.js 15, it combines live presence tracking, multi-language code execution, integrated AI assistance, and video calling into a single seamless environment.

CodeCollab Editor


Features

πŸ–ŠοΈ Real-Time Collaborative Editing

  • Live multi-cursor presence β€” see exactly where teammates are typing
  • Conflict-free collaborative state powered by Liveblocks
  • Per-user colour-coded cursor overlays and selection highlights

πŸ“ Multi-File Workspace

  • Full folder/file tree with drag-and-drop-style management
  • Create, rename, delete, cut, copy, and paste files and folders
  • Upload local files or entire folder structures from your machine
  • Download the entire workspace as a .zip archive

▢️ Code Execution

  • Web languages (HTML/CSS/JS, React, Vue, Svelte) β€” live Sandpack preview with hot reload
  • Server-side languages (Python, TypeScript, Java, C, C++, C#, Go, Ruby, Rust, PHP) β€” executed via the Wandbox API
  • Integrated terminal (xterm.js) with run command support
  • Split Preview + Console panel layout

πŸ€– AI Coding Assistant

  • Powered by Google Gemini 1.5 Pro
  • Context-aware: automatically reads the file you're currently editing
  • Streamed responses with syntax-highlighted Markdown and code blocks
  • Copy-to-clipboard for every code snippet

πŸŽ₯ Video Calls

  • Floating, draggable, resizable video call window
  • Built on ZegoCloud UIKit Prebuilt
  • Start/end call synced across all session participants via Liveblocks events
  • Camera and mic toggles, screen sharing, participant list

πŸ’¬ Real-Time Chat

  • Room-scoped chat persisted in Liveblocks storage
  • Read receipts β€” "Sent", "Read by N of M", "Read by all"
  • Unread message badge on the chat toggle button

πŸ™ GitHub Integration

  • Create a private GitHub repository directly from a session
  • Commit selected files with a custom commit message
  • View repository info and full sync operation history
  • Requires the repo OAuth scope β€” prompted automatically on sign-in

πŸ”’ Session Management

  • Public and password-protected private sessions
  • Shareable session link β€” join by entering the session ID
  • Persistent session metadata stored in MongoDB
  • Session owner can delete sessions; collaborators can leave

⏱️ Activity Timeline

  • Per-file change log (create, modify, rename, delete) in the sidebar
  • GitHub commit history alongside file-change events

🎨 Theming

  • Light / Dark mode toggle, applied both to the UI and Monaco Editor
  • Persists per-user within the session

Tech Stack

Layer Technology
Framework Next.js 15 (App Router)
Language TypeScript 5
Styling Tailwind CSS + shadcn/ui + Framer Motion
Database MongoDB via Mongoose
Auth NextAuth.js β€” GitHub OAuth + Credentials
Real-time Liveblocks (presence, storage, events)
Code Editor Monaco Editor (@monaco-editor/react)
Web Preview Sandpack (@codesandbox/sandpack-react)
Code Execution Wandbox REST API
Terminal xterm.js (@xterm/xterm)
AI Google Gemini 1.5 Pro (@google/generative-ai)
Video Calls ZegoCloud UIKit Prebuilt
GitHub API Octokit REST (@octokit/rest)
Deployment Vercel

Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • pnpm (recommended) β€” npm install -g pnpm
  • A MongoDB instance (local or Atlas)

1. Clone the Repository

git clone https://github.com/your-username/code-collab.git
cd code-collab

2. Install Dependencies

pnpm install

3. Configure Environment Variables

Create a .env file in the project root:

# MongoDB
MONGODB_URL=mongodb+srv://<user>:<password>@cluster.mongodb.net/codecollab

# NextAuth
NEXTAUTH_SECRET=your-random-secret-here
NEXTAUTH_URL=http://localhost:3000

# GitHub OAuth App (https://github.com/settings/developers)
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

# Liveblocks (https://liveblocks.io/dashboard)
NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY=pk_dev_xxxxxxxxxxxxxxxxxxxx

# Google Gemini AI (https://aistudio.google.com/app/apikey)
GEMINI_API_KEY=your-gemini-api-key

# ZegoCloud (https://console.zegocloud.com/)
NEXT_PUBLIC_ZEGO_APP_ID=123456789
NEXT_PUBLIC_ZEGO_SERVER_SECRET=your-zego-server-secret

4. Run the Development Server

pnpm dev

Open http://localhost:3000 in your browser.


Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ auth/          # NextAuth handlers + signup endpoint
β”‚   β”‚   β”œβ”€β”€ chat/          # Gemini AI streaming endpoint
β”‚   β”‚   β”œβ”€β”€ execute/       # Wandbox code execution proxy
β”‚   β”‚   β”œβ”€β”€ github/        # Create repo + commit endpoints
β”‚   β”‚   └── sessions/      # Session CRUD + file management
β”‚   β”œβ”€β”€ auth/              # Login / register pages
β”‚   β”œβ”€β”€ editor/            # Dashboard + [sessionid] editor page
β”‚   └── page.tsx           # Landing page
β”‚
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ collab-editor/     # Core editor components
β”‚   β”‚   β”œβ”€β”€ editor.tsx           # Monaco editor + live cursors
β”‚   β”‚   β”œβ”€β”€ sidebar.tsx          # File tree + timeline
β”‚   β”‚   β”œβ”€β”€ toolbar.tsx          # Session controls
β”‚   β”‚   β”œβ”€β”€ chat-panel.tsx       # Real-time chat
β”‚   β”‚   β”œβ”€β”€ chat-interface.tsx   # AI assistant
β”‚   β”‚   β”œβ”€β”€ code-execution.tsx   # Run panel + terminal
β”‚   β”‚   β”œβ”€β”€ sandpack-preview.tsx # Web preview
β”‚   β”‚   └── video-call.tsx       # ZegoCloud wrapper
β”‚   β”œβ”€β”€ editor/dashboard/  # Session dashboard UI
β”‚   └── ui/                # shadcn/ui primitives
β”‚
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ auth-opt.ts        # NextAuth config
β”‚   β”œβ”€β”€ github-sync.ts     # GitHub operation queue
β”‚   └── monogdb.ts         # Mongoose connection
β”‚
β”œβ”€β”€ models/                # Mongoose schemas
β”‚   β”œβ”€β”€ User.ts
β”‚   β”œβ”€β”€ EditorSession.ts
β”‚   β”œβ”€β”€ SyncOperation.ts
β”‚   └── SyncQueue.ts
β”‚
β”œβ”€β”€ types/                 # Global type declarations
β”‚   β”œβ”€β”€ next-auth.d.ts
β”‚   └── types.d.ts
β”‚
└── liveblocks.config.ts   # Presence + Storage type definitions

Key Concepts

Sessions

A session is the top-level collaboration unit. Each session has:

  • A unique roomId used as both the URL slug and the Liveblocks room identifier
  • A list of participants with roles (owner or collaborator)
  • Optional password protection for private sessions
  • Optional linked GitHub repository

Liveblocks Storage Schema

type Storage = {
  document:       LiveObject<{ content: string }>
  files:          LiveMap<string, FileData>       // key = file path
  messages:       LiveList<Message>
  timeline:       LiveList<TimelineEntry>
  roomSettings:   LiveObject<RoomSettings>
  executionResults: LiveMap<string, ExecutionResult>
}

Code Execution Flow

User clicks Run
    β”‚
    β–Ό
Language detected from file extension
    β”‚
    β”œβ”€ Web (HTML/JSX/TSX/Vue/Svelte) ──► Sandpack in-browser bundler
    β”‚
    └─ Server-side ──► POST /api/execute ──► Wandbox API ──► stdout/stderr

Supported Languages

Language Execution Live Preview
HTML / CSS / JS βœ… βœ… Sandpack
React (JSX/TSX) βœ… βœ… Sandpack
Vue βœ… βœ… Sandpack
Svelte βœ… βœ… Sandpack
Python βœ… Wandbox β€”
TypeScript (Node) βœ… Wandbox β€”
JavaScript (Node) βœ… Wandbox β€”
Java βœ… Wandbox β€”
C / C++ βœ… Wandbox β€”
C# βœ… Wandbox β€”
Go βœ… Wandbox β€”
Ruby βœ… Wandbox β€”
Rust βœ… Wandbox β€”
PHP βœ… Wandbox β€”

Environment Variables Reference

Variable Required Description
MONGODB_URL βœ… MongoDB connection string
NEXTAUTH_SECRET βœ… Random string for JWT signing
NEXTAUTH_URL βœ… Base URL of your deployment
GITHUB_CLIENT_ID βœ… GitHub OAuth App client ID
GITHUB_CLIENT_SECRET βœ… GitHub OAuth App client secret
NEXT_PUBLIC_LIVEBLOCKS_PUBLIC_KEY βœ… Liveblocks public API key
GEMINI_API_KEY βœ… Google Generative AI key
NEXT_PUBLIC_ZEGO_APP_ID βœ… ZegoCloud App ID
NEXT_PUBLIC_ZEGO_SERVER_SECRET βœ… ZegoCloud server secret

Deployment

The project is pre-configured for Vercel.

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

Add all environment variables listed above in your Vercel project settings under Settings β†’ Environment Variables.

Note: For GitHub OAuth, set your GitHub App's callback URL to https://your-domain.vercel.app/api/auth/callback/github.


Contributing

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

License

This project is for educational and demonstration purposes. See individual dependency licences for third-party terms.


Acknowledgements


Built by Team BitMasters

🌐 Live Demo

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages