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
| Part | What it is | Start reading at |
|---|---|---|
shade/ | @shadestack/core: almost all the logic, by feature: tables, services, admin screens, modules. | shade/kernel/context.ts, then one feature |
apps/api | The Hono server: routes, thin controllers, start-up. No business rules of its own. | src/server.ts → src/bootstrap/app.ts → src/routes/ |
apps/admin | The 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.
| What | Repository |
|---|---|
The API, the admin, core, the module SDK, @shadestack/svg, the decisions | shade |
The renderers, the framework adapters, the website editor's packages (tree, expressions, styles, render, interactions, a11y) and the starters | shade-frontend |
| The modules | their own repositories, shade-plugin-* |
| SHADE's own site | shade-site |
| These docs | shade-docs |
| Shade Desk | shade-desk |
shade-frontend is installed and checked inside the SHADE workspace, as a submodule in frontend/: the workspace
holds its lockfile.
A reading order
- The rules.
AGENTS.mdin 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. - 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. - The kernel (
shade/kernel/), the base every feature stands on:context.ts: theServiceContextevery service takes first (database, actor, files, rebuild).permissions.tsandactions.ts: who may do what;assertCanis the first line of every service.errors.ts:ShadeErrorand its codes, mapped to HTTP inapps/api/src/http/errors.ts.db/: the database client,tables.ts(every table, re-exported from the features'*.sql.ts), migrations andtesting.ts(a fresh database per test).modules/: defining, loading and switching modules (define.ts,loader.ts,switch.ts).
- One feature, all the way through. Take
shade/features/entries/(below), then compare a smaller one such asmediaoremail. Every feature has the same shape, so after two the rest read quickly. - The API around it.
apps/api/src/routes/shows every URL and its middleware; each line points to a controller inhttp/controllers/, which parses input and calls a service. - The site.
site/src/lib/shade.ts(how the build reads the API),src/pages/[...slug].astro(one page) andsrc/lib/page.ts(a page's tree resolved by@shadestack/renderand drawn byShadeTree).
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:
| Part | Holds | May 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:
| Feature | What it does |
|---|---|
entries | Content: collections compiled to SQL tables, drafts, versions, publishing, the content API. |
media | Uploads, image variants (sharp), alt texts, storage on disk or S3. |
settings | Site settings: name, address, languages, time zone. The theme and the build hook are the website module's. |
content-delivery | Rebuilds (the debounced rebuild) and other frontends. |
team | The team, Better Auth sign-in, two-factor, passkeys, roles and custom roles, API tokens. |
audit | The audit log every service writes to. |
users | Accounts on the website (a separate Better Auth instance) and modules' account roles. |
email | Sending email through SMTP or Brevo, with retries. |
providers | The provider registry: which providers (email, accounts) are set up and which modules need them, and their settings. |
data | Data sources. |
consent | The consent banner. |
privacy | Finding, exporting and erasing one person's data. |
retention | Deleting personal data after a period per kind. |
paths | Where entries with an address live on the site, and where they were (redirect paths). |
preview | Preview links: signing and reading preview tokens for modules. |
ai | AI assistants over MCP, and reverting their changes. |
packages | The Modules screen: switching catalog modules, untrusted modules. |
Next to the features:
shade/fields/<kind>/: one folder per field type (shared.tsthe definition,server.tsits 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'smodules/; website editing is one of them, see Core and the website module), with the feature parts plusmodule.tsand their own migrations. Core's fixture modules for its tests are inshade/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):
- The button.
shade/features/entries/admin/pages/collections/[slug]/[id].vuecallsPOST /api/collections/:slug/:id/publish. The admin dev server forwards/apito the API (apps/admin/nuxt.config.ts); in production they share one origin. - The route.
apps/api/src/routes/api.tsmounts it behind the session middleware (http/middleware/auth.ts) and the same-origin check (http/middleware/origin.ts). - The controller.
apps/api/src/http/controllers/collections.ts:publishparses the body withPublishEntryInputand callspublishEntry. That is all a controller does. - The service.
publishEntryinshade/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 evententries.entry.published, which search, moved addresses and the modules'onhear on the worker. - The rebuild.
shade/features/content-delivery/server/rebuild-trigger.tswaits 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). - 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. - The page. During the build,
site/src/lib/shade.tsreads the published page through the sdk with a read token, and[...slug].astrorenders its tree with@shadestack/renderandShadeTree(@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.tsis 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.tsinserver/;db, about 350). A file is a Postgres test when it makes a test database (createTestDatabase);vitest.config.tssorts the files by that. The Postgres tests run on their own server, thepostgres-testcontainer ofdocker-compose.yml(port 5433, data in memory), which they start themselves (scripts/test-database.mjs; Docker must be running);SHADE_TEST_DATABASE_URLpoints 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'sdbconnects as the running roleshade_app, so row-level security applies;TestDatabase.owneris 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-databasein theirvitest.config.ts, which passes on the checkout's test slot). - The API's tests (
apps/api/test) share their set-up inapps/api/test/testing/:app.tsbuilds the real app on a test database (testApp, with Redis, modules, user and team sign-in as options),auth.tssigns a team member (signInTeam) or a user (signUpAccount) in and holds the one test password, andhttp.tshaspostJsonandcookieOf, which builds oncookiesOffromshade/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
dbproject (a file that readsSHADE_TEST_REDIS_URL): the Redis driver's (apps/api/test/redis/driver.test.ts), on theredis-testcontainer ofdocker-compose.yml(port 6380, nothing on disk), which they start themselves (scripts/test-redis.mjs);SHADE_TEST_REDIS_URLpoints 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 importstestfrome2e/test.ts, never@playwright/test(pnpm lintchecks it), and sets up what it needs itself instead of counting on another spec having run first (e2e/helpers.tshas such steps:withHiddenEnglish,createTeamMemberfor a team member made over the API andsignInfor 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: setSHADE_TEST_SLOT, or remove the file of a checkout you no longer test from.SHADE_TEST_SLOTis 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 ofredis-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-testand the oneredis-testcontainer, always started under the compose projectshade. - Site tests read the site's address from
SITE_PORT, whiche2e/site.config.tssets for the slot.
- Which 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.lockin the temporary folder):pnpm test:e2e,pnpm test:e2e:run,pnpm test:e2e:affected, the modules'pnpm test:e2eandpnpm test:site, and the site'spnpm test:e2eall do.- The checks take it too:
pnpm lint,pnpm typecheck,pnpm testandpnpm test:affectedrun throughscripts/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), sopnpm test:affectedrunningpnpm testnever 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.
- The checks take it too:
pnpm dev:checkchecks thatpnpm devstarts the API and the admin.
Running what you need:
| Command | Runs | Time |
|---|---|---|
pnpm test | every unit and Postgres test | about 1 min |
pnpm test:unit | the tests without a database | about 10 s |
pnpm test:db | the Postgres tests | about 30 s |
pnpm test:changed | the tests of files changed since main, and of what imports them | depends |
pnpm --filter <package> test | one package's own tests, e.g. pnpm --filter @shadestack/render test (pnpm test:scripts the root's, test/) | seconds |
pnpm test:affected | the 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 schedules | seconds |
pnpm test -t "<part of a name>" | matching tests | seconds |
pnpm test:watch | reruns what a saved file affects | |
pnpm coverage | every 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:e2e | builds the admin and the API when they changed, then every browser test, on 3 workers | about 3 min |
pnpm test:e2e:affected | the 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.ts | about 10 s a spec |
pnpm test:e2e:run --last-failed | the browser tests that failed last time | |
pnpm test:e2e:run -g "<name>" | browser tests whose name matches | |
E2E_AREA=render pnpm test:e2e:run | the 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.tschecks the production cost. The setter is exported from no entry point. - The route sweep (
access.test.ts) runs in four parts,access.test.tsandaccess-2.test.tstoaccess-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): anotheraccess-5.test.tswithaccessSweep(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.tsin one of its parts (shade/exports/permissions.tslists them); collections' actions are in their definitions, anddecideis inshade/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'sadmin/locales/. - A starter component → the website module's
server/starters.ts; how a page renders →packages/render/inshade-frontend. - Why it is like this → Decisions, then its record in
docs/decisions/.