SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE
Contributing

Reading the code

A guided way into the repository: what each part is for, what to read first, and how to follow a change from a click in the admin to the visitor's page. It assumes the architecture page for the big picture and links to the detailed pages instead of repeating them.

The parts in one minute

PartWhat it isStart reading at
shade/@shadestack/core: almost all the logic, by feature: tables, services, admin screens, modules.shade/kernel/context.ts, then one feature
apps/apiThe Hono server: routes, thin controllers, start-up. No business rules of its own.src/server.ts → src/bootstrap/app.ts → src/routes/
apps/adminThe Nuxt admin shell. The screens themselves live in shade/features/*/admin.nuxt.config.ts, modules/shade-modules.ts
site/The Astro website, built to static files from the API.src/lib/shade.ts, src/pages/[...slug].astro
packages/svg@shadestack/svg, the SVG an upload may be.packages/svg/src/
frontend/ (shade-frontend)Sites in other frameworks: a framework-free client plus Astro, Next, SvelteKit and Nuxt, the website editor's packages and the starters. Its own repository since 24 November 2026; packages/ below is in it.packages/client/src/index.ts
e2e/Playwright tests against a real API, admin and site.e2e/server.ts, any file in e2e/tests/
docs/The decision records: the reasons behind the design, summed up on the docs' Decisions page. This site is the shade-docs repository.docs/decisions/index.md

Which repository

A change goes to the repository that owns the code. Open issues and pull requests there.

WhatRepository
The API, the admin, core, the module SDK, @shadestack/svg, the decisionsshade
The renderers, the framework adapters, the website editor's packages (tree, expressions, styles, render, interactions, a11y) and the startersshade-frontend
The modulestheir own repositories, shade-plugin-*
SHADE's own siteshade-site
These docsshade-docs
Shade Deskshade-desk

shade-frontend is installed and checked inside the SHADE workspace, as a submodule in frontend/: the workspace holds its lockfile.

A reading order

  1. The rules. AGENTS.md in the repository root lists the working rules and the architecture rules every service follows. They are short and explain most of what you will see.
  2. The decisions. docs/decisions/index.md, then at least its Start here list: what SHADE is, an instance, Postgres and Redis, the code and the API, and trusted and untrusted modules; then the services modules build on, collections and languages, accounts and Better Auth, and frontends.
  3. The kernel (shade/kernel/), the base every feature stands on:
    • context.ts: the ServiceContext every service takes first (database, actor, files, rebuild).
    • permissions.ts and actions.ts: who may do what; assertCan is the first line of every service.
    • errors.ts: ShadeError and its codes, mapped to HTTP in apps/api/src/http/errors.ts.
    • db/: the database client, tables.ts (every table, re-exported from the features' *.sql.ts), migrations and testing.ts (a fresh database per test).
    • modules/: defining, loading and switching modules (define.ts, loader.ts, switch.ts).
  4. One feature, all the way through. Take shade/features/entries/ (below), then compare a smaller one such as media or email. Every feature has the same shape, so after two the rest read quickly.
  5. The API around it. apps/api/src/routes/ shows every URL and its middleware; each line points to a controller in http/controllers/, which parses input and calls a service.
  6. The site. site/src/lib/shade.ts (how the build reads the API), src/pages/[...slug].astro (one page) and src/lib/page.ts (a page's tree resolved by @shadestack/render and drawn by ShadeTree).

The shape of a feature

Every folder in shade/features/ has up to three parts, and a README.md naming its code and tests. Using media as the example:

PartHoldsMay import
shared/Types and Zod input schemas (PublishedMedia, the allowed file types). Runs in the browser and on the server.other shared/ code only
server/Services (media.ts: uploads, alt texts, …), tables (*.sql.ts); their Postgres tests are under shade/test/.anything server-side
admin/Screens: pages/ (routes), components/, composables/, locales/{en,nl}.json.shared/, never server/

pnpm lint enforces the import column: no server code in shared, admin or site parts.

The features, in a sentence each:

FeatureWhat it does
entriesContent: collections compiled to SQL tables, drafts, versions, publishing, the content API.
mediaUploads, image variants (sharp), alt texts, storage on disk or S3.
settingsSite settings: name, address, languages, time zone. The theme and the build hook are the website module's.
content-deliveryRebuilds (the debounced rebuild) and other frontends.
teamThe team, Better Auth sign-in, two-factor, passkeys, roles and custom roles, API tokens.
auditThe audit log every service writes to.
usersAccounts on the website (a separate Better Auth instance) and modules' account roles.
emailSending email through SMTP or Brevo, with retries.
providersThe provider registry: which providers (email, accounts) are set up and which modules need them, and their settings.
dataData sources.
consentThe consent banner.
privacyFinding, exporting and erasing one person's data.
retentionDeleting personal data after a period per kind.
pathsWhere entries with an address live on the site, and where they were (redirect paths).
previewPreview links: signing and reading preview tokens for modules.
aiAI assistants over MCP, and reverting their changes.
packagesThe Modules screen: switching catalog modules, untrusted modules.

Next to the features:

  • shade/fields/<kind>/: one folder per field type (shared.ts the definition, server.ts its column and checks, admin/ its editor). The entries feature looks types up here instead of switching over kinds.
  • No modules: they live in their own repositories (shade-plugin-website, shade-plugin-appointments, shade-plugin-commerce, shade-plugin-editorial, in the workspace's modules/; website editing is one of them, see Core and the website module), with the feature parts plus module.ts and their own migrations. Core's fixture modules for its tests are in shade/test/testing/fixtures/modules. See Writing modules.
  • shade/sdk/: the typed read client sites use. shade/exports/: the entry points the apps import (core, schema, site). shade/module-sdk/: the package @shadestack/module-sdk, the only thing modules import from SHADE.

Following one change: publishing an entry

The quickest way to see how the parts connect. Open these files side by side (a website's page is an entry of the website module's website-pages collection):

  1. The button. shade/features/entries/admin/pages/collections/[slug]/[id].vue calls POST /api/collections/:slug/:id/publish. The admin dev server forwards /api to the API (apps/admin/nuxt.config.ts); in production they share one origin.
  2. The route. apps/api/src/routes/api.ts mounts it behind the session middleware (http/middleware/auth.ts) and the same-origin check (http/middleware/origin.ts).
  3. The controller. apps/api/src/http/controllers/collections.ts: publish parses the body with PublishEntryInput and calls publishEntry. That is all a controller does.
  4. The service. publishEntry in shade/features/entries/server/collections.ts: assertCan(ctx.actor, 'collections.<slug>.publish'), the collection's publish checks (a module's too: the website module compiles the styles and checks accessibility), then it publishes the version in a transaction, records the audit entry and asks for a rebuild (ctx.rebuild.request). With it, in the same transaction, it writes the event entries.entry.published, which search, moved addresses and the modules' on hear on the worker.
  5. The rebuild. shade/features/content-delivery/server/rebuild-trigger.ts waits for a quiet period (30 seconds by default), so ten publishes make one rebuild, then calls every other frontend's webhook and each module's rebuild target (the website module calls the site's build hook).
  6. The rebuild. The webhook reaches the site runner (site/runner/runner.mjs), which runs the Astro build into a fresh folder and switches to it in one step, then reports the result back to the API.
  7. The page. During the build, site/src/lib/shade.ts reads the published page through the sdk with a read token, and [...slug].astro renders its tree with @shadestack/render and ShadeTree (@shadestack/astro/tree).

The same path holds for almost everything: admin screen → route → controller → service → database, with the audit log, events and rebuilds as side effects of the service.

The API app

apps/api/src/:

  • server.ts: reads the configuration, starts up (bootstrap/start.ts: database check, migrations, modules, content model, jobs) and listens. config.ts is the only place that reads environment variables.
  • bootstrap/runtime.ts: the long-lived services (database, storage, auth, rebuild trigger, modules), created once. bootstrap/app.ts: the Hono app; it mounts the route files by role.
  • routes/: one file per group. api.ts (the admin's API, sessions), content.ts (the content API: the site build, read tokens), data.ts (data tokens), user.ts (accounts; the public role), mcp.ts (AI), web.ts (health, uploaded files, icons, the OpenAPI document and the admin's built files).
  • http/: controllers, middleware (auth, origin, rate limits, body limits), error mapping, CSP, the OpenAPI document.
  • console/: create-admin, collection generation and module signing commands.
  • sandbox/: untrusted modules, each in its own workerd process.

The container roles: admin serves the team, the build and MCP; public serves only the account API; worker serves only /health and runs the background work (bootstrap/worker.ts: the schedules and the heartbeat). all (the default) does everything, for development only.

The admin app

apps/admin is mostly a shell: the layout, sign-in, the dashboard and shared components in app/. modules/shade-modules.ts mounts every feature's admin/ folder (pages become routes, components and composables are auto-imported, locales get the feature's prefix); modules/shade-installed-modules.ts does the same for modules. So to find a screen, look in shade/features/<name>/admin/pages/ rather than in apps/admin.

Texts go through translation keys in Dutch and English. API error messages are too: notFound({ key, params }, sentence), an issue's message: '…', key: '…' or a refinement's message: '…', params: { key: '…' }, the key under <feature>.errors in the feature's admin/locales (the shell's common.errors, api.errors, tree.errors… for what is shared, the API's and the packages'). A helper called with nothing (notFound()) says its own sentence by its common.errors key, and "Invalid input" is validation(INVALID_INPUT, 'Invalid input', issues). apps/admin/test/checks/messages.test.ts fails on a message without a key, or a key without its English and Dutch.

Tests, and how to use them to read

Tests are the best documentation of the rules: each service's test reads as a list of what it allows and refuses.

  • Unit tests need nothing (unit, about 400 tests in seconds). Postgres tests sit next to the services (*.test.ts in server/; db, about 350). A file is a Postgres test when it makes a test database (createTestDatabase); vitest.config.ts sorts the files by that. The Postgres tests run on their own server, the postgres-test container of docker-compose.yml (port 5433, data in memory), which they start themselves (scripts/test-database.mjs; Docker must be running); SHADE_TEST_DATABASE_URL points them at another server instead. Without a server they fail with a message saying so, never skip, so a run without a database can't pass as green. Your development database is never used. Each test gets a fresh database, a copy of one migrated template (kernel/db/testing.ts), so they stay independent and fast. A test's db connects as the running role shade_app, so row-level security applies; TestDatabase.owner is the owner's handle for a test's own DDL. The browser tests use the same server, and modules too. The browser tests' servers (e2e/server.ts) and the site's (e2e/site-server.ts) start from a copy of the same template as well, instead of migrating: only the first run after a change of the migrations migrates, into a new template named after their hash (a changed or added migration, or a changed journal, makes a new one; the slot's older ones are dropped). Their seed (the test admin, the module packages signed for the run) is made per server, since it holds the run's password and signing key (testDatabase() from @shadestack/module-sdk/test-database in their vitest.config.ts, which passes on the checkout's test slot).
  • The API's tests (apps/api/test) share their set-up in apps/api/test/testing/: app.ts builds the real app on a test database (testApp, with Redis, modules, user and team sign-in as options), auth.ts signs a team member (signInTeam) or a user (signUpAccount) in and holds the one test password, and http.ts has postJson and cookieOf, which builds on cookiesOf from shade/test/testing/team-auth.ts. A test with a set-up of its own, such as one that needs a mock of the sign-in, keeps it local.
  • Redis tests run in the same db project (a file that reads SHADE_TEST_REDIS_URL): the Redis driver's (apps/api/test/redis/driver.test.ts), on the redis-test container of docker-compose.yml (port 6380, nothing on disk), which they start themselves (scripts/test-redis.mjs); SHADE_TEST_REDIS_URL points them at another Redis. Each case keeps its keys under a prefix of its own and removes them. Every test API of the browser tests runs on it too (Redis is required), and so does the site's. Core's unit tests use the memory ports instead (memoryCoordination, Redis and the ports).
  • Playwright tests (e2e/tests/*.spec.ts) click through the real admin. They are the place to see what a screen is supposed to do. They run on several workers at once (E2E_WORKERS, default 3), each with a server and a database of its own (e2e/servers.ts), so a spec imports test from e2e/test.ts, never @playwright/test (pnpm lint checks it), and sets up what it needs itself instead of counting on another spec having run first (e2e/helpers.ts has such steps: withHiddenEnglish, createTeamMember for a team member made over the API and signIn for the login screen, which the modules' browser tests import from @shadestack/e2e/helpers).
  • Checkouts side by side. Several checkouts (git worktrees, the workspace's shade/) can run their tests at the same time on one machine, each in its own test slot (scripts/test-slot.mjs):
    • Which slot: SHADE_TEST_SLOT (0–9) when set; otherwise 0 for the repository's own checkout and 1–9 for a worktree or submodule. A worktree holds its slot in a file per slot in the machine's temporary folder (shade-test-slots/<n>, holding the checkout's path): the slot a hash of its path picks, else the next free one, so two checkouts never share one. A removed worktree's slot is free again. With all nine held the tests stop and say so: set SHADE_TEST_SLOT, or remove the file of a checkout you no longer test from. SHADE_TEST_SLOT is never checked against the held slots.
    • What it changes: slot n moves every test port up by n × 100 (the browser tests' servers, the site's API, site, and the payments module's own tests stand in for Mollie with @shadestack/module-payments/testing, the image test's containers) and adds _s<n> to the databases, migration templates and containers the tests make, and uses Redis's database n of redis-test. Each checkout replaces only its own old templates.
    • What stays the same: slot 0 keeps the ports and names as they were. All slots share the one postgres-test and the one redis-test container, always started under the compose project shade.
    • Site tests read the site's address from SITE_PORT, which e2e/site.config.ts sets for the slot.
  • One browser run at a time. Slots keep the runs' ports, databases and containers apart, but two browser runs at once still share the machine's cores, and their time limits then fail tests that are fine. So Playwright runs through e2e/run.ts, which first takes the machine's lock (scripts/e2e-lock.mjs; shade-e2e.lock in the temporary folder): pnpm test:e2e, pnpm test:e2e:run, pnpm test:e2e:affected, the modules' pnpm test:e2e and pnpm test:site, and the site's pnpm test:e2e all do.
    • The checks take it too: pnpm lint, pnpm typecheck, pnpm test and pnpm test:affected run through scripts/locked.mjs, so a check never runs while another checkout's checks or browser tests do. What a check starts learns the lock is held (SHADE_TEST_LOCK_HELD, its holder's process id), so pnpm test:affected running pnpm test never waits for itself.
    • A run that finds the lock held waits, saying whose run it is: the process id, the folder it started in (its worktree), since when, and how to stop it if it is a stray one (on Windows taskkill /PID <id> /T /F, which stops Playwright's servers and browsers with it).
    • A lock whose process has ended (a run stopped hard) is removed by the next run. The lock file is JSON with the same owner, for a look by hand.
    • It waits at most three hours, then fails naming the holder.
  • pnpm dev:check checks that pnpm dev starts the API and the admin.

Running what you need:

CommandRunsTime
pnpm testevery unit and Postgres testabout 1 min
pnpm test:unitthe tests without a databaseabout 10 s
pnpm test:dbthe Postgres testsabout 30 s
pnpm test:changedthe tests of files changed since main, and of what imports themdepends
pnpm --filter <package> testone package's own tests, e.g. pnpm --filter @shadestack/render test (pnpm test:scripts the root's, test/)seconds
pnpm test:affectedthe tests of the packages changed since origin/main and of those that depend on them; everything when the root changed (--base <ref>; pnpm test:affected typecheck the same for the typecheck)seconds to the full run
pnpm test:frameworks <next|nuxt|sveltekit> (in shade-frontend)an adapter's typecheck and tests on its framework's current version (--e2e with the render bundles' browser tests; other versions in CI only, Releases)seconds
pnpm test <part of a path>matching files, e.g. pnpm test schedulesseconds
pnpm test -t "<part of a name>"matching testsseconds
pnpm test:watchreruns what a saved file affects
pnpm coverageevery unit and Postgres test, with what they run of the code: a summary per folder in coverage/index.html (reported, never a threshold)a few minutes
pnpm test:e2ebuilds the admin and the API when they changed, then every browser test, on 3 workersabout 3 min
pnpm test:e2e:affectedthe browser tests a branch needs since origin/main: none, the specs of the features it touched, or every one when it touched what all specs stand on or a path it can't place (--dry prints the choice and why; --base <ref>; --targeted: for a batch of a series, the specs it touched and a smoke set instead of every one)none to the full run
pnpm test:e2e:run <spec>browser tests without building first, e.g. tests/audit.spec.tsabout 10 s a spec
pnpm test:e2e:run --last-failedthe browser tests that failed last time
pnpm test:e2e:run -g "<name>"browser tests whose name matches
E2E_AREA=render pnpm test:e2e:runthe browser tests of one area: render, plugins or admin (every other spec)

Before a pull request: pnpm typecheck, pnpm lint, pnpm architecture:baseline, pnpm test:affected and pnpm test:e2e:affected, and the site's browser tests when it says the site reads what changed. During a series of batches, each batch runs pnpm test:e2e:affected --targeted (the specs of what it touched, plus signing in, publishing, modules and a module's consent, instead of every spec when it touched what they all stand on), and the last batch of each stack runs the full suite before it is merged; with no series named, the full suite stays the default. The full pnpm test and pnpm test:e2e run at milestones: after a series of changes, after an upgrade of a runtime, database or framework, and before every release. While working, the narrower commands; every browser run (test:e2e:run too, and a module's or the site's) builds the admin and the API first when they changed (node scripts/e2e-build.mjs; about a second when nothing did), except in CI, which takes the build job's output.

One build per run. scripts/e2e-build.mjs builds the admin, then the API, each only when something it is built from changed since its last build. After a build it records next to the output (apps/admin/.output/e2e-build.json, apps/api/dist/e2e-build.json) a hash of everything the build may read (the checkout's files, committed or not, but docs, e2e/, tests, Markdown, CI, deploy/ and the root's scripts/; the admin's .env; the installed packages' lockfile; the environment variables a build reads: NUXT_*, NITRO_*, VITE_*, NODE_ENV and SHADE_DEV_MODULES; Node's version and platform) and a hash of the output. It builds again when either differs, and whenever it can't tell: no record, no git, or an output built since by other means (pnpm build). A wrong skip would test old code, so it errs towards building. Unchanged, the check takes about a second instead of about 30 s of building. Each build is also kept in the machine's temporary folder (shade-e2e-builds, by that hash, the three used last per app), so a new worktree with the same inputs copies it in about 3 s instead of building; a kept copy whose files changed is dropped and built again.

How many test files run at once. Vitest runs about half the machine's cores' worth of test files at once (maxWorkers, scripts/test-workers.mjs), in SHADE's own tests and the modules' (moduleTestConfig), so the test containers and a second session on the same machine keep room. SHADE_TEST_WORKERS sets the number instead (SHADE_TEST_WORKERS=12 pnpm test). The browser tests have their own setting, E2E_WORKERS (3 servers by default).

Each package's own tests. Every package with a test/ folder has a test script (scripts/test-package.mjs), which runs the root's Vitest configuration on that folder only (SHADE_TEST_PACKAGE), so pnpm's own filter picks what to run, with no other tool: pnpm --filter "...[origin/main]" test runs the packages changed since origin/main and every package that depends on them. A change at the root (the Vitest configuration, the test setup, tsconfig.base.json, pnpm-lock.yaml, the scripts) reaches every package, and the root's own test is the full run, so pnpm test:affected runs pnpm test alone then. The same holds for typecheck, which every package has. The browser tests' package (e2e/) has no test script (its Playwright run is e2e), so a filter never starts them. Measured on 7 November 2026 on a developer's machine, with the test containers running: pnpm test takes about 54 s; a change to an adapter alone 3 s, to the API alone 25 s, and to @shadestack/render about 56 s, since core and the apps build on it and so most of the suite runs.

What CI runs: in .github/workflows/ci.yml, a pull request gets lint, the security checks and the typecheck and tests of pnpm test:affected against its base branch, and a push to main lint, the full typecheck and pnpm test. full.yml runs weekly, by hand and before a release: the browser tests in three areas side by side (E2E_AREA: render, plugins, admin), the admin's in two shards (E2E_SHARD=1/2, which e2e/run.ts passes to Playwright as --shard; scripts/e2e-shard.mjs). The kit's framework matrix runs weekly, by hand and before its releases. One job builds the admin and the API with scripts/e2e-build.mjs and hands them, with their records, to the browser test jobs, whose pnpm test:e2e then skips the build. A local run is never sharded unless you ask: E2E_SHARD=2/3 pnpm test:e2e:run, or --shard=2/3 after the spec arguments.

What keeps pnpm test fast:

  • Passwords are hashed at N=2^12 in the tests instead of 2^17 (scripts/test-setup.ts, a setup file of the unit and db projects), so each sign-in takes milliseconds instead of half a second and 128 MiB. Stored hashes carry their own N; crypto.test.ts checks the production cost. The setter is exported from no entry point.
  • The route sweep (access.test.ts) runs in four parts, access.test.ts and access-2.test.ts to access-4.test.ts, each on a database of its own, so they run side by side (apps/api/test/sweep/access-sweep.ts). The parts are counted from those files (access-parts.ts): another access-5.test.ts with accessSweep(import.meta.url) splits the routes over five; a gap in the numbers fails. The parts may run in any order: an answer must never depend on another route having run first.
  • What tests write goes under .data/, which test discovery skips.

Finding things

  • A URL → apps/api/src/routes/; search for its path.
  • A rule ("who may publish?") → the service's first line (assertCan), and the module's own declaration of its actions and who holds them by default, shared/permissions.ts in one of its parts (shade/exports/permissions.ts lists them); collections' actions are in their definitions, and decide is in shade/kernel/permissions.ts.
  • A table → shade/features/<name>/server/*.sql.ts; collections' tables are generated (collections.generated.sql.ts, pnpm db:collections).
  • A screen → shade/features/<name>/admin/pages/; its texts are in that feature's admin/locales/.
  • A starter component → the website module's server/starters.ts; how a page renders → packages/render/ in shade-frontend.
  • Why it is like this → Decisions, then its record in docs/decisions/.