Store

The Store serves as the primary data model in BlockSuite. Within BlockSuite, all data is managed using Yjs, a powerful framework for real-time collaboration.

Specifically, a BlockSuite document is structured as a tree and stored within a Y.Map, enabling efficient and collaborative data manipulation.

// pseudocode, some details are hidden
{
    "block1": {
        "sys:id": "block1",
        "sys:flavour": "affine:root",
        "sys:children": ["block2"]
    },
    "block2": {
        "sys:id": "block2",
        "sys:flavour": "affine:note",
        "sys:children": ["block3", "block4"]
    },
    "block3": {
        "sys:id": "block3",
        "sys:flavour": "affine:paragraph",
        "sys:children": [],
        "prop:type": "h1",
        "prop:text": [{ insert: "This is a heading" }]
    },
    "block4": {
        "sys:id": "block4",
        "sys:flavour": "affine:paragraph",
        "sys:children": [],
        "prop:type": [
            { "insert": "This is a " },
            { "insert": "normal", "attribute": { "background": "red" } },
            { "insert": " text"}
        ]
    }
}

This data describes a document like this: