BLADE: Collaborative Markdown Editor with Math Typesetting

A real-time collaborative Markdown editor built with Operational Transformation (OT) for multi-user editing, featuring LaTeX math support and distributed architecture.

Source Code: GitHub

Features

  • Operational Transformation: Core OT logic (apply, invert, compose, transform) for text manipulation, ensuring eventual consistency.
  • Client-Server Architecture: Uses Socket.IO for WebSocket communication.
  • Multi-Document Support: Create and join separate collaborative document sessions.
  • Revision Tracking: Server maintains a linear history of operations for each document.
  • Automatic Synchronization: Clients automatically push changes and integrate incoming updates in near real-time using the OT algorithm.
  • Basic Editor UI: Uses Ace Editor for text input and Alpine.js for simple UI state management.
  • Markdown Preview with Math: Renders Markdown with support for LaTeX-style math via KaTeX and Marked.js.
  • User Presence: Shows connected users for a given document with unique colors and names.
  • Persistence: Document state and history are persisted using Redis.
  • TypeScript: Entire codebase (client and server) written in TypeScript.
  • Testing: Includes unit tests for the core OT logic using Vitest.

Distributed System Strategy

The core idea is to ensure that for any given document, all connected clients communicate with a single server node that holds the authoritative "ground truth" state for that document.

This is achieved using an Nginx reverse proxy configured as a load balancer. Nginx sits in front of multiple backend application server nodes. When a client initiates a WebSocket connection to a specific document ID, Nginx extracts the document ID from the request URL and uses consistent hashing to direct the client's connection to a specific backend server node.

For persistent storage of document state and history, we utilize Redis. Each document's data (content, revision, history) is stored under a key namespaced by its document ID.

Technology Stack

  • Backend: Bun, TypeScript, Fastify, Socket.IO, Redis, Nginx
  • Frontend: TypeScript, Ace Editor, Alpine.js, Socket.IO Client, Marked.js, KaTeX
  • Testing: Vitest
  • Build: Bun, concurrently

About This Project

Authors: Michaล‚ Kurek & Natnael Teshome (Group 2)
Course: COMPSCI 2620: Final Project Showcase, Harvard University