How ozep/cwm works
Project type and purpose
• This is a full-stack, real-time collaborative coding platform (“Code With Me”) built with a React/Vite frontend and a Node.js backend.
• Its purpose is to let two or more users share a live code editor (powered by Yjs and Monaco), execute snippets via the Piston API, and exchange debugging assistance.
File structure
Top-level:
• alg/ – Proof-of-concept scripts (Piston API experiments)
• backend/ – Node.js server code
– server.js – WebSocket & REST endpoints
– question.js – question/session management
– callback.js – handles asynchronous Piston callbacks
– utils.js – axios setup for Piston API
– leetcode-train.jsonl – sample questions data
• public/ – static assets
• index.html – SPA entrypoint for Vite
• vite.config.js – Vite build config
• src/ – React application
– main.tsx – ReactDOM bootstrap
– App.tsx – root component
– api.js – HTTP + WebSocket wrapper
– context/ – React Context for WebSocket (SignalWSProvider)
– components/ – UI (CodeEditor, Output, LanguageSelector, etc.)
• package.json – dependencies (Yjs, monaco-collab, axios, react, etc.)
Extract architecture details from README
• Frontend: Vite + React + TypeScript, Real-Time Monaco + Yjs for CRDT syncing
• Backend: Node.js + WebSocket server for low-latency sync
• Code execution: Piston API via axios calls
• No external database: session state is kept in memory or via Yjs documents; questions are served from a JSONL file
A. Client App (browser)
• React UI
• Real-Time Monaco component (Yjs binding)
• SignalWSProvider: maintains WebSocket connection
• Code execution UI → calls api.js to invoke Piston
B. WebSocket Server (backend/server.js)
• Hosts Yjs WebSocket provider for document sync
• Broadcasts CRDT updates between clients
• Emits events for “run code” requests
C. REST / HTTP Endpoints
• POST /execute → callback.js / utils.js → Piston API
• GET /questions → question.js reads JSONL
D. External Service
• Piston API (https://emkc.org/api/v2/piston)
E. Data Storage
• In-memory Yjs documents (CRDT state)
• leetcode-train.jsonl for questions
Architectural patterns & design principles
• CRDT-based real-time synchronization (Yjs)
• WebSocket publish/subscribe for low-latency collaboration
• Clear separation of concerns:
• Frontend: UI + state binding
• Backend: sync engine + code execution proxy
• Stateless code-execution proxy (Piston) to maintain sandbox security