Developer guide Internals
Data model
The shared Yjs document behind every canvas, and the portable canvas file.
On this page
A canvas is one Yjs document. Everyone in the room edits the same document, and the server saves it as one file. The types live in app/src/model/types.ts, app/src/chat/model.ts and app/src/features/model.ts.
The document
openRoom exposes six maps of one Y.Doc:
| Map | Key | Value |
|---|---|---|
blocks |
block id | Block |
links |
link id | Link |
notes |
note id | Note |
chat |
message id | ChatMsg |
features |
feature id | Feature |
meta |
a name | a string |
Each value is replaced as a whole when it changes. For example, moving a block sets a new Block object with new x and y.
The meta map
| Key | Value |
|---|---|
title |
The canvas title. |
version |
major.minor.patch, for example 1.4.12. |
layers |
The layer set, as a JSON string of LayerDef[]. Absent means the default four layers. |
ai |
The router settings of the canvas, as a JSON string of AIConfig. |
source |
The library entry id, when the canvas was opened from the library. |
Blocks
export interface Block {
id: string;
kind: Kind;
x: number;
y: number;
w: number;
h: number;
title: string;
subtitle?: string;
/** The container (capability or zone) this block sits in. */
parent?: string;
}kindis one of the 34 kind keys in the design system'sKINDStable, such asagentorvectorstore.x,y,wandhare world pixels at 100% zoom.parentpoints to a block of kindcapabilityorzonethat contains this one.
Links
export type LinkKind = 'sync' | 'async' | 'flow';
export interface Link {
id: string;
from: string;
to: string;
kind: LinkKind;
label?: string;
}from and to are block ids. flow is an information flow, drawn with running dashes.
Notes
export interface Note {
id: string;
text: string;
color: StickyColor; // 'yellow' | 'pink' | 'blue' | 'green' | 'violet'
/** World position when free; ignored while attached. */
x: number;
y: number;
attach?: { type: 'block' | 'link'; id: string; dx: number; dy: number };
author: { name: string; critter: string; color: string };
createdAt: number;
}A pinned note keeps an offset (dx, dy) from its target, so it follows the block or connection.
Layers
export interface LayerDef {
id: string;
name: string;
/** Height in world pixels, a whole number of grid steps. */
height: number;
}Layers stack from y = 0 downwards, in array order. A block belongs to the band that contains its vertical centre.
| Constant | Value |
|---|---|
GRID |
24 |
NODE_W |
168 (7 grid steps) |
NODE_H |
96 (4 grid steps) |
LAYER_BAND |
GRID * 12, the default band height |
MIN_BAND |
GRID * 8 |
MAX_BAND |
GRID * 120 |
DEFAULT_LAYERS holds the four built-in layers: experience (Experience), apps (Applications & Agents), data (Data & Platforms) and infra (Infrastructure). Each one is LAYER_BAND high. resizeLayer moves every block below the resized band in the same transaction, so no block changes layer by accident.
Chat messages
export interface ChatMsg {
id: string;
at: number;
text: string;
author?: ChatAuthor;
/** The Architect speaking. */
ai?: boolean;
status?: 'thinking' | 'streaming' | 'done' | 'error';
model?: { id: string; provider: string; label: string };
/** Who asked the Architect (their name), so only they get the automatic spotlight. */
askedBy?: string;
/** Blocks this message is about (the selection when it was sent). */
about?: string[];
}Block references inside text are [[block-id]] tokens. See Architect protocol.
Features
A feature is a lens over the canvas. It references existing blocks by id and never copies them.
export interface FeatureStep {
id: string;
title: string;
narration: string;
/** The block the step starts at. */
from: string;
/** The block the step goes to; absent for a step that happens inside one block. */
to?: string;
}
export interface Scenario {
id: string;
name: string;
steps: FeatureStep[];
}
export interface Feature {
id: string;
name: string;
description?: string;
blockIds: string[];
scenarios: Scenario[];
source: 'manual' | 'ai';
createdBy?: string;
updatedAt: number;
}- A step travels along the link between its two blocks, in either direction, when one exists (
linkBetween). - Every block that a step uses is a member of the feature (
withStepMembers). - An Architect draft passes through
cleanDraft. It drops unknown block ids and steps that lose their start, and keeps at most 6 scenarios of at most 16 steps. - Presenting to the room is not stored in the document. The presenter publishes
present(featureId,scenarioId,step) in awareness, and the other screens follow.
Ids
newId(prefix) returns the prefix plus nine random base-36 characters.
| Prefix | Used for |
|---|---|
b_ |
blocks |
l_ |
links |
n_ |
notes |
m_ |
chat messages |
layer_ |
layers added in the layer editor |
f_ |
features |
s_ |
scenarios |
st_ |
feature steps |
A canvas id is 32 random bytes in URL-safe base64: 43 characters. It sits in the c query parameter of the link. The server accepts room names that match ^[A-Za-z0-9_-]{1,64}$.
Versions
- A new canvas starts at
1.0.0. - The server adds one to the patch digit 1.5 seconds after a burst of edits settles.
- The server never bumps on its own writes or when it loads a file.
- A transaction that only changes
meta.versionis not bumped. This is how people set a new minor or major version from the version chip. - A malformed version restarts at
1.0.1.
Deleting a block
deleteBlock runs in one transaction:
- Blocks inside the deleted block move up to its own container. They are never deleted with it.
- Notes pinned to the block stay on the canvas, unpinned, where they were.
- Every feature forgets the block, with the steps that start or end there (
forgetBlock). - Links from or to the block are deleted.
The portable file
Export, import, the HTML export and the library all use CanvasFile:
export interface CanvasFile {
format: 'archipelego';
version: 1;
title: string;
/** The guided layer set; absent in files from before layers were stored. */
layers?: LayerDef[];
blocks: Block[];
links: Link[];
notes?: Note[];
/** Feature architectures over this canvas. */
features?: Feature[];
}parseCanvasFile in app/src/model/io.ts rejects files without format: 'archipelego'. It drops blocks with an unknown kind or no position. Features keep only the blocks and steps that exist in the file. loadFile replaces the canvas content in one transaction and keeps only links whose two ends exist. The chat is not part of the file.