CodeCollab
CodeCollab
Suyash Singh
Posted by Suyash Singh
19 days ago on July 13, 2024
Photo by on Unsplash

Motivations

I embarked on this project driven by a curiosity to delve into CRDT. I chose Rust for the backend to handle WebSockets and manage YJS documents. For the frontend, I opted for Next.js with React. This project serves as a prototype, aiming to lay the groundwork for a resilient and scalable collaborative platform.

Tech Stack

  • Rust
  • Next.js
  • React
  • YJS
  • CRDT

Demo

Architecture

High Level Flow

High Level flows
  • Multiple Users: Users access and interact with a collaborative code editor frontend built using Next.js and React.
  • WebSocket Communication: Frontend communicates with a Rust server backend via WebSockets.
  • CRDT Management: Rust server manages CRDT (Conflict-free Replicated Data Type) documents using YRS (YJS Rust Server).
  • Real-time Synchronization: Changes made by users are synchronized across all connected clients in real-time.
  • Efficient Collaboration: Allows multiple users to edit code concurrently without conflicts.
  • Responsive User Interface: Next.js and React provide a robust frontend for intuitive and responsive user interaction.

The collaborative code editor utilizes Next.js and React to provide users with an accessible and responsive web-based interface for editing code collaboratively. Users interact with the frontend, which communicates seamlessly with a Rust server backend via WebSockets. The Rust server employs YRS (YJS Rust Server) to manage CRDT documents, enabling concurrent editing without conflicts among multiple users.

This architecture ensures that edits made by any participant are synchronized instantly across all connected clients, fostering efficient and seamless collaboration on shared code projects. Next.js and React play pivotal roles in delivering an intuitive user experience, integrating well with the backend infrastructure to support real-time synchronization and responsive updates to the collaborative editing environment.

Low-Level Flow

Rust Server flows
  • WebSocket Setup: Frontend establishes WebSocket connections to the Rust server for real-time communication.
  • Message Parsing: Messages sent over WebSocket are parsed by the Rust server to identify CRUD (Create, Read, Update, Delete) operations on CRDT documents.
  • CRDT Integration: YRS within the Rust server manages CRDT documents, handling concurrent edits and resolving conflicts.
  • State Management: Rust server maintains the state of CRDT documents, applying changes received from clients and broadcasting updates.
  • Event Handling: Event listeners in the frontend capture user actions and transmit them via WebSocket to the Rust server.
  • Conflict Resolution: YRS ensures conflict-free editing by reconciling concurrent changes made by multiple users.
  • Rendering Updates: Next.js and React update the frontend UI in response to changes received via WebSocket from the Rust server. High-Level Flow Paragraph:

At a lower level, the collaborative code editor’s frontend establishes WebSocket connections to the Rust server, facilitating bi-directional communication. Messages exchanged between the frontend and backend are parsed by the Rust server to interpret CRUD operations on CRDT documents managed by YRS. The Rust server handles state management of these documents, applying changes received from clients and broadcasting updates back via WebSocket.

YRS ensures conflict-free editing by resolving concurrent changes, thus maintaining document consistency across all clients. Event listeners in the frontend capture user actions and transmit them efficiently to the backend, where they are processed and integrated into the collaborative editing environment. Next.js and React dynamically update the frontend UI based on real-time updates received from the Rust server, ensuring a responsive and interactive user experience during collaborative coding sessions.