The Real-Time Collaborative Code Editor is an advanced, production-ready full-stack application that allows multiple users to join a room and collaboratively edit code in real-time. The project extends beyond a simple WebSocket proxy by integrating Artificial Intelligence (AI) Code Review, horizontal scalability, conflict resolution mechanisms, and enterprise-grade observability and security features.
- React.js (v18.2.0): UI framework.
- React Router (v6.2.1): Client-side routing for navigating between the home screen and editor rooms.
- CodeMirror (v5.65.2): Lightweight, powerful code editor component.
- Socket.io-client: For persistent, real-time bidirectional communication with the backend.
- React-Avatar & React-Hot-Toast: For user presence visualization and elegant notifications.
- Axios & DOMPurify: Used for safe external API fetching and XSS sanitization.
- Node.js (>=18.0.0) & Express.js: REST API and static file serving.
- Socket.IO (v4.4.1): WebSockets implementation for real-time code changes and user presence events.
- Redis & ioredis: Used for Pub/Sub messaging across multiple Node instances, caching, and rate limiting.
- Bull (v4.10.4): Redis-based job queue for processing heavy workloads (e.g., AI Code Reviews) sequentially.
- MongoDB (Mongoose): Document database for persistence (where configured).
- Security: Helmet, CORS, Express Rate Limit, bcryptjs, XSS protection.
- Monitoring & Logging: Winston (structured logging, daily rotation), Prom-client (Prometheus metrics configuration).
- Docker:
Dockerfileanddocker-compose.ymlfor containerized environments. - Jest & React Testing Library: Unit and component testing.
- Artillery: Load-testing (
load-test.yml).
Users create or join specific "Rooms" via unique IDs. CodeMirror instances broadcast changes down to individual keystrokes using Socket.IO.
- Operational Transformation (OT): Used to handle race conditions where two users edit the exact same line simultaneously to ensure document consistency.
The editor features a built-in AI assistant module (integrated heavily with Google's Gemini API).
- Users can request code reviews within the editor. The code is sent to the backend, which proxies the request to the AI service.
- Collaborative Reviews: Reviews are stored in-memory (in
server.js) mapped byreviewIdand broadcast to the room. Users in the room can add specific line comments on the AI feedback.
The backend is designed for horizontal scaling across Load Balancers.
- Redis Pub/Sub: Inter-server communication ensures that events in a room are broadcast to all relevant users even if they are connected to different Node instances.
- Message Queues: Heavy background tasks are pipelined using Bull queues to prevent the main event loop from blocking.
- Endpoints like
/healthand/health/detailedreport on memory usage, active Redis connections, active rooms, etc. - Prometheus scraping metrics are exposed at
/metricsso tools like Grafana can monitor performance.
Real-Time-Collaborative-Code-Editor/
├── config/ # Configuration files and environment loader
├── middleware/ # Express middlewares (auth.js, validation.js)
├── models/ # Database schemas
├── public/ # React public resources (index.html, logos)
├── routes/ # Express routing controllers
├── services/
│ ├── aiCodeReview.js # Gemini AI integration and review logic
│ ├── encryption.js # Data encryption utilities
│ ├── healthCheck.js # System parameter checking logic
│ ├── logger.js # Winston configuration for daily rotated logs
│ ├── messageQueue.js # Bull queue definitions
│ ├── monitoring.js # Prometheus metrics configurations
│ ├── operationalTransform.js # OT code resolution logic
│ └── redis.js # Redis connection manager and cache APIs
├── src/ # React Frontend Source Code
│ ├── components/ # Reusable UI components
│ │ ├── AIReviewPanel.js # Slide-out UI for AI feedback
│ │ ├── SimpleAIReview.js# Compact AI feedback component
│ │ ├── Editor.js # CodeMirror wrapper logic
│ │ └── Client.js # Avatar display component
│ ├── pages/
│ │ ├── Home.js # Landing page to create/join rooms
│ │ └── EditorPage.js # Main workspace with editor and sidebar
│ ├── Actions.js # Shared constants for Socket events
│ ├── App.js # React Router configuration
│ ├── index.js # Entry point
│ └── socket.js # Socket.io client bootstrapper
├── package.json # NPM dependencies & scripts
├── server.js # Core standalone Node server
├── server-enhanced.js # Enterprise server with Redis & Rate Limiting
├── server-simple.js # Basic lightweight version
└── Dockerfile # Containerization strategy
- Takes
roomIdandusernameinput. - Connects to the React Router to forward state to the
EditorPage. - Capable of generating a random UUID for quick room generation.
- Holds the global Socket instance connection.
- Listens for
ACTIONS.JOINEDto update the list of connected clients and display their Avatars on the sidebar. - Manages the AI Side panel toggling.
- Reacts to
ACTIONS.DISCONNECTEDto show toast notifications when a user leaves.
- Attached specifically to a
<textarea>upon mounting. - Instantiates
CodeMirror.fromTextArea. - Whenever a local content change happens (
changeevent, but not triggered by socketsetValue), it emitsACTIONS.CODE_CHANGEvia socket.
- Contains tabs for viewing the "Prompt, Summary, and Issues" provided by AI.
- Interfaces directly with endpoints like
/api/ai-review/create. - Polls or listens via sockets for
review_comment_addedso teammates can see comments in real-time.
- GET
/health&/health/detailed: Provides memory heap limits, dependency status, versioning, and environment variables. Required by deployment platforms like Render. - GET
/api/status&/api/ai-review/status: Provides info on active rooms, enabled AI functionalities, active users, and cache hits. - POST
/api/ai-review/create: Payload:code,language. Submits code to AI review (viaaiCodeReviewService) and maps the generated result to theroomId. - GET
/api/ai-review/:reviewId: Fetches review contents and specific collaborative comments. - POST
/api/ai-review/:reviewId/comment: Allows users to attach a comment (e.g. "I agree with this AI suggestion") to a specific code review.
JOIN: Sent by client when entering an EditorPage.JOINED: Broadcasted by Server to all clients in the room to indicate new user.DISCONNECTED: Notifies clients that a user has exited the room.CODE_CHANGE: Bi-directional event. Client sends on keypress; Server forwards to everyone else in the room.SYNC_CODE: Server asks for the current state of the document from an existing user to synchronize a brand-new user who just joined the room.
The package.json contains a robust suite of scripts to start the app in different lifecycle modes.
npm run start:dev: Starts the React app, Redis, and Node vianodemon.npm run start:simple: Fires upserver-simple.jsstrictly using WS, avoiding AI or Redis overhead locally.npm run start:enhanced: Starts production-ready architecture (server-enhanced.js) utilizing advanced middlewares, Operational Transform, and Health Metrics.npm run test:load: Uses artillery runningload-test.ymlto benchmark server concurrency performance.npm run build:render&npm run build:simple: Specific build tasks optimized for different hosting providers (Render, Railway).
- Nginx configuration: Includes an
nginx.confdesigned for reverse proxying traffic and mapping/health. - The root includes multiple markdown docs related to deployment:
DEPLOYMENT-READY.md,DOCKER-DEPLOYMENT.md,RENDER-DEPLOYMENT-GUIDE.md. These indicate the project has been fine-tuned to be deployed quickly either via Docker Swarm, or automatically on Render/Railway. - Includes
fix-build.shandvalidate-deployment.shto check for missing dependencies in a CI/CD pipeline prior to completing a build step.