English

Developer guide Overview

Architecture

The parts of Archipelego and how they talk to each other.

On this page

Archipelego is one Node server and one single-page app. The server syncs canvases, stores them, routes AI requests and serves the built app. The app draws the canvas and holds the shared document.

Overview

text
 Browser (wall, laptop, tablet, phone)
 +--------------------------------------------------+
 | React app (app/)                                 |
 |  Workspace: Canvas, Toolbox, Features panel,     |
 |  Inspector, Chat, Explain, Library, AI settings, |
 |  3D (lazy), docked or floating side panels       |
 |  Rich chat: Markdown, A2UI, MCP Apps (iframes)   |
 |  window.Archipelego (design-system bundle)       |
 |  Y.Doc  <->  IndexedDB (archipelego:<id>)        |
 +------------|---------------------|---------------+
              | WebSocket /yjs/<id> | HTTP /api/*, /docs/
 +------------v---------------------v---------------+
 | Node server (server/)                            |
 |  yroom.ts        Yjs rooms, saves <id>.yjs       |
 |  explain.ts      POST /api/explain (SSE)         |
 |  architect.ts    POST /api/architect (SSE)       |
 |  feature.ts      POST /api/feature (JSON)        |
 |  mcp.ts          /api/mcp/* MCP Apps host        |
 |  ai-routes.ts    catalog, keys, key test         |
 |  llm/router.ts -> llm/providers.ts -> providers  |
 |  llm/simulator.ts offline Architect              |
 |  llm/vault.ts    encrypted server keys           |
 |  library.ts      server/library/*.json           |
 |  static files    app/dist, docs-site/dist        |
 +--------------------------------------------------+

The client

  • app/src/App.tsx opens the room for the canvas id in the URL and renders Workspace. Workspace holds the camera, the tool, the selection, the theme, sound, the spotlight and which panels are open.
  • app/src/canvas/Canvas.tsx draws layers, blocks, frames, connections, post-its and remote cursors. It handles pan, pinch, wheel zoom, dragging, nesting and the layer warp.
  • The panels in app/src/panels/ are the toolbox, the inspector, the layer editor, Explain, the library, AI models and keys, the identity popover, the version chip and the dock frame.
  • app/src/chat/ChatPanel.tsx is the room chat, the @architect client and the Apps menu. app/src/chat/markdown.tsx renders message Markdown to React elements, never to HTML.
  • app/src/rich/ holds the rich chat UI: the A2UI v1.0 renderer in a2ui.tsx, the card frame in RichContent.tsx, and the MCP Apps host in mcpApp.tsx. See Rich chat UI.
  • app/src/features/ is Feature Architecture: the data model and draft cleaning in model.ts, and the Features panel and editor in FeaturesPanel.tsx. App.tsx runs the lens, the story player, presenting, following and drafting.
  • app/src/panels/Dockable.tsx docks the toolbox and the chat to their edge or floats them, and remembers the state per browser. Docked widths become insets that fit, spotlight and the lens frame around.
  • app/src/three/Scene3D.tsx is the 3D explorer. App.tsx loads it with lazy(), so three.js only downloads when someone opens 3D.
  • The design system bundle registers its components on window.Archipelego. app/src/ds/index.ts re-exports them for the app.

The sync server

Each canvas is a Yjs room at /yjs/<canvas id>. The server speaks the y-websocket protocol, keeps one Y.Doc per open room and saves it to <data folder>/<canvas id>.yjs. The server is also the only writer of the patch digit of the canvas version. See Sync server.

The HTTP API

All routes come from server/src/index.ts, server/src/ai-routes.ts and server/src/mcp.ts.

Method Path Purpose
GET /health Returns {"ok":true}.
POST /api/explain Narrates the canvas or one block, streamed as server-sent events.
POST /api/architect Answers an @architect question, streamed as server-sent events.
POST /api/feature Drafts a feature from one sentence. Answers one JSON object with the draft, the model and an A2UI review card. See Architect protocol.
GET /api/mcp/apps The tools that have a ui:// resource, across the built-in server and the configured remote servers.
POST /api/mcp/call Calls a tool. The body is { server, tool, arguments, canvasId }. Answers the MCP CallToolResult.
GET /api/mcp/resource?server=<name>&uri=<ui://...> Reads an app's ui:// resource. Answers { html, mimeType, meta }.
GET /api/ai/catalog The providers and models the router knows, and the providers the server can use with its own credentials.
GET /api/ai/keys?canvas=<id> The status of server keys for a canvas: provider, last four characters, date, and whether you own the key.
PUT /api/ai/keys/<provider>?canvas=<id> Stores a key for a canvas. Returns an owner token.
DELETE /api/ai/keys/<provider>?canvas=<id> Removes a key. Needs the owner token.
POST /api/ai/test Sends one short request to check a key.
GET /api/canvases Saved canvases on this server, newest first, at most 50.
GET /api/library The reference architectures.
POST /api/library/<id>/open Creates a new canvas from a reference architecture and returns its id.
GET /docs, /docs/... Serves the built docs site from docs-site/dist, or the folder in ARCHIPELEGO_DOCS. /docs redirects to /docs/. A missing page answers the site's 404.html.
GET any other path Serves the built app from app/dist, with index.html as the fallback.

The owner token travels in the x-owner-token header. Any other method on an unknown path returns 405.

The LLM router

Explain, the Architect and feature drafts never call a provider directly. They call routeStream in server/src/llm/router.ts. The router builds an ordered list of candidate models, keeps the ones whose provider has a key, and streams from the first one that answers. See LLM router.

The offline simulator

server/src/llm/simulator.ts is a deterministic stand-in for the Architect. simulateAnswer ranks blocks by the words of the question and lists how they connect, with a small A2UI card. simulateFeature grows a feature from the best-matching blocks along the canvas's own connections, and walks them into a main path, plus an exception path when a human-in-the-loop, a guardrail or a review block is nearby.

ARCHIPELEGO_AI_MOCK turns it on. With on, architect.ts and feature.ts fall back to it when the router fails with 401 because no provider has a key. With always, they use it before the router. The model is archipelego-simulator, provider archipelego, label "Offline simulator". Explain does not use the simulator.

The vault

server/src/llm/vault.ts stores the keys that people choose to keep on the server for one canvas.

  • Each key is encrypted with AES-256-GCM.
  • The ciphertext is bound to its canvas and provider as additional authenticated data.
  • The master key comes from ARCHIPELEGO_SECRET, or from a .vault.key file in the data folder.
  • The API only ever returns the last four characters.

Keys kept in the browser are encrypted with a non-extractable device key in IndexedDB, in app/src/ai/keystore.ts. The browser sends them with each AI request. The server uses them for that call only.

The library

server/src/library.ts lists the JSON files in the library folder. Opening an entry writes a brand-new canvas file with a fresh id, so every workshop gets its own copy. See Library format.

Streamed answers

/api/explain and /api/architect answer with text/event-stream. /api/feature waits for the whole draft and answers plain JSON. The events are:

Event Data Meaning
model id, provider, label, source The model that answers, and where its key came from: browser, server or platform.
skip id, reason A model failed before its first word. The router tries the next one.
text text The next piece of the answer.
done {} The answer is complete.
error message Nothing could answer. The message is written for people.

If the browser goes away, the server aborts the provider call.