# toeverything/affine architecture

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

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

## Overview

AFFiNE is a local-first workspace combining document editing, an edgeless canvas, and planning features such as databases. The main user workflow is to create or edit block-based content, arrange it in document or canvas views, and retain or synchronize workspace data. The README documents collaboration and multimodal AI; the tree identifies relevant modules, but their full wiring is not shown in the sampled source, so those links are kept broad and evidence limits are noted.

Main entry points: [`blocksuite/affine/all/src/index.ts`](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/index.ts) (BlockSuite entry), [`blocksuite/affine/all/src/store/index.ts`](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/store/index.ts) (Document storage), [`blocksuite/affine/all/src/foundation/store.ts`](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/foundation/store.ts) (Editor foundation), [`blocksuite/affine/all/src/blocks/note/index.ts`](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/note/index.ts) (Document blocks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_editing["Editing surface"]
  node_editor["BlockSuite entry<br/>[index.ts]"]
  node_foundation["Editor foundation<br/>[store.ts]"]
  node_widgets["Editing controls<br/>[index.ts]"]
  node_outline["Document navigation<br/>[index.ts]"]
end

subgraph group_content["Content and canvas"]
  node_notes["Document blocks<br/>[index.ts]"]
  node_text["Text and inline content<br/>[index.ts]"]
  node_canvas["Edgeless canvas<br/>[index.ts]"]
  node_graphics["Canvas objects<br/>[index.ts]"]
  node_embeds["Embeds and links<br/>[index.ts]"]
  node_tables["Database views<br/>[index.ts]"]
  node_data_views["Data view system<br/>[index.ts]"]
  node_adapters["Content adapters<br/>[index.ts]"]
end

subgraph group_workspace["Workspace data"]
  node_doc_store["Document storage<br/>[index.ts]"]
  node_sync["Workspace sync<br/>[index.ts]"]
  node_blob_engine["Blob synchronization<br/>[engine.ts]"]
  node_native_store[("Local SQLite storage<br/>[storage.rs]")]
  node_snapshots[("Document snapshots<br/>[doc_storage.rs]")]
end

subgraph group_ai["AI and integrations"]
  node_ai_loop["AI tool loop<br/>[engine.rs]"]
  node_copilot_blobs["Copilot attachments<br/>[storage.ts]"]
  node_link_preview["Link previews"]
end

node_user(("Workspace user"))

node_user -->|"edits in"| node_editor
node_editor -->|"uses editor core"| node_foundation
node_editor -->|"provides controls"| node_widgets
node_editor -->|"composes blocks"| node_notes
node_notes -->|"contains text"| node_text
node_editor -->|"opens canvas"| node_canvas
node_canvas -->|"arranges objects"| node_graphics
node_editor -->|"inserts embeds"| node_embeds
node_editor -->|"uses databases"| node_tables
node_tables -->|"offers views"| node_data_views
node_editor -->|"navigates documents"| node_outline
node_editor -->|"imports and exports"| node_adapters
node_foundation -->|"stores document state"| node_doc_store
node_doc_store -->|"persists locally"| node_native_store
node_doc_store -->|"synchronizes workspace"| node_sync
node_sync -->|"syncs blobs"| node_blob_engine
node_doc_store -.->|"stores snapshots"| node_snapshots
node_user -.->|"requests AI work"| node_ai_loop
node_ai_loop -.->|"uses attachments"| node_copilot_blobs
node_embeds -.->|"requests previews"| node_link_preview

click node_editor "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/index.ts"
click node_foundation "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/foundation/store.ts"
click node_widgets "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/widgets/toolbar/index.ts"
click node_outline "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/fragments/outline/index.ts"
click node_notes "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/note/index.ts"
click node_text "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/paragraph/index.ts"
click node_canvas "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/surface/index.ts"
click node_graphics "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/gfx/shape/index.ts"
click node_embeds "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/embed/index.ts"
click node_tables "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/database/src/index.ts"
click node_data_views "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/data-view/src/index.ts"
click node_adapters "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/database/src/adapters/index.ts"
click node_doc_store "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/store/index.ts"
click node_sync "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/sync/index.ts"
click node_blob_engine "https://github.com/toeverything/affine/blob/canary/blocksuite/framework/sync/src/blob/engine.ts"
click node_native_store "https://github.com/toeverything/affine/blob/canary/packages/frontend/native/nbstore/src/storage.rs"
click node_snapshots "https://github.com/toeverything/affine/blob/canary/packages/backend/native/src/runtime/backend_runtime/doc_storage.rs"
click node_ai_loop "https://github.com/toeverything/affine/blob/canary/packages/backend/native/src/llm/host/tool_loop/engine.rs"
click node_copilot_blobs "https://github.com/toeverything/affine/blob/canary/packages/backend/server/src/plugins/copilot/storage.ts"
click node_link_preview "https://github.com/toeverything/affine/blob/canary/blocksuite/affine/shared/src/services/link-preview-service/link-preview-service.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_editor,node_foundation,node_widgets,node_outline,node_user toneBlue
class node_notes,node_text,node_canvas,node_graphics,node_embeds,node_tables,node_data_views,node_adapters toneAmber
class node_doc_store,node_sync,node_blob_engine,node_native_store,node_snapshots toneMint
class node_ai_loop,node_copilot_blobs,node_link_preview toneRose
```

## Components

### Editing surface

- [BlockSuite entry](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/index.ts): `blocksuite/affine/all/src/index.ts`
- [Editor foundation](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/foundation/store.ts): `blocksuite/affine/all/src/foundation/store.ts`
- [Editing controls](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/widgets/toolbar/index.ts): `blocksuite/affine/all/src/widgets/toolbar/index.ts`
- [Document navigation](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/fragments/outline/index.ts): `blocksuite/affine/all/src/fragments/outline/index.ts`

### Content and canvas

- [Document blocks](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/note/index.ts): `blocksuite/affine/all/src/blocks/note/index.ts`
- [Text and inline content](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/paragraph/index.ts): `blocksuite/affine/all/src/blocks/paragraph/index.ts`
- [Edgeless canvas](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/surface/index.ts): `blocksuite/affine/all/src/blocks/surface/index.ts`
- [Canvas objects](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/gfx/shape/index.ts): `blocksuite/affine/all/src/gfx/shape/index.ts`
- [Embeds and links](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/blocks/embed/index.ts): `blocksuite/affine/all/src/blocks/embed/index.ts`
- [Database views](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/database/src/index.ts): `blocksuite/affine/blocks/database/src/index.ts`
- [Data view system](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/data-view/src/index.ts): `blocksuite/affine/blocks/data-view/src/index.ts`
- [Content adapters](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/blocks/database/src/adapters/index.ts): `blocksuite/affine/blocks/database/src/adapters/index.ts`

### Workspace data

- [Document storage](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/store/index.ts): `blocksuite/affine/all/src/store/index.ts`
- [Workspace sync](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/all/src/sync/index.ts): `blocksuite/affine/all/src/sync/index.ts`
- [Blob synchronization](https://github.com/toeverything/affine/blob/canary/blocksuite/framework/sync/src/blob/engine.ts): `blocksuite/framework/sync/src/blob/engine.ts`
- [Local SQLite storage](https://github.com/toeverything/affine/blob/canary/packages/frontend/native/nbstore/src/storage.rs): `packages/frontend/native/nbstore/src/storage.rs`
- [Document snapshots](https://github.com/toeverything/affine/blob/canary/packages/backend/native/src/runtime/backend_runtime/doc_storage.rs): `packages/backend/native/src/runtime/backend_runtime/doc_storage.rs`

### AI and integrations

- [AI tool loop](https://github.com/toeverything/affine/blob/canary/packages/backend/native/src/llm/host/tool_loop/engine.rs): `packages/backend/native/src/llm/host/tool_loop/engine.rs`
- [Copilot attachments](https://github.com/toeverything/affine/blob/canary/packages/backend/server/src/plugins/copilot/storage.ts): `packages/backend/server/src/plugins/copilot/storage.ts`
- [Link previews](https://github.com/toeverything/affine/blob/canary/blocksuite/affine/shared/src/services/link-preview-service/link-preview-service.ts): `blocksuite/affine/shared/src/services/link-preview-service/link-preview-service.ts`

### Other components

- **Workspace user**

## Connections

- Workspace user → BlockSuite entry: edits in
- BlockSuite entry → Editor foundation: uses editor core
- BlockSuite entry → Editing controls: provides controls
- BlockSuite entry → Document blocks: composes blocks
- Document blocks → Text and inline content: contains text
- BlockSuite entry → Edgeless canvas: opens canvas
- Edgeless canvas → Canvas objects: arranges objects
- BlockSuite entry → Embeds and links: inserts embeds
- BlockSuite entry → Database views: uses databases
- Database views → Data view system: offers views
- BlockSuite entry → Document navigation: navigates documents
- BlockSuite entry → Content adapters: imports and exports
- Editor foundation → Document storage: stores document state
- Document storage → Local SQLite storage: persists locally
- Document storage → Workspace sync: synchronizes workspace
- Workspace sync → Blob synchronization: syncs blobs
- Document storage → Document snapshots: stores snapshots
- Workspace user → AI tool loop: requests AI work
- AI tool loop → Copilot attachments: uses attachments
- Embeds and links → Link previews: requests previews
