Skip to content

trishit78/p2p-program

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Code Together

A real-time collaborative coding platform for pair programming, technical interviews, and coding practice sessions.

Next.js Node.js WebSocket MongoDB

πŸš€ Live Demo

System Design

image

Video Demo

video1450339436.mp4

✨ Features

  • Real-time Code Collaboration - Write code together with live synchronization using Yjs CRDT
  • Monaco Editor - VS Code-like editing experience with syntax highlighting and IntelliSense
  • Video Chat - Face-to-face communication powered by LiveKit
  • AI-Powered Questions - Generate coding challenges using Google Gemini AI
  • Solution Reviews - AI-assisted code review and feedback
  • Infinite Rooms - Create unlimited collaborative sessions
  • Dark/Light Mode - Theme switching for comfortable coding

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 16 (React 19)
  • Editor: Monaco Editor (@monaco-editor/react)
  • Real-time Sync: Yjs + y-websocket + y-monaco
  • Video: LiveKit (@livekit/components-react)
  • Styling: Tailwind CSS 4
  • UI Components: Radix UI, shadcn/ui

Backend

  • Runtime: Node.js with Express 5
  • WebSocket: ws library with @y/websocket-server
  • Database: MongoDB with Mongoose
  • Auth: JWT (jsonwebtoken + bcryptjs)
  • AI: OpenAI (@openai/openai)
  • Video: LiveKit Server SDK

πŸ“ Project Structure

p2p-program/
β”œβ”€β”€ frontend/           # Next.js frontend application
β”‚   β”œβ”€β”€ app/           # App router pages
β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”œβ”€β”€ lib/           # Utilities and API functions
β”‚   └── hooks/         # Custom React hooks
β”‚
β”œβ”€β”€ backend/           # Node.js backend server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ http/      # Express routes
β”‚   β”‚   β”œβ”€β”€ ws/        # WebSocket handlers
β”‚   β”‚   β”œβ”€β”€ config/    # Configuration files
β”‚   β”‚   β”œβ”€β”€ utils/     # Helper functions
β”‚   β”‚   └── types/     # TypeScript types
β”‚   └── dist/          # Compiled JavaScript
β”‚
└── README.md

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • MongoDB instance
  • LiveKit account (for video chat)
  • OpenAI API key (for AI features)

Backend Setup

cd backend

# Install dependencies
npm install

# Create .env file with required variables
cp .env.example .env

# Build TypeScript
npm run build

# Start development server
npm run dev

Environment Variables (backend/.env):

PORT=8000
MONGO_URI=mongodb://localhost:27017/codetogether
JWT_SECRET=your-jwt-secret
OPENAI_API_KEY=your-openai-key
LIVEKIT_API_KEY=your-livekit-key
LIVEKIT_API_SECRET=your-livekit-secret

Frontend Setup

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Environment Variables (frontend/.env.local):

NEXT_PUBLIC_ENVIRONMENT=DEVELOPMENT

🌐 Deployment

Backend (Render)

  1. Create a new Web Service on Render
  2. Connect your GitHub repository
  3. Set build command: npm install && npm run build
  4. Set start command: npm run start
  5. Add environment variables

Frontend (Vercel)

  1. Import project from GitHub
  2. Set root directory to frontend
  3. Add environment variable: NEXT_PUBLIC_ENVIRONMENT=PRODUCTION
  4. Deploy

πŸ”§ WebSocket Architecture

The application uses a single WebSocket endpoint (/ws) with query parameter routing:

  • Room connections: /ws?room=<roomId>&type=room
  • Yjs sync connections: /ws?room=<roomId>&type=yjs

Features:

  • noServer mode for manual upgrade handling
  • Ping/pong keepalive (30s interval) for proxy compatibility
  • Compatible with Render, Vercel, and other reverse proxies

πŸ“ API Endpoints

Endpoint Method Description
/auth/signup POST User registration
/auth/signin POST User login
/api/chat/question GET Generate AI coding question
/api/chat/answer POST Submit solution for AI review
/livekit/getToken GET Get LiveKit room token
/code/run POST Execute code
/code/submit POST Submit code solution

πŸ‘€ Author

Trishit Bhowmik

πŸ“„ License

This project is licensed under the ISC License.

Releases

No releases published

Packages

 
 
 

Contributors