跪拜 Guibai
← All articles
Frontend

No SaaS, No Sales Calls: lingyi-doc Gives Teams a Self-Hosted Docs System With CRDT, MCP, and One Docker Command

By AN ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Self-hosting collaborative documents used to require a full team and deep pockets; lingyi-doc shows a solo engineer can ship real-time sync, AI agent access, and on-prem deployment with open-source code. It also puts a concrete number on how AI shifts a senior developer's job from typing code to making and owning architectural decisions.

Summary

lingyi-doc grew out of a single frontend engineer's refusal to hand a company's core documents to a SaaS vendor. The project now runs inside that company, with dozens of teams and over a thousand people writing requirements, weekly reports, and knowledge base entries daily. It is published on GitHub as an open-source repository with a demo at lingyidoc.com, and it ships multi-dimensional tables, a mind-map/whiteboard canvas, real-time collaboration, import/export, and one-command Docker self-hosting.

Under the hood, the collaboration stack uses CRDT (conflict-free replicated data types) plus HLC (hybrid logical clocks) over WebSocket, rejecting OT because of its server-side complexity. An MCP server (spec 2024-11-05) exposes the knowledge base to Cursor, Claude Desktop, and custom agents through Streamable HTTP, with tokens separated from user JWTs and scopes like kb:read, doc:read, and ai:rag. The core engine ships as npm packages (@lingyi-doc/core, @lingyi-doc/editor, @lingyi-doc/mind-map) so teams can embed tables and diagrams in their own products.

AI wrote roughly 80% of the code (boilerplate, CRUD, test drafts, comments) by the developer's own accounting. Architecture, the hardest choices (CRDT vs OT), review, and acceptance stayed with a human—and that remaining 20% of judgment, not API recall, is the value a ten-year frontend veteran claims to retain in the AI era.

Takeaways
— lingyi-doc is open-sourced at https://github.com/James-Nie/lingyi-doc; an online demo runs at https://lingyidoc.com.
— Inside the company, dozens of teams and over a thousand people use it daily for requirements, weekly reports, and knowledge base management.
— AI wrote roughly 80% of the code—boilerplate, repeated components, CRUD, test drafts, and documentation comments; architecture and acceptance stayed with a human.
— Real-time collaboration uses CRDT + HLC over WebSocket, chosen over OT because OT demands complex server-side transformation logic.
— The MCP server implements Streamable HTTP on spec 2024-11-05, with scoped permissions (kb:read/write, doc:read/write, ai:rag) and Bearer tokens separated from user JWTs.
— Self-hosting requires Node.js 18+, MySQL 8/PostgreSQL 15, and Redis 6+, and can be brought up with `npm run docker:up -- --with-mysql --migrate`.
— The core engine ships as npm packages @lingyi-doc/core, @lingyi-doc/editor, and @lingyi-doc/mind-map for embedding into other products.
— Open-source code covers collaboration, import/export (DOCX/XLSX/Markdown), knowledge base, and MCP; AI assistant and RAG remain commercial-licensed.
Conclusions

AI first drafts frequently fall short of usable, and several rewrite rounds are normal, so the 80% code-generation figure comes with a nontrivial review tax that the fast-demo stories omit.

MCP tokens are separated from login JWTs and scoped per resource; that separation lets agent credentials be revoked without touching human accounts, and it's a pattern any team wiring AI to internal docs should copy.

Treating documents as company data leads to self-hosting as the product's foundation, with AI assistant and RAG kept commercial while the core is open source; that's a defensible line for a project that must survive in compliance-heavy environments.

Concepts & terms
CRDT
Conflict-free Replicated Data Type. A data structure that lets multiple replicas merge independent updates without a central coordinator, automatically resolving concurrent edits so offline work can sync without destructive conflict.
OT (Operational Transformation)
A technique for collaborative editing where concurrent operations are transformed against each other on a server to converge to the same document state; the article rejects it in favor of CRDT due to server-side complexity.
HLC (Hybrid Logical Clock)
A timestamp that combines a physical clock with a logical counter, giving causally ordered event IDs that are stable across offline and reconnect, which is needed for CRDT merges.
MCP (Model Context Protocol)
An open protocol (spec 2024-11-05) that lets AI agents read and write external data sources—here, a document/knowledge base—through a standardized HTTP endpoint with bearer-token scopes.
RAG (Retrieval-Augmented Generation)
A pattern where a model answers with retrieved context, here used for vector search over the knowledge base; it's kept under a commercial license in this project.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗