# tahash/wayflow architecture

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

- Interactive diagram: https://gitdiagram.com/tahash/wayflow
- Repository: https://github.com/tahash/wayflow

## Overview

#### Purpose and public entry points
Wayflow is an embeddable, framework-agnostic TypeScript/DOM visual workflow editor and workflow execution stack. The package façade is `src/index.ts`; consumers primarily mount an editor through `createWorkflowEditor`, then attach a local or remote runtime. The monorepo separates graph semantics, editor rendering, UI composition, agent nodes, model adapters, and runtime transport.

#### Graph domain and execution planning
`packages/core/src/model.ts` defines the workflow graph model; analysis and execution ordering live in `packages/core/src/graph-analysis.ts` and `packages/core/src/execution.ts`. This layer owns graph structure, node/edge predicates, selection, history, viewport state, text utilities, and serialization. It is the provider- and UI-independent boundary: editors and runtimes consume the same workflow representation.
- `packages/core/src/model.ts`
- `packages/core/src/graph-analysis.ts`
- `packages/core/src/serializer.ts`

#### Editor shell, canvas, and interaction
The DOM package mounts and operates the editor without React/Vue/Svelte dependencies. `packages/dom/src/editor.ts` is the editor-facing integration point; rendering, pointer interaction, keyboard behavior, and persistence are split below it. It transforms core graph state into an interactive DOM canvas and emits edits/run requests toward the UI/runtime boundary.
- `packages/dom/src/editor.ts`
- `packages/dom/src/renderer.ts`
- `packages/dom/src/interaction.ts`

#### Product UI composition
The UI package supplies the complete workspace around the canvas: workflow editor shell, palette, inspector/configuration, run/result surfaces, approval UI, theming, responsive behavior, and mounting. It composes DOM editor capabilities with domain-specific controls rather than depending on an application framework.
- `packages/ui/src/workflow-editor.ts`
- `packages/ui/src/mount.ts`
- `packages/ui/src/result-panel.ts`

#### Agent workflow nodes
`packages/agent` provides higher-level node types for LLMs, images, tools, arrays/maps, operators, and validation. Its execution adapter interprets agent-oriented nodes on top of the generic graph executor. This is the bridge from visual AI/logic workflows to model dispatch and tool execution, while allowing custom node types and editor extensions.
- `packages/agent/src/node-types.ts`
- `packages/agent/src/execution.ts`
- `packages/agent/src/tools.ts`

#### Model-provider boundary
`packages/models` normalizes chat and image model invocation behind provider interfaces and dispatchers. OpenAI support and mock implementations are included, but graph/agent layers target the abstraction rather than a vendor. Handler logic covers streaming/tool-call accumulation and request/response schema/template concerns.
- `packages/models/src/provider.ts`
- `packages/models/src/dispatch.ts`
- `packages/models/src/openai.ts`

#### Local/server runtime and human-in-the-loop
`packages/runtime` runs graphs, manages sessions, exposes tools, and supports browser-to-server execution through a client/protocol/SSE boundary. The runtime is responsible for lifecycle events, async coordination, resumable sessions, handlers, logging, and graph workflows callable as tools. A browser editor can therefore execute locally or delegate the same graph to a backend runtime.
- `packages/runtime/src/runtime.ts`
- `packages/runtime/src/client.ts`
- `packages/runtime/src/sessions.ts`

#### Delivery surfaces
Runnable Vite examples demonstrate standalone embedding and server-backed execution; the backend example places runtime ownership in a Node server. Astro documentation is a separate site package and is not part of the library runtime.
- `examples/with-backend/server/index.ts`
- `examples/quickstart/main.ts`
- `docs/src/pages/docs/[...slug].astro`

Main entry points: [`packages/dom/src/editor.ts`](https://github.com/tahash/wayflow/blob/main/packages/dom/src/editor.ts) (DOM editor), [`packages/core/src/model.ts`](https://github.com/tahash/wayflow/blob/main/packages/core/src/model.ts) (Workflow graph model), [`packages/agent/src/execution.ts`](https://github.com/tahash/wayflow/blob/main/packages/agent/src/execution.ts) (Agent execution adapter), [`packages/runtime/src/runtime.ts`](https://github.com/tahash/wayflow/blob/main/packages/runtime/src/runtime.ts) (Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Graph Core"]
  node_graph_model["Workflow graph model<br/>domain model<br/>[model.ts]"]
  node_graph_analysis["Graph analysis<br/>planner<br/>[graph-analysis.ts]"]
  node_core_execution["Generic executor<br/>execution engine<br/>[execution.ts]"]
  node_serializer["Workflow serialization<br/>persistence<br/>[serializer.ts]"]
end

subgraph group_editor["Editor &amp; UI"]
  node_dom_editor["DOM editor<br/>editor integration<br/>[editor.ts]"]
  node_renderer["Canvas renderer<br/>DOM rendering<br/>[renderer.ts]"]
  node_interaction["Editor interaction<br/>input behavior<br/>[interaction.ts]"]
  node_ui_workspace["Workflow workspace<br/>UI composition<br/>[workflow-editor.ts]"]
  node_ui_mount["UI mounting<br/>mount API<br/>[mount.ts]"]
  node_result_panel["Run results<br/>UI surface<br/>[result-panel.ts]"]
end

subgraph group_execution["Execution Stack"]
  node_agent_nodes["Agent node types<br/>node catalog<br/>[node-types.ts]"]
  node_agent_execution["Agent execution adapter<br/>node interpreter<br/>[execution.ts]"]
  node_agent_tools["Agent tools<br/>tool integration<br/>[tools.ts]"]
  node_model_provider["Model provider interfaces<br/>provider boundary<br/>[provider.ts]"]
  node_model_dispatch["Model dispatcher<br/>model execution<br/>[dispatch.ts]"]
  node_openai_adapter["OpenAI adapter<br/>provider adapter<br/>[openai.ts]"]
  node_runtime["Runtime<br/>[runtime.ts]"]
  node_runtime_client["Runtime client<br/>remote transport<br/>[client.ts]"]
  node_sessions[("Resumable sessions<br/>session store<br/>[sessions.ts]")]
end

subgraph group_delivery["Delivery Surfaces"]
  node_backend_example["Backend example<br/>Node server example<br/>[index.ts]"]
  node_quickstart["Quickstart example<br/>Vite example<br/>[main.ts]"]
  node_docs["Documentation site<br/>Astro site<br/>[&#91;...slug&#93;.astro]"]
end

node_package_facade["Package facade<br/>public API<br/>[index.ts]"]

node_package_facade -->|"exports shared graph API"| node_graph_model
node_package_facade -->|"exposes editor"| node_dom_editor
node_graph_model -->|"analyzed as"| node_graph_analysis
node_graph_analysis -->|"plans execution"| node_core_execution
node_graph_model -->|"serialized"| node_serializer
node_graph_model -->|"editor state"| node_dom_editor
node_dom_editor -->|"renders through"| node_renderer
node_dom_editor -->|"handles edits through"| node_interaction
node_ui_mount -->|"mounts"| node_ui_workspace
node_ui_workspace -->|"composes canvas"| node_dom_editor
node_ui_workspace -->|"shows run output"| node_result_panel
node_graph_model -->|"defines agent graph nodes"| node_agent_nodes
node_agent_nodes -->|"interpreted by"| node_agent_execution
node_agent_execution -->|"uses generic executor"| node_core_execution
node_agent_execution -->|"invokes"| node_agent_tools
node_agent_execution -->|"dispatches model nodes"| node_model_dispatch
node_model_dispatch -->|"targets interfaces"| node_model_provider
node_openai_adapter -->|"implements"| node_model_provider
node_runtime -->|"runs agent workflows"| node_agent_execution
node_runtime -->|"manages"| node_sessions
node_runtime_client -.->|"remote execution protocol"| node_runtime
node_dom_editor -.->|"delegates remote runs"| node_runtime_client
node_quickstart -->|"embeds"| node_ui_mount
node_backend_example -->|"hosts"| node_runtime

click node_package_facade "https://github.com/tahash/wayflow/blob/main/src/index.ts"
click node_graph_model "https://github.com/tahash/wayflow/blob/main/packages/core/src/model.ts"
click node_graph_analysis "https://github.com/tahash/wayflow/blob/main/packages/core/src/graph-analysis.ts"
click node_core_execution "https://github.com/tahash/wayflow/blob/main/packages/core/src/execution.ts"
click node_serializer "https://github.com/tahash/wayflow/blob/main/packages/core/src/serializer.ts"
click node_dom_editor "https://github.com/tahash/wayflow/blob/main/packages/dom/src/editor.ts"
click node_renderer "https://github.com/tahash/wayflow/blob/main/packages/dom/src/renderer.ts"
click node_interaction "https://github.com/tahash/wayflow/blob/main/packages/dom/src/interaction.ts"
click node_ui_workspace "https://github.com/tahash/wayflow/blob/main/packages/ui/src/workflow-editor.ts"
click node_ui_mount "https://github.com/tahash/wayflow/blob/main/packages/ui/src/mount.ts"
click node_result_panel "https://github.com/tahash/wayflow/blob/main/packages/ui/src/result-panel.ts"
click node_agent_nodes "https://github.com/tahash/wayflow/blob/main/packages/agent/src/node-types.ts"
click node_agent_execution "https://github.com/tahash/wayflow/blob/main/packages/agent/src/execution.ts"
click node_agent_tools "https://github.com/tahash/wayflow/blob/main/packages/agent/src/tools.ts"
click node_model_provider "https://github.com/tahash/wayflow/blob/main/packages/models/src/provider.ts"
click node_model_dispatch "https://github.com/tahash/wayflow/blob/main/packages/models/src/dispatch.ts"
click node_openai_adapter "https://github.com/tahash/wayflow/blob/main/packages/models/src/openai.ts"
click node_runtime "https://github.com/tahash/wayflow/blob/main/packages/runtime/src/runtime.ts"
click node_runtime_client "https://github.com/tahash/wayflow/blob/main/packages/runtime/src/client.ts"
click node_sessions "https://github.com/tahash/wayflow/blob/main/packages/runtime/src/sessions.ts"
click node_backend_example "https://github.com/tahash/wayflow/blob/main/examples/with-backend/server/index.ts"
click node_quickstart "https://github.com/tahash/wayflow/blob/main/examples/quickstart/main.ts"
click node_docs "https://github.com/tahash/wayflow/blob/main/docs/src/pages/docs/%5B...slug%5D.astro"

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_graph_model,node_graph_analysis,node_core_execution,node_serializer toneBlue
class node_dom_editor,node_renderer,node_interaction,node_ui_workspace,node_ui_mount,node_result_panel toneAmber
class node_agent_nodes,node_agent_execution,node_agent_tools,node_model_provider,node_model_dispatch,node_openai_adapter,node_runtime,node_runtime_client,node_sessions toneMint
class node_backend_example,node_quickstart,node_docs toneRose
class node_package_facade toneNeutral
```

## Components

### Graph Core

Provider- and UI-independent workflow representation and planning.

- [Workflow graph model](https://github.com/tahash/wayflow/blob/main/packages/core/src/model.ts): domain model · Shared graph, state, and workflow representation. · `packages/core/src/model.ts`
- [Graph analysis](https://github.com/tahash/wayflow/blob/main/packages/core/src/graph-analysis.ts): planner · Analyzes graph structure and execution order. · `packages/core/src/graph-analysis.ts`
- [Generic executor](https://github.com/tahash/wayflow/blob/main/packages/core/src/execution.ts): execution engine · Executes planned generic workflows. · `packages/core/src/execution.ts`
- [Workflow serialization](https://github.com/tahash/wayflow/blob/main/packages/core/src/serializer.ts): persistence · `packages/core/src/serializer.ts`

### Editor & UI

Framework-agnostic DOM editing and workspace composition.

- [DOM editor](https://github.com/tahash/wayflow/blob/main/packages/dom/src/editor.ts): editor integration · Mounts the interactive editor and emits edits or run requests. · `packages/dom/src/editor.ts`
- [Canvas renderer](https://github.com/tahash/wayflow/blob/main/packages/dom/src/renderer.ts): DOM rendering · `packages/dom/src/renderer.ts`
- [Editor interaction](https://github.com/tahash/wayflow/blob/main/packages/dom/src/interaction.ts): input behavior · Pointer and keyboard editing behavior. · `packages/dom/src/interaction.ts`
- [Workflow workspace](https://github.com/tahash/wayflow/blob/main/packages/ui/src/workflow-editor.ts): UI composition · Composes canvas, palette, inspector, approval, and run surfaces. · `packages/ui/src/workflow-editor.ts`
- [UI mounting](https://github.com/tahash/wayflow/blob/main/packages/ui/src/mount.ts): mount API · `packages/ui/src/mount.ts`
- [Run results](https://github.com/tahash/wayflow/blob/main/packages/ui/src/result-panel.ts): UI surface · `packages/ui/src/result-panel.ts`

### Execution Stack

Agent interpretation, model dispatch, and local or remote runtime.

- [Agent node types](https://github.com/tahash/wayflow/blob/main/packages/agent/src/node-types.ts): node catalog · LLM, image, tool, collection, operator, and validation nodes. · `packages/agent/src/node-types.ts`
- [Agent execution adapter](https://github.com/tahash/wayflow/blob/main/packages/agent/src/execution.ts): node interpreter · Maps agent-oriented nodes onto generic execution. · `packages/agent/src/execution.ts`
- [Agent tools](https://github.com/tahash/wayflow/blob/main/packages/agent/src/tools.ts): tool integration · `packages/agent/src/tools.ts`
- [Model provider interfaces](https://github.com/tahash/wayflow/blob/main/packages/models/src/provider.ts): provider boundary · Vendor-neutral chat and image invocation contracts. · `packages/models/src/provider.ts`
- [Model dispatcher](https://github.com/tahash/wayflow/blob/main/packages/models/src/dispatch.ts): model execution · Handles provider calls, streaming, and tool-call accumulation. · `packages/models/src/dispatch.ts`
- [OpenAI adapter](https://github.com/tahash/wayflow/blob/main/packages/models/src/openai.ts): provider adapter · `packages/models/src/openai.ts`
- [Runtime](https://github.com/tahash/wayflow/blob/main/packages/runtime/src/runtime.ts): graph runtime · Runs graphs and coordinates handlers, lifecycle, logging, and tools. · `packages/runtime/src/runtime.ts`
- [Runtime client](https://github.com/tahash/wayflow/blob/main/packages/runtime/src/client.ts): remote transport · Browser-to-server execution client and protocol boundary. · `packages/runtime/src/client.ts`
- [Resumable sessions](https://github.com/tahash/wayflow/blob/main/packages/runtime/src/sessions.ts): session store · Maintains runtime session state across async and approval flows. · `packages/runtime/src/sessions.ts`

### Delivery Surfaces

Embedding examples and separate documentation site.

- [Backend example](https://github.com/tahash/wayflow/blob/main/examples/with-backend/server/index.ts): Node server example · Places runtime ownership on a server. · `examples/with-backend/server/index.ts`
- [Quickstart example](https://github.com/tahash/wayflow/blob/main/examples/quickstart/main.ts): Vite example · Demonstrates standalone embedding. · `examples/quickstart/main.ts`
- [Documentation site](https://github.com/tahash/wayflow/blob/main/docs/src/pages/docs/%5B...slug%5D.astro): Astro site · Separate documentation delivery surface. · `docs/src/pages/docs/[...slug].astro`

### Other components

- [Package facade](https://github.com/tahash/wayflow/blob/main/src/index.ts): public API · Primary consumer entry point. · `src/index.ts`

## Connections

- Package facade → Workflow graph model: exports shared graph API
- Package facade → DOM editor: exposes editor
- Workflow graph model → Graph analysis: analyzed as
- Graph analysis → Generic executor: plans execution
- Workflow graph model → Workflow serialization: serialized
- Workflow graph model → DOM editor: editor state
- DOM editor → Canvas renderer: renders through
- DOM editor → Editor interaction: handles edits through
- UI mounting → Workflow workspace: mounts
- Workflow workspace → DOM editor: composes canvas
- Workflow workspace → Run results: shows run output
- Workflow graph model → Agent node types: defines agent graph nodes
- Agent node types → Agent execution adapter: interpreted by
- Agent execution adapter → Generic executor: uses generic executor
- Agent execution adapter → Agent tools: invokes
- Agent execution adapter → Model dispatcher: dispatches model nodes
- Model dispatcher → Model provider interfaces: targets interfaces
- OpenAI adapter → Model provider interfaces: implements
- Runtime → Agent execution adapter: runs agent workflows
- Runtime → Resumable sessions: manages
- Runtime client → Runtime: remote execution protocol
- DOM editor → Runtime client: delegates remote runs
- Quickstart example → UI mounting: embeds
- Backend example → Runtime: hosts
