# toeverything/blocksuite architecture

> Architecture diagram of the GitHub repository toeverything/blocksuite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toeverything/blocksuite
- Repository: https://github.com/toeverything/blocksuite

## Overview

##### Overall Project Purpose and Type
- BlockSuite is designed as an editor framework that provides a set of reusable core libraries (data store, inline editing, block modeling) along with high-level prebuilt editing components (editors such as PageEditor and EdgelessEditor, UI widgets, fragments, etc.).
- Its purpose is to enable the creation of collaborative, real-time, rich-content editing applications with support for custom blocks, inline embeds, CRDT-based collaboration (Yjs), and a component-oriented architecture using native web components.

##### File Structure
- The file tree is extensive with various top-level folders such as “packages/framework,” “packages/blocks,” “packages/presets,” “packages/playground,” etc. Each “packages” directory represents a different facet:
- Framework packages (e.g., @blocksuite/store, @blocksuite/inline, @blocksuite/block-std) provide the core headless logic.
- Component packages (e.g., @blocksuite/blocks and @blocksuite/presets) offer user interfaces built on top of the framework.
- The “playground” package supplies demo apps and experimentation environments.
- There are several configuration, build, and test files scattered across the repository, confirming a modular design where each package is self-contained, yet interdependent.

##### Main Components & Architectural Layers
A. Headless Framework (Core Infrastructure)
- @blocksuite/store: Acts as the data model layer for collaborative documents. It is built atop Yjs, supporting real-time CRDT updates, time-travel debugging, and document snapshots.
- @blocksuite/inline: Provides minimal, modular rich-text editing capabilities that can be integrated within blocks.
- @blocksuite/block-std: Supplies the abstraction for editable blocks, handling aspects like block structure, events, selection, clipboard support, and rendering.

B. UI Component Layer
- @blocksuite/blocks: Contains default implementations of editable blocks and widgets used within the editors.
- @blocksuite/presets: Houses pre-built editors (e.g., PageEditor, EdgelessEditor) and other UI fragments like CopilotPanel, DocTitle, and various toolbar components.
- These components are built as native web components, ensuring framework-agnostic use (possible integration with React, Vue, etc.).

C. Additional Supporting and Testing Tools:
- “playground” and “examples” packages: These are demo apps and test harnesses that integrate both core modules and UI components in sample editors.
- “scripts” and “tests”: They represent automation, codemods, and comprehensive testing of features (e.g., collaboration tests, CRDT consistency, command execution, clipboard).

(Include these as supplementary modules that support development and integration testing.)

##### Relationships and Interactions Between Components
- The Data Layer (store) delivers a consistent state model across documents. It interacts with the inline and block-std packages to synchronize content state.
- UI Components (from blocks and presets) consume the document state from the store and render interactive editors. They also handle user events (keyboard shortcuts, drag-and-drop, formatting commands) and then pass these commands to the lower-level framework modules.
- Some utilities (e.g., for CRDT synchronization, state scheduling, transformers for markdown/HTML) act as bridges between persistent storage and the dynamic editing sessions.

##### Architectural Patterns and Technologies
- Component-driven Architecture: Each package is self-contained with clear APIs for intercommunication.
- Layered/Modular Design: Separation of data (store, CRDT, block-std) and presentation (blocks, presets). This mirrors the separation between the headless framework and the pre-baked editors.
- Real-Time Collaboration: Integration of Yjs for CRDT functionalities.
- Web Components: UI is built on native web components, ensuring encapsulation and framework-agnostic reuse.
- Command & Event-Driven Mechanism: The system uses commands and events (e.g., for clipboard actions, keyboard events, GFX events) that propagate from the UI layer down to the core logic.
- Testing and Build Pipeline: The extensive tests and scripts indicate an internal CI/CD pipeline and monorepo integration strategy.

##### Final Touches
- Component is clearly annotated with its responsibilities and any key technologies (for example, “Store – powered by Yjs, supports CRDT and real-time collaboration”).
- Maintain clarity by grouping related packages (e.g., group all framework packages on one side).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Headless Framework (Logic / Data)"
        st("Store (CRDT engine - Yjs)"):::core
        in("Inline Editing Module"):::core
        bs("Block Standard (Block Modeling)"):::core
    end

    subgraph "UI Component Layer"
        ub("UI Blocks (Web Components)"):::ui
        pr("Presets/Editors (Pre-built UI)"):::ui
    end

    subgraph "Supporting Tools"
        pl("Playground/Demo Applications"):::support
    end

    st -->|"state-update"| ub
    st -->|"state-update"| pr
    ub -->|"command"| in
    ub -->|"command"| bs
    pr -->|"command"| in
    pr -->|"command"| bs
    in -->|"sync"| st
    bs -->|"sync"| st

    pl --> legend["Legend:\nHeadless Framework - Blue\nUI Components - Green\nSupporting Tools - Pink"]:::legend

    click st "https://github.com/toeverything/blocksuite/tree/master/packages/framework/store"
    click in "https://github.com/toeverything/blocksuite/tree/master/packages/framework/inline"
    click bs "https://github.com/toeverything/blocksuite/tree/master/packages/framework/block-std"
    click ub "https://github.com/toeverything/blocksuite/tree/master/packages/blocks"
    click pr "https://github.com/toeverything/blocksuite/tree/master/packages/presets"
    click pl "https://github.com/toeverything/blocksuite/tree/master/packages/playground"

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef support fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef legend fill:#FFFFE0,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
```
