Skip to content

Architecture

Felix is one pnpm workspace: sixteen packages under packages/ and five apps under apps/. The packages hold the runtime and the shared presentation code; the apps choose providers, tools, storage and the screen, and compose the packages into something you run. The tables below cover the core ones. The others are @felix/lookups (tools over public services), @felix/mcp (MCP tools), @felix/quickjs (the script engine), @felix/skills (the Agent Skills format), @felix/storage (the hosted stores, their clients and the partition host, over a portable key-value contract), @felix/telemetry, @felix/workflows (the workflow interpreter) and @felix/workspace (the browser workspace), and apps/evals runs live scenarios through the terminal client, and checks harness prompts it does not run against the same model.

These three make a run happen. None of them imports a Node or Cloudflare API, so the same code runs in the Worker, in Node and in tests.

Package Owns Does not own
@felix/ai Messages, the Model interface, completeModel for one inference, message and conversation validation, provider error types, the provider adapters (Workers AI, Anthropic, OpenAI, OpenAI-compatible, Google Gemini and Vertex AI, Mistral, Amazon Bedrock), image and classifier models, SSE decoding. Tools, the loop, sessions, configuration, storage.
@felix/agent runAgent: the tool loop, tool parsing, the beforeTool gate and afterTool hook, parallel batches, budgets, retries, steering and context hooks, and the order of checkpoints and events. Persistence, which tools exist, approval records, HTTP.
@felix/harness The Session interface, prompt (history checks, then the user checkpoint, then the run), the prompt queue, compaction, closing interrupted calls, and the child-agent supervisor. Storage adapters, locks and leases, instruction files, credentials.

@felix/ai exports its providers and fixtures on separate paths, so importing the core does not pull them in:

Export Contents
@felix/ai The provider-neutral contract.
@felix/ai/workers-ai workersAiModel (over an injected run function, such as the Worker’s AI binding) and workersAiRestModel.
@felix/ai/anthropic anthropicModel.
@felix/ai/openai-responses, /openai-compatible, /google, /mistral, /bedrock, /aws The other model providers, and the AWS request signing Bedrock uses.
@felix/ai/workers-ai-images, /openai-images, /google-images, /openrouter-images, /workers-ai-classifier, /system-one Image generation and classifier models.
@felix/ai/workers-ai-transcription Workers AI speech-to-text.
@felix/ai/sse The SSE decoder, shared with the HTTP client.
@felix/ai/testing, @felix/ai/testing/anthropic, @felix/ai/testing/bedrock Scripted models and provider wire fixtures for tests and the demo.

@felix/harness/demo is the credential-free scripted run behind pnpm demo, the terminal client’s --demo and the API’s /demo route. Outside tests, it is the only code that imports the testing fixtures.

Package Owns Does not own
@felix/protocol The versioned run request and event frames, thread and health shapes, their paths, and the validators both ends use. Any HTTP client or server.
@felix/client A fetch client for run streams, threads and health, built on the protocol. Credentials are passed in by the caller. Server code, React, caching.
@felix/transcript The view-agnostic transcript model the web and terminal transcripts both read: turns, tool cards, plans, and parsing of tool-result shapes. Rendering, conversation state.
@felix/ui React controls, the shared mark, and styles. App state, networking.
@felix/design Design tokens and the mark’s geometry, used by the web app, the terminal client and this site. Components.
App Owns
apps/api The Cloudflare Worker: HTTP routing and authentication, provider selection from its bindings, the backpressured SSE stream, and hosted thread storage (revisions, leases, limits) on SQLite-backed Durable Objects.
apps/web The React app: conversation and thread state, browser storage, server reads through TanStack Query, and the screens.
apps/cli The felix terminal client: configuration, the workspace file tools, the write prompt, instruction files, locked session files, and the full-screen renderer.
apps/docs This site.

An app is never a dependency of another workspace. Platform code stays in the app that runs on the platform: the stores are portable (@felix/storage), and the Durable Object adapter that hosts them is in apps/api; the filesystem tools and session files are in apps/cli.

What runs where in a Felix deployment, and what each part needsTwo Workers make a deployment. The felix-next Worker answers felix.run: its static assets serve the web app built from apps/web, falling back to index.html for unknown paths, and only /api/*, /v1/* and /health run the Worker first. The Worker's fetch handler routes every API request and counts /v1 routes against the RATE_LIMITER binding. Hosted conversation runs, rejoins and stops go to the RUNS namespace, one ThreadRuns Durable Object per thread id, which executes the run so it outlives the request. Threads, leases and approvals live in THREADS, SQLite-backed ThreadDatabase objects. With FELIX_STORES=postgres and FELIX_THREAD_INDEX=read, as felix.run sets them, people, the audit log, settings, workflow records and connections are in Postgres tables reached through the STORES and CONNECTIONS Hyperdrive bindings, and thread lists and search read the THREAD_INDEX copy there; unset, those stores are THREADS objects too. TELEMETRY keeps run spans and metrics. Images, skill files and workspace files are in three R2 buckets. Runs call Workers AI through the AI binding by default, or another provider over HTTPS when FELIX_PROVIDER or a FELIX_MODELS entry selects it, and use BROWSER for fetch_url and LOADER for run_script. FelixWorkflow, on FELIX_WORKFLOWS, runs workflow definitions. FelixBackup, on FELIX_BACKUPS, has a daily schedule that backs up THREADS, the Postgres tables and the R2 buckets to an S3-compatible destination only when FELIX_BACKUP is on. The ThreadSandbox container, one Linux machine per thread, is bound as SANDBOX and runs only when FELIX_SANDBOX is on. Each binding is optional in the code and switches its feature on. The separate felix-docs Worker serves this site's static files on docs.felix.run with no runtime code.felix-next Worker — felix.runHTTPSHTTPS/api/*, /v1/*, /healthrun the Worker firsthosted runs, events, stopthread readspeople, audit, lists, searchlease, append messagesmodel calls by defaultover HTTPSrun spansimages, skill and workspacefilestool callsshell tools, when boundstart and decide runsdefinitions, run recordsreads THREADS and R2reads the tablessealed snapshots,only with FELIX_BACKUP=onBrowser, felix CLI,API clientsStatic assetsapps/web/dist,SPA fallbackfetch handlerrouting, auth,RATE_LIMITERRUNS ·ThreadRunsone object perthreadFELIX_WORKFLOWSFelixWorkflowFELIX_BACKUPS ·FelixBackupdaily 03:17 UTCSANDBOX ·ThreadSandboxcontaineroff untilFELIX_SANDBOX=onTHREADS ·ThreadDatabaseSQLite: threads,leases, approvalsPostgres viaHyperdrivepeople, audit,settings, indexTELEMETRYspans and metricsR2: IMAGES,SKILLS,WORKSPACESBROWSER,LOADERfetch_url,run_scriptfelix-docs Workerstatic assets,docs.felix.runWorkers AI via theAI bindingOther modelproviderswhenFELIX_PROVIDERor aFELIX_MODELSentry names oneS3-compatiblebackupdestinationDeployment topology
What runs where in a Felix deployment, and what does each part need?Drawn from docs/diagrams/deploy-topology.mmd, which follows apps/api/wrangler.jsonc (env.workers-ai, env.workers-ai-sandbox), apps/api/src/config.ts:Env and apiConfig, apps/api/src/main.ts, apps/api/src/storage/stores.ts, apps/docs/wrangler.jsonc..
How POST /v1/runs/stream reaches the model and the threadThe Worker's entry first applies the jurisdiction gate, which can answer 503 for a bad FELIX_JURISDICTION or 409 while restricted storage is not ready, and strips an /api prefix so the web app's /api/v1 paths reach the same routes. The app then identifies the caller once, as the operator token or a signed-in person's session, and counts the request against RATE_LIMITER at 10 units, refusing with 429 rate_limited. routeChat checks the bearer token (401) and reads the body (413 over 128 KiB, 400 when it is not JSON). A stateless request, or any request on a deployment without RUNS, runs in this request. A hosted request is checked for thread access (404 thread_not_found) and replayed to the thread's ThreadRuns Durable Object, which refuses with 409 run_in_progress while a run is in flight and otherwise records the run in its storage and executes it on its own signal, so the run outlives the client. Either way chatResponse validates the request and, for a hosted thread, takes the writer lease in THREADS at the revision sent, refused with 409 stale_revision or run_in_progress. The harness's prompt then runs the agent loop, which streams from the model, Workers AI through the AI binding by default, and appends each committed message to the thread at the lease's revision. The run's events leave as server-sent frames.10 units a requeststateless, or no RUNSthreadId: thread access,then POST /startin-flight record saved,run on its own signalacquire at revisionModel.streamappend each messageat the lease's revisioneventResponse, seestream-path429 rate_limited401, 413, 400409 run_in_progress409 stale_revision,404 thread_not_foundWorker entryjurisdiction gate,strip /apiidentifyoperator token orsessionRATE_LIMITERrouteChattoken, body ≤ 128KiBchatResponsevalidate, take theleaseThreadRunsone per thread idTHREADSThreadDatabaseprompt, thenrunAgent@felix/harness,@felix/agentWorkers AIbinding by defaultSSE frames to theclientRefused beforeany runPOST /v1/runs/stream request path
How does POST /v1/runs/stream reach the model and the thread?Drawn from docs/diagrams/request-path.mmd, which follows apps/api/src/index.ts:fetch, apps/api/src/app.ts:createApp (fetch, routeChat), apps/api/src/runs/run-host.ts:createRunHost (start), apps/api/src/routes/chat.ts:chatResponse..
ai ◄── agent ◄── harness
▲
└── protocol ◄── client
api ─► ai, agent, harness, protocol, client, lookups, mcp, skills, storage, telemetry, workflows
cli ─► ai, agent, harness, protocol, client, lookups, mcp, quickjs, skills, telemetry, transcript, design
web ─► ai, client, protocol, skills, transcript, workspace, ui, design
docs ─► protocol, design
evals ─► ai, agent, harness, protocol

ai depends on no other Felix package. agent depends on ai, and harness on both. protocol uses the message types from ai; client depends on protocol and the SSE decoder from ai. transcript, ui and design depend on no other Felix package. The web app reaches the runtime only over HTTP: it imports neither agent nor harness.

pnpm check runs the structural checks in .agents/skills/felix-architecture/scripts/check.ts before the type checks. Its boundary check reads every source file in every workspace and fails on:

Rule Example it rejects
Undeclared dependency Importing a package the workspace’s package.json does not list.
Non-public import Importing a path another package does not list in its exports.
Relative import across workspaces ../../packages/ai/src/types.ts from an app.
App as a dependency Any import of an app from another workspace.
Platform API in a package node:fs or cloudflare:workers in non-test code under packages/.
Uncheckable loading A dynamic import() or require() with a computed path.
Runtime dependency cycle Two workspaces that depend on each other.

Tests may import Node APIs and declared dev dependencies. Production package type checks run without Node’s ambient types, and tests are type-checked separately. See Testing for the full verification command.

.agents/skills/felix-architecture/scripts/conventions.ts declares the repository’s structure as data: each workspace, what it owns, the Felix workspaces it uses, and the purpose of each top-level src/ folder. The same pnpm check step, also available as pnpm structure, fails on:

Rule Example it rejects
Unregistered workspace A new packages/* folder with no entry.
Workspace shape A package without private, "type": "module", a check script, or a tsconfig.json that excludes src/test/**.
Undeclared internal dependency A @felix/* dependency the entry’s uses does not list.
Undeclared folder A new top-level src/ folder with no purpose.
Misplaced test A name.test.ts or name.browser.ts outside src/test/, or a src/test/ folder with no src/ counterpart.
Name A file or folder that is not kebab-case (Astro components are PascalCase), or a generic name such as utils or helpers.

The checks run against conventions.ts itself too: a declared folder, dependency, or exception that no longer exists fails, so the file stays accurate.