# casualoffice/docs architecture

> Architecture diagram of the GitHub repository casualoffice/docs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/casualoffice/docs
- Repository: https://github.com/casualoffice/docs

## Overview

1. **Top-level shape: a split system**
   - The repository is organized around two runtime halves:
     - `docx-editor/`: the browser-side editor monorepo.
     - `collab/`: a Node-based collaboration server, pulled in as a submodule.
   - The intended deployment is a single Docker image exposing one HTTP port, serving both the editor SPA and the WebSocket collaboration backend.

2. **Editor core is the document engine**
   - `docx-editor/packages/core` is the non-UI heart of the system.
   - It owns the `.docx` domain model: unzip/parse/serialize, OOXML-specific handling, style inheritance, numbering, tables, headers/footers, images, math, comments, footnotes/endnotes, and selective XML save/patch logic.
   - This package is where round-trip fidelity is preserved; it is the boundary between raw WordprocessingML bytes and the editable internal model.

3. **Internal editing model is ProseMirror**
   - The editor does not edit OOXML directly in the UI.
   - The core package maps DOCX content into a ProseMirror schema, applies editing commands and plugins there, then serializes back out.
   - The ProseMirror layer is also where extension points, keymaps, marks/nodes, tracked changes, suggestion mode, selection tracking, and document transformations live.

4. **Rendering uses a custom paginated layout pipeline**
   - The visible WYSIWYG document is produced by a custom layout stack in `packages/core/src/layout-*` and the React paged editor in `packages/react/src/paged-editor`.
   - The flow is roughly: parsed document model → layout bridge/measuring → pagination/layout engine → painter/renderers for pages, paragraphs, tables, images, text boxes, and headers/footers.
   - This is the main architectural boundary that makes the editor “Word-like” rather than a generic rich-text surface.

5. **React package is the UI composition layer**
   - `docx-editor/packages/react` provides the exported `<DocxEditor>` and related components.
   - It composes the editor shell, ribbon/toolbar, formatting bar, dialogs, sidebars, context menus, status bar, rulers, and mobile-format controls.
   - Most user-facing behavior is assembled here, but the actual document semantics still live in `packages/core`.

6. **File source and storage are abstracted from editing**
   - The editor supports multiple file-source modes through `packages/react/src/file-source` and related hooks:
     - local/browser files
     - personal/authenticated modes
     - WOPI-style integration
     - autosave and restore via IndexedDB
   - This separation keeps file lifecycle concerns distinct from document editing. The UI asks a file-source layer for bytes and save semantics rather than talking directly to storage.

7. **Real-time collaboration is room-based and stateless by default**
   - Co-editing is driven by Yjs + Hocuspocus over WebSockets in the `collab` server.
   - The server models each shared document as a room with a Y.Doc and no required database.
   - The browser side synchronizes through a collaboration provider, exchanging document updates, cursor presence, and room metadata.
   - Seed bytes are uploaded/fetched through REST endpoints, while live editing travels over `/yjs`.

8. **Persistence is intentionally split between room state and file bytes**
   - The collaboration server can persist room state in memory, local disk, or Redis, but that is separate from file storage.
   - The host/application layer is responsible for actual document bytes in production integrations.
   - This boundary matters: collaboration can be stateless and transient even when the underlying file source is durable or external.

9. **AI and DocOps are gated, streamed subsystems**
   - AI features are present but explicitly pre-release and hidden unless a model is reachable.
   - There are two main AI paths:
     - desktop/local model execution via an ai-worker sidecar
     - web/cloud inference via Anthropic API configured on the collab server
   - Responses stream back via SSE into UI panels, then get applied as document mutations or suggestions rather than as direct free-form edits.

10. **Plugin architecture is first-class**
    - The core package exposes plugin APIs and registry machinery.
    - The React package also has a plugin host and re-export boundaries so custom UI or behavior can be inserted without rewriting the editor.
    - Example apps in `docx-editor/examples/plugins` show how extensions integrate with the editor shell.

11. **Format support is broader than DOCX, but DOCX remains canonical**
    - `.docx` is the native round-trip format.
    - `.md`, `.txt`, and `.odt` are converted through a lazy-loaded WASM worker path in `packages/core`.
    - PDF export happens through the browser print pipeline.
    - Architecture-wise, everything is normalized through the DOCX/prose model rather than having separate editing engines per format.

12. **Quality and fidelity are enforced by specialized test pipelines**
    - The repo uses unit tests for parser/serializer/layout behavior, Playwright E2E for editor workflows, and visual-fidelity checks against reference renders.
    - There is also a round-trip audit script that parses and reserializes `document.xml` to catch fidelity regressions.
    - These tests are not just validation; they reflect the repo’s key architectural constraint: visual and OOXML fidelity are part of the core design, not an afterthought.

13. **Examples and tooling are a separate delivery surface**
    - The `examples/` directories show the editor embedded in Vite, Next.js, Remix, Astro, Vue, and collaboration demos.
    - That indicates the package boundaries are designed for reuse: the editor library can be embedded into other apps while the monorepo also ships a full reference application.

14. **Operational packaging ties everything together**
    - The top-level Dockerfile and compose files package the browser app and collab server together.
    - The repo therefore has two deployment modes:
      - local development with separate editor and collab processes
      - production/self-hosted single-container deployment
    - This is the main operational boundary to show in an architecture diagram: browser client, optional host/storage integrations, and the collaboration server are distinct runtime nodes, even though they ship from one repo.

Main entry points: [`docx-editor/packages/react`](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react) (React shell), [`docx-editor/packages/core`](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core) (Core engine), [`docx-editor/e2e`](https://github.com/casualoffice/docs/tree/main/docx-editor/e2e) (Quality checks), [`docx-editor`](https://github.com/casualoffice/docs/tree/main/docx-editor) (Editor repo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repository"]
  node_docker_stack["Docker image<br/>deployment"]
end

subgraph group_editor["Editor runtime"]
  node_editor_monorepo["Editor repo<br/>workspace"]
  node_core_pkg["Core engine<br/>docx engine"]
  node_docx_pipeline["DOCX pipeline<br/>ooxml IO"]
  node_prosemirror_layer["ProseMirror layer<br/>editing model"]
  node_layout_stack["Layout stack<br/>paginated layout"]
  node_react_shell["React shell<br/>ui composition"]
  node_paged_editor["Paged editor<br/>render host"]
  node_file_source["File source<br/>bytes lifecycle"]
  node_plugin_api["Plugin API<br/>extension surface"]
  node_ai_docops["AI / DocOps<br/>streamed assistants"]
  node_collab_client["Collab client<br/>sync provider"]
  node_docops_pkg["DocOps package<br/>assistant tooling"]
end

subgraph group_collab["Collaboration runtime"]
  node_collab_server["Collab server<br/>yjs websocket"]
end

subgraph group_ops["Delivery"]
  node_examples["Examples<br/>embedders"]
  node_quality["Quality checks<br/>validation"]
  node_deploy["Deployment<br/>infra"]
  node_roundtrip_audit["Round-trip audit<br/>fidelity script"]
end

node_docker_stack -->|"serves"| node_editor_monorepo
node_docker_stack -->|"includes"| node_collab_server
node_editor_monorepo -->|"contains"| node_core_pkg
node_editor_monorepo -->|"contains"| node_react_shell
node_core_pkg -->|"owns"| node_docx_pipeline
node_core_pkg -->|"maps to"| node_prosemirror_layer
node_core_pkg -->|"drives"| node_layout_stack
node_core_pkg -->|"exposes"| node_plugin_api
node_react_shell -->|"composes"| node_paged_editor
node_react_shell -->|"abstracts"| node_file_source
node_react_shell -->|"hosts"| node_plugin_api
node_react_shell -->|"syncs via"| node_collab_client
node_react_shell -->|"surfaces"| node_ai_docops
node_paged_editor -->|"renders with"| node_layout_stack
node_collab_client -->|"syncs"| node_collab_server
node_docops_pkg -->|"powers"| node_ai_docops
node_examples -->|"embeds"| node_react_shell
node_quality -->|"verifies"| node_core_pkg
node_quality -->|"verifies"| node_react_shell
node_quality -->|"includes"| node_roundtrip_audit
node_deploy -->|"defines"| node_docker_stack

click node_docker_stack "https://github.com/casualoffice/docs/tree/main/Dockerfile"
click node_editor_monorepo "https://github.com/casualoffice/docs/tree/main/docx-editor"
click node_core_pkg "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core"
click node_docx_pipeline "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/docx"
click node_prosemirror_layer "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/prosemirror"
click node_layout_stack "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/layout-engine"
click node_react_shell "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react"
click node_paged_editor "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/paged-editor"
click node_file_source "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/file-source"
click node_plugin_api "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/plugin-api"
click node_ai_docops "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/lib/writer"
click node_collab_server "https://github.com/casualoffice/docs/tree/main/collab"
click node_collab_client "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/collab"
click node_docops_pkg "https://github.com/casualoffice/docs/tree/main/docx-editor/packages/docops"
click node_examples "https://github.com/casualoffice/docs/tree/main/docx-editor/examples"
click node_quality "https://github.com/casualoffice/docs/tree/main/docx-editor/e2e"
click node_deploy "https://github.com/casualoffice/docs/tree/main/deploy"
click node_roundtrip_audit "https://github.com/casualoffice/docs/blob/main/docx-editor/scripts/roundtrip-audit.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_docker_stack toneBlue
class node_editor_monorepo,node_core_pkg,node_docx_pipeline,node_prosemirror_layer,node_layout_stack,node_react_shell,node_paged_editor,node_file_source,node_plugin_api,node_ai_docops,node_collab_client,node_docops_pkg toneAmber
class node_collab_server toneMint
class node_examples,node_quality,node_deploy,node_roundtrip_audit toneRose
```

## Components

### Repository

Top-level monorepo with browser editor and collaboration backend.

- [Docker image](https://github.com/casualoffice/docs/tree/main/Dockerfile): deployment · Single-container packaging that serves the editor UI and collab backend on one HTTP entrypoint. · `Dockerfile`

### Editor runtime

Browser-side editor monorepo and reusable packages.

- [Editor repo](https://github.com/casualoffice/docs/tree/main/docx-editor): workspace · Browser-side monorepo containing the core engine, React UI, examples, and supporting packages. · `docx-editor`
- [Core engine](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core): docx engine · Canonical document engine for DOCX parsing, model conversion, serialization, and fidelity-preserving round trips. · `docx-editor/packages/core`
- [DOCX pipeline](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/docx): ooxml IO · Unzip/parse/serialize layer for WordprocessingML, including styles, numbering, sections, tables, media, comments, and selective save patches. · `docx-editor/packages/core/src/docx`
- [ProseMirror layer](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/prosemirror): editing model · Internal schema, commands, plugins, marks, nodes, and document transformations used for editing semantics. · `docx-editor/packages/core/src/prosemirror`
- [Layout stack](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/layout-engine): paginated layout · Bridge, measuring, pagination, and painting pipeline that produces Word-like paged rendering. · `docx-editor/packages/core/src/layout-engine`
- [React shell](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react): ui composition · Exported DocxEditor surface and surrounding editor chrome, panels, dialogs, and controls. · `docx-editor/packages/react`
- [Paged editor](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/paged-editor): render host · React host for the paginated WYSIWYG document, selection overlays, and page interaction. · `docx-editor/packages/react/src/paged-editor`
- [File source](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/file-source): bytes lifecycle · Abstracts local files, authenticated modes, WOPI-style integration, autosave, and restore semantics. · `docx-editor/packages/react/src/file-source`
- [Plugin API](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/core/src/plugin-api): extension surface · Core and React plugin boundaries used to inject behavior without rewriting the editor. · `docx-editor/packages/core/src/plugin-api`
- [AI / DocOps](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/lib/writer): streamed assistants · Gated AI and document-operations subsystems with streamed responses and tool-driven mutations. · `docx-editor/packages/react/src/lib/writer`
- [Collab client](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/react/src/collab): sync provider · Browser-side collaboration provider exchanging updates, presence, and room metadata with the server. · `docx-editor/packages/react/src/collab`
- [DocOps package](https://github.com/casualoffice/docs/tree/main/docx-editor/packages/docops): assistant tooling · Shared agent, retrieval, and MCP tooling for document-oriented operations and integrations. · `docx-editor/packages/docops`

### Collaboration runtime

Node-based room server for live co-editing.

- [Collab server](https://github.com/casualoffice/docs/tree/main/collab): yjs websocket · Node collaboration backend based on Yjs and Hocuspocus rooms over WebSockets plus REST seed endpoints. · `collab`

### Delivery

Packaging, deployment, examples, and verification surfaces.

- [Examples](https://github.com/casualoffice/docs/tree/main/docx-editor/examples): embedders · Reference embeddings for Vite, Next.js, Remix, Astro, Vue, and collaboration demos. · `docx-editor/examples`
- [Quality checks](https://github.com/casualoffice/docs/tree/main/docx-editor/e2e): validation · Unit, Playwright, visual-fidelity, and round-trip audit pipelines that guard semantics and rendering fidelity. · `docx-editor/e2e`
- [Deployment](https://github.com/casualoffice/docs/tree/main/deploy): infra · Compose and deployment assets that support local development and production/self-hosted serving. · `deploy`
- [Round-trip audit](https://github.com/casualoffice/docs/blob/main/docx-editor/scripts/roundtrip-audit.mjs): fidelity script · Scripted parse-reserialize and render comparison checks used to catch OOXML fidelity regressions. · `docx-editor/scripts/roundtrip-audit.mjs`

## Connections

- Docker image → Editor repo: serves · Packages and serves the browser editor application.
- Docker image → Collab server: includes · Bundles the collaboration backend in the same runtime image.
- Editor repo → Core engine: contains · Core document engine lives inside the editor monorepo.
- Editor repo → React shell: contains · UI composition layer for the editor shell.
- Core engine → DOCX pipeline: owns · DOCX parsing and serialization boundary.
- Core engine → ProseMirror layer: maps to · Transforms DOCX content into the editable ProseMirror model and back.
- Core engine → Layout stack: drives · Feeds paginated layout and painting from the document model.
- Core engine → Plugin API: exposes · Provides extension points and registry machinery.
- React shell → Paged editor: composes · Builds the visible WYSIWYG editor around the paginated host.
- React shell → File source: abstracts · Routes open/save/autosave through file-source modes.
- React shell → Plugin API: hosts · Supports user and product extension at the UI layer.
- React shell → Collab client: syncs via · Connects editor state to live collaboration updates.
- React shell → AI / DocOps: surfaces · Exposes AI and doc-operations panels and actions.
- Paged editor → Layout stack: renders with · Uses the layout pipeline to paint pages, headers, tables, and text boxes.
- Collab client → Collab server: syncs · WebSocket/Yjs document updates and presence exchange.
- DocOps package → AI / DocOps: powers · Provides shared agent and retrieval tooling for document operations.
- Examples → React shell: embeds · Demonstrates the editor library inside host apps.
- Quality checks → Core engine: verifies · Covers parser, serializer, and layout fidelity.
- Quality checks → React shell: verifies · Covers editor workflows and UI behavior.
- Quality checks → Round-trip audit: includes · Round-trip audits are part of the fidelity guardrails.
- Deployment → Docker image: defines · Compose and production assets drive the deployment shape.
