# prosemirror/prosemirror-collab architecture

> Architecture diagram of the GitHub repository prosemirror/prosemirror-collab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prosemirror/prosemirror-collab
- Repository: https://github.com/prosemirror/prosemirror-collab

## Overview

##### Project type and purpose
- From the file tree and README, this is not a standalone front-end/back-end application but an open-source “core module” (a plugin) for the ProseMirror rich-text editor.
- Its sole responsibility is to track editor changes, package them up as “steps,” and coordinate merging those steps across collaborating clients.

##### File structure
- Top level: configuration files (.gitignore, package.json, etc.), documentation (README, CONTRIBUTING), and a src directory.
- src/collab.ts: the one source file exporting the plugin logic.
- test/: unit tests around collab behavior.
- No “backend” or “frontend” folders—this is a library meant to be embedded into a browser-side editor and paired with a server component elsewhere.

##### README for additional insights
- The module implements a ProseMirror plugin that plugs into the editor’s state management.
- It depends on ProseMirror’s core (state, transform) and exposes an API for sending/receiving steps.
- No built-in network or persistence; integrates with whatever real-time messaging (WebSocket, REST, CRDT sync) you choose.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Client Side"
        Editor["ProseMirror Editor Instance"]:::frontend
        subgraph "Collab Plugin"
            SB["Step Buffer"]:::frontend
            VT["Version Tracker"]:::frontend
            MS["Message Serializer"]:::frontend
            API["Public API (init, sendSteps, receiveSteps)"]:::frontend
        end
    end

    Network["Network Layer"]:::network
    Server["Collab Server Endpoint"]:::server
    Storage[(Step Storage DB)]:::server
    Other["Other Collaborating Clients"]:::frontend

    Editor -->|"transaction"| SB
    SB -->|"append step"| VT
    VT -->|"prepare steps"| MS
    MS -->|"{steps,version}"| Network
    Network -->|"send {steps,version}"| Server
    Server -->|"validate & store {steps}"| Storage
    Server -->|"broadcast {steps,version}"| Network
    Network -->|"receive {steps,version}"| MS
    MS -->|"apply remote steps"| VT
    VT -->|"transform & rebase"| SB
    SB -->|"update local state"| Editor
    Server -->|"broadcast"| Other
    Other -->|"{steps,version}"| Network

    click SB "https://github.com/prosemirror/prosemirror-collab/blob/master/src/collab.ts"
    click VT "https://github.com/prosemirror/prosemirror-collab/blob/master/src/collab.ts"
    click MS "https://github.com/prosemirror/prosemirror-collab/blob/master/src/collab.ts"
    click API "https://github.com/prosemirror/prosemirror-collab/blob/master/src/collab.ts"
    click Editor "https://github.com/prosemirror/prosemirror-collab/blob/master/src/README.md"
    click Other "https://github.com/prosemirror/prosemirror-collab/blob/master/README.md"
    click Other "https://github.com/prosemirror/prosemirror-collab/blob/master/CONTRIBUTING.md"
    click Server "https://github.com/prosemirror/prosemirror-collab/blob/master/package.json"
    click Storage "https://github.com/prosemirror/prosemirror-collab/blob/master/package.json"
    click Other "https://github.com/prosemirror/prosemirror-collab/blob/master/test/test-collab.ts"
    click Other "https://github.com/prosemirror/prosemirror-collab/blob/master/test/test-rebase.ts"

    classDef frontend fill:#e0ffe0,stroke:#2d7,stroke-width:2px;
    classDef network fill:#e0f0ff,stroke:#37f,stroke-width:2px;
    classDef server fill:#ffe0b2,stroke:#f93,stroke-width:2px;
    classDef external fill:#f0f0f0,stroke:#aaa,stroke-width:1px;
```
