An Engineer-First Real-time Collaborative Code Editor & Development Environment
High-performance web IDE with bi-directional real-time syncing, integrated execution engine, and built-in team communication.
- System Architecture
- End-to-End User & Data Flow
- Core Engineering Features
- Deep Dive: Project Structure
- Local Setup & Deployment
- Visual Gallery
DevSync is built on a Custom Next.js Server architecture to natively support WebSockets alongside Next.js App Router for server-rendered UI.
graph TD
Client[Client Browser]
subgraph Frontend [Next.js App Router]
Monaco[Monaco Editor]
Whiteboard[Canvas API]
ChatUI[Chat Interface]
Sidebar[File Explorer]
end
subgraph Backend [Custom Node Server]
NextHandle[Next.js Request Handler]
SocketIO[Socket.IO Server]
RoomStore[(In-Memory Room State)]
end
subgraph External [External Services]
Piston[Piston Code Execution Engine]
end
Client -->|HTTP/Next.js| NextHandle
Client <-->|WebSocket| SocketIO
Monaco <-->|Cursor/Code Sync| SocketIO
Whiteboard <-->|Draw Line Sync| SocketIO
ChatUI <-->|Message Event| SocketIO
SocketIO <--> RoomStore
Monaco -->|Compile Request| Piston
- Custom HTTP Server (
server.ts): Instead of relying on standard serverless API routes (which cannot maintain stateful WebSocket connections), DevSync employs a custom HTTP server wrapping bothnext/serverandsocket.io. - In-Memory State Management: For optimal real-time performance without database bottlenecks, session states (files, user lists, active cursors) are managed via an in-memory
Mapdata structure on the Node server. - Piston API Integration: Offloads the heavy lifting of secure, sandboxed code compilation/execution to the Piston execution engine, preventing remote code execution (RCE) vulnerabilities on the primary server.
- User navigates to the landing page and clicks Create Room.
- The client generates a unique
roomId(viananoid) and redirects to/room/[roomId]. - Upon mounting,
useSocketestablishes a persistent TCP connection to the Socket.IO server. - The server initializes an isolated namespace for the
roomIdinside theroomsMap. - Hydration: The server emits
sync-filesandactive-usersto the new client, seeding the initial Monaco editor state and file tree.
- File Edits: Typing in the Monaco Editor triggers
onChange. The frontend emits acode-changeevent containing{ roomId, fileName, code }. - Cursor Tracking: Monaco's cursor observer fires
cursor-move. The server broadcasts the exact{ line, column }alongside the user's generated hex color code to other clients. - Whiteboard Engine: Canvas
mousemoveevents generate coordinate deltas(prevPoint, currentPoint)sent asdraw-lineevents. The server performs fan-out broadcasting to render lines simultaneously on all peers.
- User selects a file and clicks the Run button.
- The frontend packages the raw string content and the designated language.
- A REST
POSTpayload is dispatched to the Piston API. - Piston spins up an ephemeral Docker container, executes the code, and pipes
stdout/stderrback to the client's terminal UI component.
Utilizing @monaco-editor/react to provide a VS Code-equivalent editing experience on the web. Features integrated:
- Rich syntax highlighting and auto-completion.
- Custom decorations injected dynamically for remote cursor rendering.
- Virtualized DOM rendering for massive files.
An intricate set of WebSockets events manages the entire collaborative lifecycle:
join-room/disconnect: Manages the ephemeral user session lifecycle and auto-purges zombies.selection-change: Broadcasts text highlighting selections in real-time.create-file/delete-file: Mutations to the virtual file tree are synced with optimistic UI updates.
Built with Tailwind CSS v4 and Framer Motion:
- Hardware-accelerated UI transitions.
- Dynamic theme switching (VS Dark, VS Light, High Contrast) injected dynamically into Monaco and Tailwind context.
devsync/
βββ src/
β βββ app/
β β βββ page.tsx # Landing page component
β β βββ room/[roomId]/page.tsx# Core room engine (initializes socket)
β β βββ layout.tsx # Global metadata and providers
β β βββ globals.css # Tailwind v4 injection
β βββ components/
β β βββ CodeEditor.tsx # Monaco wrapper with socket sync logic
β β βββ Chat.tsx # Real-time WebSocket chat layer
β β βββ Whiteboard.tsx # 2D Canvas context controller
β β βββ Sidebar.tsx # Virtual file tree state manager
β β βββ LanguageSelector.tsx # Piston API language parser mapping
β β βββ ThemeSelector.tsx # Context-aware theme injector
β βββ hooks/
β β βββ useSocket.ts # Singleton pattern for Socket.io-client
β βββ lib/
β βββ utils.ts # clsx + tailwind-merge utilities
β βββ piston.ts # Piston API execution wrapper
βββ server.ts # The Heart: Custom Node/Express/Socket server
βββ package.json # Dependencies (tsx, next, socket.io)
βββ tsconfig.json # Strict TypeScript configuration
- Node.js
20.x+(due to Next.js 14+ requirements) - Optional: Python/C++ compiler locally if attempting to self-host Piston, but by default, it relies on the public Piston API.
git clone https://github.com/iam-sarthakdev/DevSync.git
cd DevSync
# Install standard dependencies
npm install
# Run the custom server (DO NOT use 'next dev' directly)
npm run dev
# Under the hood, this runs: `tsx server.ts`Because of the custom server, standard Vercel deployments (which enforce serverless architecture) are not supported. DevSync must be deployed to a persistent container/VPS service like Railway, Render, or AWS EC2.
npm run build
npm start # Runs NODE_ENV=production tsx server.ts
Sarthak Dev
- GitHub: @iam-sarthakdev
- LinkedIn: Sarthak Kanoi
Made with β€οΈ by Sarthak Dev