|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Jupyter Server Documents is a JupyterLab extension that provides real-time collaboration (RTC) capabilities by moving document state to the server. The extension consists of: |
| 8 | + |
| 9 | +- **Python backend** (`jupyter_server_documents/`): Server extension handling WebSocket connections, room management, output processing, and collaboration state |
| 10 | +- **TypeScript frontend** (`src/`): JupyterLab extension providing UI components, document providers, and awareness indicators |
| 11 | +- **Hybrid architecture**: Frontend builds to `lib/` and gets packaged into `jupyter_server_documents/labextension/` |
| 12 | + |
| 13 | +## Development Commands |
| 14 | + |
| 15 | +### Setup |
| 16 | + |
| 17 | +```bash |
| 18 | +# Create development environment |
| 19 | +micromamba env create -f dev-environment.yml |
| 20 | +micromamba activate serverdocs |
| 21 | + |
| 22 | +# Development installation |
| 23 | +jlpm dev:install |
| 24 | +``` |
| 25 | + |
| 26 | +### Building |
| 27 | + |
| 28 | +```bash |
| 29 | +# Build frontend only |
| 30 | +jlpm build |
| 31 | + |
| 32 | +# Build for production |
| 33 | +jlpm build:prod |
| 34 | + |
| 35 | +# Clean build artifacts |
| 36 | +jlpm clean:all |
| 37 | +``` |
| 38 | + |
| 39 | +### Development Workflow |
| 40 | + |
| 41 | +```bash |
| 42 | +# Watch mode (auto-rebuild frontend on changes) |
| 43 | +jlpm watch |
| 44 | + |
| 45 | +# Start JupyterLab (in separate terminal) |
| 46 | +jupyter lab |
| 47 | +``` |
| 48 | + |
| 49 | +### Testing |
| 50 | + |
| 51 | +```bash |
| 52 | +# Python tests |
| 53 | +pytest -vv -r ap --cov jupyter_server_documents |
| 54 | + |
| 55 | +# Frontend tests |
| 56 | +jlpm test |
| 57 | + |
| 58 | +# Integration tests (Playwright) |
| 59 | +cd ui-tests && yarn test |
| 60 | +``` |
| 61 | + |
| 62 | +### Code Quality |
| 63 | + |
| 64 | +```bash |
| 65 | +# Lint and format |
| 66 | +jlpm lint |
| 67 | + |
| 68 | +# Check only (no fixes) |
| 69 | +jlpm lint:check |
| 70 | +``` |
| 71 | + |
| 72 | +## Architecture |
| 73 | + |
| 74 | +### Backend Components |
| 75 | + |
| 76 | +- **`app.py`**: Main server extension (`ServerDocsApp`) - entry point and configuration |
| 77 | +- **`rooms/`**: Y-document room management and file-based collaboration state |
| 78 | +- **`outputs/`**: Notebook output processing and storage optimization |
| 79 | +- **`kernels/`**: Kernel management, execution state, and WebSocket connections |
| 80 | +- **`websockets/`**: WebSocket handlers for real-time collaboration |
| 81 | +- **`handlers.py`**: HTTP API endpoints |
| 82 | + |
| 83 | +### Frontend Components |
| 84 | + |
| 85 | +- **`src/docprovider/`**: Document providers, awareness, and Y.js integration |
| 86 | +- **`src/notebook-factory/`**: Custom notebook model and factory for collaboration |
| 87 | +- **`src/codemirror-binding/`**: CodeMirror editor bindings for real-time editing |
| 88 | +- **`src/executionindicator.tsx`**: UI component showing execution awareness |
| 89 | + |
| 90 | +### Key Patterns |
| 91 | + |
| 92 | +- Uses **Y.js/Yjs** for conflict-free replicated data types (CRDTs) |
| 93 | +- **WebSocket-based** real-time synchronization via `YRoomWebsocket` |
| 94 | +- **Output separation**: Large outputs stored separately from notebook documents |
| 95 | +- **Awareness protocol**: Shows user cursors and execution state across collaborators |
| 96 | +- **Kernel state management**: Handles kernel connections and execution across multiple users |
| 97 | + |
| 98 | +## Development Notes |
| 99 | + |
| 100 | +- After Python changes: restart Jupyter server |
| 101 | +- After frontend changes: run `jlpm build` and refresh browser |
| 102 | +- Frontend builds to `lib/` then packages to `jupyter_server_documents/labextension/` |
| 103 | +- Uses `jlpm` (JupyterLab's yarn) instead of npm/yarn directly |
| 104 | +- Development installation uses `uv` for faster Python package management |
0 commit comments