Skip to content

Latest commit

History

274 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Smart Code Lab

Code together. Think faster.

  • Real-Time Collaboration: A real-time collaborative code editor with AI-powered assistance. Multiple users can simultaneously write, edit, and debug code in the same room — with live cursor tracking, instant code synchronization, and an AI assistant powered by Google Gemini that streams responses in real-time.

  • Scalability: Designed a stateless backend architecture by replacing in-memory state with Redis, enabling horizontal scaling across multiple server instances.

  • AI Integration: Implemented an AI assistant with streaming responses (SSE), delivering real-time incremental outputs similar to ChatGPT.

  • Distributed Architecture: Developed a Redis-based data model (room:{id}:users) as a single source of truth for user presence, ensuring consistency in distributed environments.

  • Persistence & Reliability: Built a snapshot persistence system with authenticated fetch keepalive, ensuring code is saved reliably even during page unload events.

CI Pipeline


Features

FeatureDescription
🖥️ Monaco EditorVS Code-quality editor with syntax highlighting, IntelliSense, and custom themes per language
👥 Real-Time CollaborationMultiple users edit simultaneously with live cursor positions and colored name badges
🤖 AI Assistant (Gemini)Ask Gemini to explain, review, fix, or optimize your code — responses stream in real-time via SSE
✂️ Selection ToolbarSelect any code snippet → inline floating toolbar with Explain, Review, Fix, Optimize, and custom Ask actions
▶️Code ExecutionRun code directly in the browser (Python, JavaScript, C++, C) via Judge0 API
📸 Version HistoryAutomatic snapshots on every run + manual save with one-click restore
🔐 JWT AuthenticationSecure signup/signin with bcrypt password hashing and JWT tokens
Redis-Backed StateRoom state, user presence, and code content stored in Redis for horizontal scaling
🖱️ Resizable AI PanelDrag to resize the AI output section for a customized workspace
📥 Code DownloadDownload your code as a properly named file (e.g., Rahul-2026-04-04.py)
🎨 Custom ThemesEach language has its own color-tuned Monaco theme (blue for Python, amber for JS, purple for C++, teal for C)

Supported Languages

LanguageBadgeJudge0 IDMonaco Theme
JavaScriptJS63Warm amber
PythonPY71Deep blue
C++C++54Purple
CC50Teal

System Architecture

%%{init: {'theme': 'base'}}%%
flowchart TB
subgraph Client["🖥️ Frontend · React + Vite"]
direction LR
Monaco["Monaco Editor"]
AIP["AI Panel"]
VH["Version History"]
end
subgraph HooksLayer["🪝 Hooks Layer"]
direction LR
HC["useCollaboration"]
HA["useAI"]
HP["useEditorPersistence"]
end
Client --> HooksLayer
HC <-->|"WebSocket"| SocketIO
HA <-->|"SSE Stream"| AIRoute
HP <-->|"REST + JWT"| RoomRoute
subgraph Server["⚙️ Backend · Express"]
MW["Middleware\nHelmet · CORS · Rate Limit · JWT · Zod"]
subgraph Core["Services"]
direction LR
SocketIO["Socket.IO Server\n+ Redis Adapter"]
AIRoute["AI Service\nGemini 2.5 Flash"]
RoomRoute["Room Service"]
CompileSvc["Compile Service"]
end
MW --> Core
end
CompileSvc -->|"HTTP"| Judge0["Judge0 API"]
AIRoute -->|"API"| Gemini["Google Gemini"]
subgraph DataStores["💾 Data Layer"]
direction LR
PG["PostgreSQL · Prisma ORM\nUser · Room · Snapshot · AIMessage"]
RD["Redis\nRoom State · Presence · Pub/Sub"]
end
Core --> DataStores
SocketIO -.->|"horizontal scaling"| RD
%% 🎨 COLOR DEFINITIONS
classDef client fill:#3b82f6,stroke:#1e40af,color:#fff
classDef core fill:#10b981,stroke:#065f46,color:#fff
classDef service fill:#f59e0b,stroke:#92400e,color:#fff
classDef realtime fill:#8b5cf6,stroke:#5b21b6,color:#fff
classDef data fill:#ef4444,stroke:#7f1d1d,color:#fff
classDef external fill:#f3f4f6,stroke:#9ca3af,color:#111
%% 🎯 APPLY COLORS
%% Frontend
class Monaco,AIP,VH client
%% Hooks + Middleware
class HC,HA,HP,MW core
%% Services
class AIRoute,RoomRoute,CompileSvc service
%% Realtime
class SocketIO realtime
%% Data
class PG,RD data
%% External APIs
class Judge0,Gemini external
Loading

Project Structure

smart-code-lab/
├── .github/
│ └── workflows/
│ └── ci.yml # CI pipeline (GitHub Actions)
├── backend/ # Express API + Socket.IO server
├── frontend/ # React + Vite SPA
├── .gitignore
└── README.md

Tech Stack

Frontend

TechnologyVersionPurpose
React19.2UI framework
Vite8.0Build tool & dev server
TypeScript5.9Type safety
TailwindCSS4.2Utility-first styling
Monaco Editor4.7Code editor (VS Code engine)
Socket.IO Client4.8Real-time WebSocket communication
Axios1.13HTTP client with interceptors
React Router DOM7.13Client-side routing
React Markdown10.1AI response rendering
Vitest4.1Testing framework
Testing Library16.3Component testing

Backend

TechnologyVersionPurpose
Express5.2Web framework
TypeScript5.9Type safety
Prisma5.22ORM for PostgreSQL
PostgreSQLPrimary database
Redis5.11Session state + Socket.IO adapter
Socket.IO4.8Real-time WebSocket server
@socket.io/redis-adapter8.3Multi-server pub/sub
Google Generative AI0.24Gemini AI integration
JSON Web Token9.0Authentication
Bcrypt6.0Password hashing
Zod4.3Request validation
Helmet8.1Security headers
Express Rate Limit8.3Rate limiting
Jest30.3Testing framework
Supertest7.2HTTP assertion library

Getting Started

Prerequisites

  • Node.js ≥ 20
  • npm ≥ 9
  • PostgreSQL (local or hosted, e.g., Neon DB)
  • Redis (local or hosted, e.g., Render Redis)
  • Gemini API KeyGet one here

1. Clone the Repository

git clone https://github.com/rah7202/smart-code-lab.git
cd smart-code-lab

2. Backend Setup

cd backend
npm install

Create backend/.env.local:

DATABASE_URL="postgresql://user:password@localhost:5432/smartcodelab"GEMINI_API_KEY=your_gemini_api_keyJWT_SECRET=your_jwt_secret_here_minimum_64_charsALLOWED_ORIGINS=http://localhost:5173REDIS_URL=redis://localhost:6379LOG_LEVEL=debug

Generate Prisma client and run migrations:

npx prisma generate
npx prisma migrate dev

Start the backend dev server:

npm run dev
# → Server starts on http://localhost:8000

3. Frontend Setup

cd ../frontend
npm install

Create frontend/.env.local:

VITE_BACKEND_URL=http://localhost:8000

Start the frontend dev server:

npm run dev
# → App opens on http://localhost:5173

4. Open the App

  1. Navigate to http://localhost:5173
  2. Sign up for an account
  3. Create a room or enter an existing Room ID
  4. Start coding!

Environment Variables

Backend (backend/.env.local)

VariableRequiredDescription
DATABASE_URLPostgreSQL connection string
GEMINI_API_KEYGoogle Gemini API key
JWT_SECRETSecret for signing JWT tokens (min 64 chars)
ALLOWED_ORIGINSComma-separated allowed CORS origins
REDIS_URLRedis connection string
LOG_LEVELLog level (debug, info, warn, error)
NODE_ENVEnvironment mode

Frontend (frontend/.env.local)

VariableRequiredDescription
VITE_BACKEND_URLBackend server URL

Scripts Reference

Backend

ScriptDescription
npm run devStart dev server with hot reload
npm run buildCompile TypeScript to dist/
npm startStart production server
npm testRun tests with coverage report

Frontend

ScriptDescription
npm run devStart Vite dev server
npm run buildType-check + build for production
npm testRun tests once
npm run test:coverageRun tests with coverage report
npm run lintLint all files

CI/CD Pipeline

GitHub Actions runs on every push/PR to main. Both jobs enforce 70% coverage thresholds for lines and functions.

backend job:
1. Checkout → Setup Node 20 → npm ci (cached)
2. npx prisma generate
3. npm test -- --coverage --ci
4. npm run build
frontend job (runs after backend passes):
1. Checkout → Setup Node 20 → npm ci (cached)
2. npm run test:coverage
3. npm run build

Future Roadmap

FeaturePriorityNotes
Yjs / CRDT Integration🔵 Next MajorReplace keystroke broadcasting with binary delta sync for better concurrency
Docker Compose🟡 MediumRedis + PostgreSQL + App in one-command setup
More Languages🟡 MediumJava, Go, Rust, etc.
AI Context Awareness🔵 FuturePass execution output to Gemini for smarter debugging
JWT Blacklist on Logout🟢 Easyredis.set(blacklist:${token}) with TTL

Author

Rahulgithub.com/rah7202

Repositorygithub.com/rah7202/smart-code-lab

About

A high-performance, real-time collaborative IDE featuring AI-driven pair programming, multi-language execution, and automated version snapshots for seamless team development.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages