How casualoffice/docs works
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: react React shell · core Core engine · e2e Quality checks · docx-editor Editor repo
Components 18
Repository
Top-level monorepo with browser editor and collaboration backend.
- Docker image · 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 · Browser-side monorepo containing the core engine, React UI, examples, and supporting packages.
docx-editor - Core engine · Canonical document engine for DOCX parsing, model conversion, serialization, and fidelity-preserving round trips.
docx-editor/packages/core - DOCX pipeline · 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 · Internal schema, commands, plugins, marks, nodes, and document transformations used for editing semantics.
docx-editor/packages/core/src/prosemirror - Layout stack · Bridge, measuring, pagination, and painting pipeline that produces Word-like paged rendering.
docx-editor/packages/core/src/layout-engine - React shell · Exported DocxEditor surface and surrounding editor chrome, panels, dialogs, and controls.
docx-editor/packages/react - Paged editor · React host for the paginated WYSIWYG document, selection overlays, and page interaction.
docx-editor/packages/react/src/paged-editor - File source · Abstracts local files, authenticated modes, WOPI-style integration, autosave, and restore semantics.
docx-editor/packages/react/src/file-source - Plugin API · Core and React plugin boundaries used to inject behavior without rewriting the editor.
docx-editor/packages/core/src/plugin-api - AI / DocOps · Gated AI and document-operations subsystems with streamed responses and tool-driven mutations.
docx-editor/packages/react/src/lib/writer - Collab client · Browser-side collaboration provider exchanging updates, presence, and room metadata with the server.
docx-editor/packages/react/src/collab - DocOps package · 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 · Node collaboration backend based on Yjs and Hocuspocus rooms over WebSockets plus REST seed endpoints.
collab
Delivery
Packaging, deployment, examples, and verification surfaces.
- Examples · Reference embeddings for Vite, Next.js, Remix, Astro, Vue, and collaboration demos.
docx-editor/examples - Quality checks · Unit, Playwright, visual-fidelity, and round-trip audit pipelines that guard semantics and rendering fidelity.
docx-editor/e2e - Deployment · Compose and deployment assets that support local development and production/self-hosted serving.
deploy - Round-trip audit · Scripted parse-reserialize and render comparison checks used to catch OOXML fidelity regressions.
docx-editor/scripts/roundtrip-audit.mjs
Connections 21
- 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.