How casualoffice/sheets works
1. Top-level shape
- This is a monorepo for a spreadsheet product with three main runtime surfaces: the self-hosted web app in apps/web, the backend in apps/server, and the embeddable SDK in packages/sdk.
- The repo also contains docs, Playwright E2E tests, Docker assets, and a pinned Univer fork workspace under vendor/ for upstream spreadsheet-engine work.
2. Primary runtime deployment
- In the deployed product, a single container serves the built SPA, exposes HTTP APIs, and hosts the collaboration WebSocket endpoint.
- Redis is an optional sidecar used for room persistence and Yjs update storage; without it, the app can run in transient in-memory mode.
- The same server handles both anonymous “open a workbook” usage and named room-based co-editing via /r/:roomId.
3. Backend boundary: HTTP + WebSocket collaboration
- apps/server is the backend boundary for room lifecycle, seed upload/download, snapshot upload/download, room diagnostics, health checks, and the /yjs WebSocket upgrade path.
- The collaboration protocol is Yjs/Hocuspocus over WebSocket, with Fastify used for the HTTP layer and direct WS routing for sync traffic.
- Room password checks, snapshot preflight, and client counts are all server concerns rather than frontend concerns.
4. Frontend editor shell
- apps/web is the main browser application, built with React, TypeScript, and Vite.
- Its role is not just rendering sheets, but providing the Office-like shell around the engine: title bar, menus, ribbon, dialogs, right-side panels, status bar, and mobile variants.
- The large shell/ subtree is the UI command surface; home/, auth/, admin/, and collab/ are separate app-level flows around the editor.
5. Spreadsheet engine integration
- The editor is layered on Univer OSS, with apps/web/src/univer* and related context/hooks acting as the glue between the custom UI and the spreadsheet engine.
- This layer is where workbook, sheet, theme, zoom, plugins, formula execution, and engine-level policy are wired together.
- The repo emphasizes an engine boundary: the shell drives commands into Univer, rather than reimplementing spreadsheet mechanics in React.
6. Collaboration data flow
- Shared editing state flows through Yjs documents, presence tracking, and room metadata.
- The collab/ area handles avatar presence, live cursors, view-only mode, share links, room join metadata, and op-log related UI.
- The key architectural boundary is that collaboration is not only visual: some enforcement, such as view-only mutation blocking, happens at the engine layer.
7. File I/O pipeline
- Workbook import/export is split off from the main UI and done in workers to avoid blocking the main thread on large files.
- apps/web/src/xlsx and packages/sdk/src/xlsx handle .xlsx parsing/serialization; ODS and CSV/TSV support is also present.
- The repository treats Excel fidelity as a first-class pipeline: comments, drawings, tables, pivots, conditional formatting, data validation, and other workbook metadata are round-tripped where possible.
8. Worker and off-main-thread architecture
- Heavy operations are intentionally isolated in Web Workers: xlsx parsing/export, formula worker execution, and some embed/runtime work.
- This keeps interaction responsive while opening large files, exporting, or recalculating formulas.
- The apps/web/src/ai/*, univer/formula-worker.ts, and packages/sdk/src/xlsx/*worker* files show this pattern repeated across features.
9. Storage and persistence modes
- The product supports multiple storage modes: anonymous ephemeral use, personal mode with persisted user/workbook data, and WOPI-style integration for host-managed documents.
- Personal mode introduces an admin panel and authenticated user/workbook scoping, with local storage or other configured backends.
- Autosave and recent-file features use browser-side persistence such as IndexedDB, while room collaboration persistence lives server-side.
10. SDK / embed surface
- packages/sdk is a separate package boundary for embedding the editor in another product.
- It exposes a CasualSheets React component, embed transports, chrome primitives, collab helpers, and workbook import/export utilities.
- The SDK is designed as a data boundary: the host app provides initial data and receives snapshots back on save/exit, rather than the SDK owning persistence.
11. Admin and customization layer
- The apps/web/src/admin subtree is the runtime admin UI for configuring deployment concerns such as branding, storage, networking, auth, limits, and webhooks.
- This is distinct from the editor surface; it configures the server/product instance rather than workbook content.
- The docs indicate this is the place to wire JWT/OIDC/SAML-style customization and webhook integrations.
12. Feature modules around the core editor
- The repo has feature-oriented subsystems for charts, pivots, outlines, sparklines, comments, version history, file sources, recovery, print/export, and autosave.
- These modules generally sit between the shell and the engine: they present UI, issue workbook commands, and sometimes persist auxiliary resources.
- They are important diagram nodes because they explain the product’s breadth without being separate services.
13. External dependencies that matter architecturally
- Univer OSS is the spreadsheet engine, Yjs/Hocuspocus is the collaboration fabric, Redis is the optional state backend, and Playwright is the system test harness.
- ExcelJS and SheetJS are the key file-format dependencies; React/Vite/TypeScript define the UI runtime; Docker is the default deployment unit.
- The repository also carries a Univer fork reference in vendor/, but the main product is built around the OSS upstream package set.
14. Quality gates and delivery
- The architecture is backed by extensive unit and E2E coverage, with many tests focused on collaboration, file fidelity, and spreadsheet UX regressions.
- CI/CD, Docker publishing, and Pages deployment are first-class in the repo, indicating the project is shipped as both a hosted app and a distributable image/package.
Main entry points: shell Editor shell · main.tsx Web entry · index.ts SDK entry · e2e E2E tests
Components 22
Web app
Main browser application for the spreadsheet editor and product shell.
- Web entry · Browser application bootstrap and routing entrypoints.
apps/web/src/main.tsx - Editor shell · Office-like chrome around the spreadsheet engine: menus, ribbon, dialogs, panels, status, and mobile UI.
apps/web/src/shell - Univer glue · Adapters, hooks, and facades that wire the custom shell into Univer OSS.
apps/web/src/univer - Collab UI · Avatar, cursor, room metadata, view-only behavior, and share-link collaboration surfaces.
apps/web/src/collab - File pipeline · Spreadsheet import/export, worker offloading, and workbook format fidelity handling.
apps/web/src/xlsx - Home flows · Home screen, templates, recent files, restore banners, and pinned-folder UX.
apps/web/src/home - Auth flows · Login, signup, account, and personal-mode gating for authenticated workbook access.
apps/web/src/auth - Admin UI · Runtime admin console for branding, storage, networking, auth, limits, and webhooks.
apps/web/src/admin - Feature modules · Charts, pivots, outlines, sparklines, autosave, recovery, version history, and other feature subsystems.
apps/web/src
Server
Backend boundary for HTTP APIs, collaboration, and deployment serving.
- Server entry · Backend bootstrap for HTTP APIs, health, diagnostics, room lifecycle, and collaboration upgrade routing.
apps/server - Yjs bridge · WebSocket collaboration endpoint and sync traffic handling for shared workbook rooms.
apps/server - Room storage · Room metadata, snapshots, seed upload/download, and optional Redis-backed Yjs update storage.
apps/server - HTTP APIs · HTTP surface for room lifecycle, snapshot preflight, password checks, client counts, health checks, and diagnostics.
apps/server
SDK
Embeddable editor package and its supporting transports and workbook pipelines.
- SDK entry · Public package surface for embedding and browser-hosted editor integration.
packages/sdk/src/index.ts - CasualSheets · Embeddable React editor surface with host-driven data boundaries and save/exit snapshot flow.
packages/sdk/src/sheets/CasualSheets.tsx - Embed transport · Host/editor messaging protocol and transport helpers for embedded deployments.
packages/sdk/src/embed - SDK collab · WebSocket URL, attach helpers, and replay logic for collaborative embed mode.
packages/sdk/src/collab - SDK xlsx · Worker-based parse/serialize/export pipeline with format passthrough resources and fidelity handling.
packages/sdk/src/xlsx
Ops & docs
Deployment, documentation, CI, and validation assets.
- Docs · Repository documentation for deployment, storage modes, collaboration, SDK, and product behavior.
docs - E2E tests · End-to-end coverage for editor UX, collaboration, file fidelity, embed flows, and regression scenarios.
tests/e2e - Ops & build · Docker, compose, workflows, scripts, and package-level build/release infrastructure.
Dockerfile
Vendor
Pinned upstream spreadsheet-engine workspace and fork-related assets.
- Univer fork · Pinned vendor workspace for upstream spreadsheet-engine work and fork integration.
vendor
Connections 35
- Web entry → Editor shell: renders · Bootstraps the editor shell and app-level UI surfaces.
- Web entry → Univer glue: initializes · Wires the browser app into the spreadsheet engine layer.
- Web entry → Home flows: routes · Switches between home and editor-style application flows.
- Web entry → Auth flows: routes · Mounts login, signup, and personal-mode gates.
- Web entry → Admin UI: routes · Mounts the admin configuration console.
- Editor shell → Univer glue: drives · Issues workbook commands into Univer rather than reimplementing spreadsheet mechanics.
- Editor shell → Collab UI: shows · Surfaces room state, presence, and view-only indicators.
- Editor shell → File pipeline: imports/exports · Connects user actions to workbook file I/O and export flows.
- Editor shell → Feature modules: hosts · Provides UI entry points for charts, pivots, version history, recovery, and related modules.
- Collab UI → Feature modules: feeds · Collaboration state informs comments, presence, and room-aware UX.
- File pipeline → Univer glue: serializes · Transforms engine state to and from workbook file formats.
- Feature modules → Univer glue: commands · Feature modules coordinate workbook actions through the engine boundary.
- Auth flows → Home flows: gates · Personal mode and account state influence landing and reopening flows.
- Admin UI → HTTP APIs: configures · Admin settings are persisted and applied through backend-facing APIs.
- Server entry → HTTP APIs: serves · Exposes HTTP endpoints for product and room lifecycle concerns.
- Server entry → Yjs bridge: upgrades · Routes `/yjs` collaboration traffic to WebSocket sync handling.
- HTTP APIs → Room storage: reads/writes · Room, snapshot, and diagnostic operations persist via the storage layer.
- Yjs bridge → Room storage: syncs · Collaboration updates and room state can be persisted or kept transient.
- SDK entry → CasualSheets: exports · Primary public editor component surface.
- SDK entry → Embed transport: exports · Embedding transport and protocol primitives.
- SDK entry → SDK collab: exports · Collaboration helpers for embedded use.
- SDK entry → SDK xlsx: exports · Workbook import/export utilities are part of the SDK boundary.
- CasualSheets → Embed transport: uses · Embed host transport coordinates data exchange with the parent app.
- CasualSheets → SDK xlsx: loads/saves · Embedded sheets rely on the SDK workbook codec pipeline.
- SDK collab → Yjs bridge: connects to · SDK collaboration clients speak the same WebSocket sync protocol as the server.
- SDK xlsx → File pipeline: shares codec · Web app and SDK share the workbook import/export architecture.
- E2E tests → Editor shell: covers · Validates the main editor UX and command surface.
- E2E tests → Yjs bridge: covers · Exercises room co-editing and sync behavior.
- E2E tests → CasualSheets: covers · Checks embed surface behavior and host integration.
- E2E tests → SDK xlsx: covers · Covers fidelity and round-trip workbook pipelines.
- Docs → Server entry: documents · Explains deployment, storage modes, collaboration, and self-hosting.
- Docs → SDK entry: documents · Describes the SDK and embed integration model.
- Ops & build → Server entry: builds · Container and release tooling package the backend and serving model.
- Ops & build → E2E tests: runs · CI and local scripts execute the Playwright suite.
- Ops & build → Univer fork: pins · Repository maintenance includes a vendorized upstream workspace.