ParallelCode is a powerful, real-time collaborative code editor that allows multiple users to code together seamlessly. It features a live code editor, support for multiple programming languages, and an integrated terminal to see execution output. The application is built with a microservices architecture, consisting of a frontend, a backend, and a code execution service.
- Real-time Collaboration: Work with multiple users in the same coding room.
- Live Code Editor: See code changes from other users instantly.
- Multi-language Support: Write and execute code in various languages, including C++, Java, Python, JavaScript, and more.
- Syntax Highlighting: A rich code editor with multiple themes and language-specific syntax highlighting.
- Integrated Terminal: View the output of your code directly in the editor.
- Room-based Sessions: Create unique rooms for your coding sessions and share the ID to invite others.
The application is composed of three main services that run in separate Docker containers:
- Description: A React-based single-page application that provides the user interface. It includes the code editor (CodeMirror), a list of connected clients, language/theme selection, and an output terminal.
- Communication: It communicates with the backend via a Socket.io connection for real-time updates and an HTTP API for code execution.
- Technology: React, Socket.io-client, Recoil, CodeMirror.
- Description: A Node.js server that manages user sessions, rooms, and real-time communication. It uses Socket.io to handle events like users joining/leaving rooms and to synchronize code changes among clients.
- Communication: It listens for socket connections from the frontend and forwards code execution requests to the executor service.
- Technology: Node.js, Express, Socket.io.
- Description: A specialized Node.js service responsible for executing code sent from the backend. It receives a language and a code string, then spins up a dedicated Docker container for that language to run the code securely.
- Communication: It exposes a single REST endpoint that the backend calls. It uses Dockerode to interact with the host's Docker daemon.
- Technology: Node.js, Express, Dockerode.
/
├── backend/
│ ├── src/
│ │ ├── actions/
│ │ ├── routes/
│ │ ├── index.js
│ │ ├── rooms.js
│ │ ├── server.js
│ │ └── socket.js
│ ├── Dockerfile
│ └── package.json
├── executor/
│ ├── src/
│ │ ├── runners/
│ │ ├── execute.js
│ │ └── index.js
│ ├── docker/
│ │ ├── python.Dockerfile
│ │ └── ... (other language Dockerfiles)
│ ├── Dockerfile
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── services/
│ │ ├── App.js
│ │ └── socket.js
│ ├── Dockerfile
│ └── package.json
└── docker-compose.yml
- Frontend: Owns the user interface, client-side state management, and user interactions. It is responsible for rendering the editor and broadcasting user events (like code changes) to the backend. It must never handle business logic or code execution.
- Backend: Owns the real-time collaboration logic. It manages rooms, user sessions, and synchronizes state between clients. It is responsible for receiving events from one client and broadcasting them to others. It must never execute user code directly; instead, it delegates execution to the executor service.
- Executor: Owns the code execution environment. It is responsible for receiving code, running it in a secure, isolated container, and returning the output. It must never handle user sessions or room management; its sole focus is on secure code execution.
The collaboration model is based on a centralized, server-authoritative approach using WebSockets (Socket.io).
- Connection: When a user enters a room, the frontend establishes a persistent WebSocket connection with the backend.
- State Synchronization: The backend maintains the authoritative state for each room, including the list of connected clients and the current code in the editor.
- Event Broadcasting: When a user types in the editor, the frontend emits a
CODE_CHANGEevent to the backend. The backend then broadcasts this event to all other clients in the same room. - Client-side Updates: Upon receiving a
CODE_CHANGEevent, each client updates its local editor state to reflect the changes. This ensures that all users see the same code in near real-time.
Code execution is designed to be secure and isolated, preventing arbitrary code from running on the host system.
- Execution Request: The user triggers an execution from the frontend, which sends an HTTP request to the backend containing the code and the selected language.
- Delegation: The backend validates the request and forwards it to the executor service via a REST API call.
- Isolated Execution: The executor service creates a temporary file containing the user's code. It then spins up a new, short-lived Docker container specific to the requested language (e.g., a Python container for Python code).
- Output Capturing: The code is executed within the container, and its
stdoutandstderrstreams are captured. The container is destroyed immediately after execution. - Result Propagation: The executor service returns the captured output to the backend, which then sends it back to the originating client via a WebSocket event. The frontend displays the output in the integrated terminal.
You can run the entire application using Docker (recommended) or set up each service to run locally on your machine.
- Docker: Required for both the Docker and local installation methods. Download and install Docker Desktop from docker.com.
- Node.js: Required for the local installation method. Download and install Node.js from nodejs.org.
- Git: Required to clone the repository.
This is the simplest way to get the application running.
-
Clone the repository:
git clone https://github.com/Vaibhav-44/ParallelCode.git cd ParallelCode -
Start the services using Docker Compose:
# Recommended (Docker Compose V2): builds and starts frontend, backend, executor docker compose up -d --buildThis will build and start the
frontend,backend, andexecutorservices.The repository also includes build-only services for the language runner images (defined under the
buildersprofile indocker-compose.yml). To build those images as well use:# Build and start everything including language images docker compose --profile builders up -d --build # Or just build the language images without starting services docker compose --profile builders build
If you're using the legacy
docker-composebinary (hyphenated), profiles may not be supported — preferdocker composesupplied by Docker Desktop. -
Access the application: Open your web browser and navigate to
http://localhost:3000.To stop the application, run:
docker-compose down
This method requires you to run each service in a separate terminal.
-
Clone the repository:
git clone https://github.com/Vaibhav-44/ParallelCode.git cd ParallelCode -
Set up environment variables: Create a
.envfile in each service directory:backendexecutorfrontendwith the following content:backend/.envPORT=5000 EXECUTION_URL=http://localhost:4000 EXECUTION_SECRET=change-meexecutor/.envPORT=4000 EXECUTION_SECRET=change-mefrontend/.envREACT_APP_BACKEND_URL=http://localhost:5000 -
Run the Executor service: Open a terminal, navigate to the
executordirectory, and run:cd executor npm install npm run devThe executor service will be running on
http://localhost:4000. -
Run the Backend service: Open a second terminal, navigate to the
backenddirectory, and run:cd backend npm install npm run devThe backend service will be running on
http://localhost:5000. -
Run the Frontend service: Open a third terminal, navigate to the
frontenddirectory, and run:cd frontend npm install npm startThe frontend development server will start, and you can access the application at
http://localhost:3000(or the port specified in the terminal). Make sure the React app is pointing to the correct backend URL. You may need to modify theREACT_APP_BACKEND_URLinfrontend/package.jsonor related files to point tohttp://localhost:5000.
- The
executorservice uses the host Docker daemon (it mounts/var/run/docker.sock) so it can create runtime containers for code execution. On Windows this requires Docker Desktop with WSL2 backend or an equivalent setup that exposes the Docker socket. If you encounter socket permission/availability issues, you can build the language images locally usingdocker buildfrom theexecutorfolder, or run thedocker compose --profile builders buildcommand on a machine with a working Docker socket.