How facebook/lexical works
Main Components
• Core Engine (“lexical” package)
• Extension Packages (e.g. lexical-code, lexical-markdown, lexical-yjs, etc.)
• Framework Bindings (lexical-react)
• Developer Tools (lexical-devtools browser extension)
• Example Apps & Playground (examples/ and packages/lexical-playground)
• Documentation Site (lexical-website)
• CI/CD Pipeline & External Services (GitHub Actions, npm registry)
Relationships & Data Flows
• Extensions depend on the Core Engine.
• Framework Bindings import Core + Extensions to expose React APIs.
• Example Apps import Framework Bindings (and possibly some Extensions) to render live editors.
• Playground → Exercise the full stack: Core → Extensions → React Bindings → Browser DOM
• Devtools Extension:
• background scripts communicate with browser (tabs)
• content scripts inject code into the page to hook the editor
• DevTools panel UI fetches editor state via messaging with content/background
• Documentation Site: static site generator reads package metadata and MDX docs to produce public website
• CI Pipeline: GitHub Actions runs tests → publishes packages to npm → deploys website
Architectural Patterns
• Monorepo workspace pattern (all packages live in a single repo)
• Publishable packages pattern (each subfolder under packages/ is its own npm module)
• Plugin architecture in Core Engine (registerCommands, node transforms)
• Double buffering model in Core Engine (current vs pending EditorState)
• React “hooks + components” pattern in lexical-react
Technologies & Frameworks
• Node.js + npm workspaces / Lerna-like scripts
• TypeScript + Flow (type systems in various packages)
• Jest for unit tests, Playwright for e2e
• Docusaurus for website
• Vite for example apps bundling
• GitHub Actions for CI/CD
Layered Views
To avoid clutter, consider two layers:
A. Package Architecture (monorepo structure)
B. Runtime Architecture (how an end-user’s browser, devtools extension, and examples interact with Core + Extensions + Bindings)
Key Points to Capture
• The Core Engine is dependency-free and is extended via plugins.
• All extensions and framework bindings flow from the Core.
• Publishing pipeline: code → version bump → npm publish → website regeneration.
• DevTools is a complex browser extension with multiple entrypoints: background, content, injected, and panel.
• Examples and Playground demonstrate usage of Core + Extensions + Bindings in a Vite-powered environment.
• the modular composition of Lexical (Core + Extensions + Bindings)
• how code moves from development through CI to npm and website
• the runtime interactions in both example apps and the devtools extension