# Werker architecture

> How the repository is divided into apps and packages, what each one owns, and the tools that check it.

Source: https://werker.cloud/docs/engineering/architecture (updated 2026-12-01)

How the repository is divided into apps and packages, what each one
owns, and the tools that check it.

The processes and the limits that follow from them are in
[how it's built](../how-its-built.md).

## Package structure

```
apps/app/              SvelteKit UI and Node server; calls core, and
                       uses rules for pure logic the browser shares
apps/site/             Public site, docs, blog and waiting list; UI and rules only
apps/reels/            The web app's pages as scripted demos for the site
apps/worker/           Starts the run engine; enqueue script
apps/cli/              The command werker, for npm; types only
packages/ui/           Theme, logo and UI primitives; no dependencies
packages/domain/       Shared types; no dependencies
packages/rules/        Deterministic decisions over domain values
packages/db/           Postgres access, migrations, row-level security
packages/connections/  Provider adapters, secrets, capability bindings
packages/auth/         Sign-in, sessions, workspaces and roles (Better Auth)
packages/core/         Use cases the apps call
packages/runtime/      Run engine: queue claims, Pi harness, workflows
packages/scripts/      Runs an assistant's script in its own process
tools/checks/          Executable package and import boundaries
docs/                  Generated glossary of the docs in apps/site
```

Packages use the `@werkerai` npm scope. The project domain is
`werker.cloud`: the public site is at the apex and the app at
`app.werker.cloud`, both deployed on Coolify
([public site](site-plan.md),
[Coolify](../self-hosting.md#on-coolify)).

Source entrypoints are under each package's `src/index.ts`.

## Dependency direction

| Package     | May depend on                        |
| ----------- | ------------------------------------ |
| domain      | nothing                              |
| rules       | domain                               |
| db          | domain                               |
| connections | domain, rules                        |
| auth        | domain, db                           |
| core        | domain, rules, db, connections, auth |
| runtime     | domain, rules, db, connections       |
| scripts     | domain                               |
| ui          | nothing                              |
| web         | core, domain, rules, scripts, ui     |
| site        | ui, rules                            |
| reels       | web, domain, ui                      |
| worker      | runtime, core, domain                |
| cli         | domain                               |

Each package may depend only on the packages its policy lists in
`tools/checks/policy.ts`. Which package owns which third-party
dependency, and the other enforced rules, are in
[executable boundary checks](guardrails.md).

## Packages

One line each; the README has the detail.

- **[domain](https://github.com/werker-ai/werker/blob/main/packages/domain/README.md):** shared
  types and the registry of platform parts.
- **[rules](https://github.com/werker-ai/werker/blob/main/packages/rules/README.md):**
  deterministic decisions over domain values.
- **[db](https://github.com/werker-ai/werker/blob/main/packages/db/README.md):** Postgres access,
  migrations, row-level security and live-update listening.
- **[connections](https://github.com/werker-ai/werker/blob/main/packages/connections/README.md):**
  provider adapters, sealed secrets and capability bindings
  ([capabilities](capabilities.md)).
- **[auth](https://github.com/werker-ai/werker/blob/main/packages/auth/README.md):** sign-in,
  sessions, workspaces and roles
  ([workspaces and access](workspaces-and-access.md)).
- **[core](https://github.com/werker-ai/werker/blob/main/packages/core/README.md):** the use cases
  the apps call.
- **[runtime](https://github.com/werker-ai/werker/blob/main/packages/runtime/README.md):** the run
  engine: queue claims, Pi Durable, sandboxes, workflows.
- **[scripts](https://github.com/werker-ai/werker/blob/main/packages/scripts/README.md):** runs a
  script an assistant wrote over MCP
  ([scripts](api-and-cli.md#scripts)).
- **[ui](https://github.com/werker-ai/werker/blob/main/packages/ui/README.md):** theme, logo and
  UI primitives.

## Apps

- **`apps/app`:** the signed-in SvelteKit app and Node server. Product
  copy is in `apps/app/src/lib/messaging/`. `GET /api/health` reports
  process liveness only. How pages update live:
  [database and events](database-and-events.md#live-updates-pubsub).
- **`apps/site`:** the public landing page, pages, docs and blog,
  prerendered, with a Node server for the waiting list
  ([public site](site-plan.md)). The app's `/` redirects to the
  dashboard or to sign-in.
- **`apps/reels`:** plays `apps/app`'s pages with made-up data, for
  the public site to run in an iframe
  ([reels](https://github.com/werker-ai/werker/blob/main/apps/reels/README.md)). `pnpm reels:build` writes
  it into the site's static files.
- **`apps/worker`:** `src/main.ts` starts the run engine;
  `src/enqueue.ts` queues a run or workflow.

- **`apps/cli`:** the command `werker`, for npm as `@werkerai/cli`. It
  talks to a Werker over HTTP and bundles the types it shares
  ([API, CLI and MCP](api-and-cli.md)).

## Tooling and checks

- Node 24.15+ and pnpm 12.
- SvelteKit 3 and Svelte 5 with the Node adapter.
- Strict TypeScript and shared `tsconfig.base.json`.
- Tailwind CSS 4.
- Vite+ for development, builds, linting, formatting, and Vitest.
- Playwright Chromium for browser component tests.
- wiki0 for documentation indexing and linting.

Dependency versions are centralised in the pnpm catalogue.
`pnpm check` runs [boundary checks](guardrails.md), package type
checks, and root tooling type checks.

## Tests

- `pnpm test:boundaries`: Node tests for the checker and source
  parser.
- `pnpm test:packages`: Vitest tests for the package APIs.
- Web `client` project: `*.svelte.test.ts` in real Chromium.
- Web `server` project: other `*.test.ts` in Node.

`pnpm test:unit` runs all four groups. Tests require no credentials.

## Configuration and deployment

Local development uses Postgres from `compose.yaml` (`pnpm db:up`,
port 54329). In development (`pnpm dev`) the worker reads
`WERKER_SECRET_KEY` from the root `.env` through `nopeek`;
`pnpm start` reads an `.env` if there is one.

The schema is the migrations in `packages/db/sql/`, applied in name
order by `pnpm db:migrate` and recorded in `schema_migrations`.
`001_schema.sql` is the baseline. Every change is a new numbered file,
and the existing ones are frozen. `packages/db/schema.sql` is the
schema those files produce, generated by `pnpm db:schema` (CI fails
when it is out of date) and never edited by hand. The rules for
foreign keys and their indexes are at the top of `001_schema.sql`.

`pnpm db:migrate` applies a file once, so an edited file does not
reach an existing database. `pnpm db:reset` drops the local database
and rebuilds it: migrations and the dev seed. The seed adds the dev
user, a connection for each provider key in `.env`, and the sandbox
host from `WERKER_SANDBOX_HOST` in `.env` (for example
`ssh://user@box`); without it, eval cases that need a shell are
skipped. The reset loses runs, workflows, agents and `workspace-b`
(which `pnpm db:rls-check` needs; `pnpm add-user` adds it back, with
an email no other workspace has).

SvelteKit configuration lives in `apps/app/vite.config.ts`. The
optional root `.env` is read during development and builds, and loaded
by the production start command. `ORIGIN` sets the canonical origin
during the build; runtime `HOST` and `PORT` control the Node listener.

Local environment files, build output, databases, and browser reports
are ignored by Git. [.env.example](https://github.com/werker-ai/werker/blob/main/.env.example)
contains non-secret examples.
