Skip to content

Architecture

Knetik is a Hono server on Node that hosts the Flue agent runtime, a stage executor, a SQLite store and a React dashboard. The same core also runs on Cloudflare Workers, with D1 and R2 as the store.

Path Package What
packages/sdk @knetikdotdev/sdk defineModule, stage helpers, ctx types, module UI validation. What a module imports.
packages/core @knetikdotdev/core SQL storage (SQLite on Node, D1 on Cloudflare), the stage executor, artifacts, the HTTP API, the event stream
packages/cli @knetikdotdev/cli The knetik command
packages/testing @knetikdotdev/testing runModule and mockConnector
packages/ai @knetikdotdev/ai ctx.ai (chat, search, image), safe page fetch, the same as agent tools
packages/connectors @knetikdotdev/connectors Encrypted vault, Slack, Google and MCP OAuth, connections API
packages/auth @knetikdotdev/auth Sessions, allowlist, magic link, GitHub, Firebase
packages/client @knetikdotdev/client Typed API client, stream helper, derivations
packages/ui @knetikdotdev/ui The design-system component library
apps/web @knetikdotdev/web The dashboard (React, its own Vite build)
apps/server @knetikdotdev/server The host: a Flue app on Node that mounts the API and serves the dashboard
apps/docs @knetikdotdev/docs This site
flowchart TD
  Browser[Dashboard] -->|JSON and SSE| API[HTTP API]
  API --> Executor[Stage executor]
  API --> DB[(SQLite or D1)]
  Executor --> DB
  Executor -->|agent stages| Flue[Flue runtime]
  Executor -->|code stages| Module[Module code]
  Flue -->|model calls| Providers[Model providers]
  Module -->|ctx.connectors| Connectors[Slack, Google, MCP]
  Module -->|ctx.ai, ctx.fetchPage| AI[AI service]

The server also serves the built dashboard at / and the sign-in pages. The dashboard talks only to /api.

A module’s process is a list of stages. The executor owns a small state machine on top of Flue:

  • each agent stage runs as a Flue submission, and the executor picks the next stage when it completes;
  • each code stage runs in process with a ctx;
  • a gate stores a pending item in the database and ends the turn. A person’s decision arrives through an authenticated route and the run resumes.

Run state, outputs, gate decisions, attempts, history and the event timeline are rows in the database. A run is therefore never a waiting process: it survives restarts. On start-up the executor resumes runs that were mid-flight.

After a crash, a stage may run again. Agent stages carry an attempt counter, so a retry after a failed submission is a new submission. External effects must be idempotent, and ctx.artifacts.put already is.

Before each stage the executor asks the connector service whether the connectors the stage needs are usable. If not, the run goes to blocked and continues when the connection is fixed.

Flue on Node has one live owner per conversation, and the executor continues work after a request returns. Hence one Node instance, with its data folder on a persistent volume. On Cloudflare each run is driven by its own Durable Object, so this rule does not apply there. See Hosting.

Store Holds
knetik.db (SQLite) on Node, D1 on Cloudflare Runs, run events, artifact metadata, module config overrides, sessions, users, connections (encrypted), migrations
Flue’s own store (flue.db) Agent conversations on Node
Files in the data folder on Node, R2 on Cloudflare Artifact bytes

On Node everything lives in one data folder, KNETIK_DATA_DIR. Core sees the database only as a Pool with query, batch and end; sqlitePool and fsStore (from @knetikdotdev/core/node) and d1Pool and r2Store (from @knetikdotdev/core/cloudflare) implement it. There are no interactive transactions: each state change is a single guarded statement, and multi-statement changes use an atomic batch.

Migrations are versioned and idempotent. On Cloudflare they are generated SQL files applied with wrangler d1 migrations apply.

D1 limits shape a few things: a row is at most 2 MB, so a run’s stage outputs must stay under about 1.5 MB in total (larger content goes in an artifact); search terms are cut to 45 bytes; times are ISO-8601 text with millisecond precision.

Modules live in their own repos. knetik add vendors a module’s runtime files into apps/server/src/modules/<id>/ because Flue only discovers agents under the server’s source root. It records the source, commit and integrity hash in knetik.modules.json and regenerates modules.generated.ts. Modules never import @knetikdotdev/core; they talk to the host only through ctx.

  • Trust. Modules are trusted first-party code with no sandbox. knetik add shows connectors and scopes for review and records an approver.
  • Sign-in fails closed. The server refuses to start with auth on and no base URL, allowlist or method. Sessions are hashed, revocable and HttpOnly.
  • Origin guard on state-changing requests.
  • Artifacts are untrusted. Served sandboxed with a restrictive content policy.
  • Connector tokens are encrypted with AES-256-GCM, bound to the connection id.
  • Safe page fetch validates the connected address, re-checks redirects, and caps size and time.
  • Model output is never trusted as markup. The content creator’s renderer escapes everything and re-creates a few tags, with links limited to https.
  • Prompt injection. Fetched text is fenced and labelled untrusted. The structural defenses are that agents cannot publish and that a person approves before anything leaves the system.

See each topic’s page, and in particular Hosting: one instance, coarse authorization, no API tokens, and modules fixed at image build time.