Architecture
SHADE runs underneath client systems. The team works in a Nuxt app (apps/admin), the admin screens, which call
the API (apps/api, a Hono server laid out like Laravel); visitors get a fully static Astro site
rebuilt on publish, SHADE's own frontend in its own repository (shadehq-dev/shade-site, site/ in the SHADE
workspace). In production the API also serves the admin's built files, on one origin. Paths below starting with site/
are in that repository. Each client runs their own instance on their own server. The reasons behind the design are
recorded as decision records in the shade repository, in docs/decisions/ (not published on this site). New to the
code? Start with Reading the code. Website editing is a module, not core:
what each side holds is in Core and the website module.
Runtime picture
flowchart LR
accTitle: The runtime picture
accDescr: The team uses the API in the admin role, which serves the admin screens' built files, /api/*, /api/mcp and /uploads. The site build (Astro) and the preview server read the content API with a token. The site build makes static files, which Caddy (target static) serves to visitors. The team's /preview iframe loads the preview server (target preview). Visitors' forms and checkout go to the API in the public role: /api/v1/account/*, plugin routes with auth 'public', and CORS for the site. Both API roles use Postgres.
team([The team]) --> admin["API, role admin<br>admin screens (built files), /api/*, /api/mcp, /uploads"]
build["Site build (Astro)"] -- "content API (token)" --> admin
build --> files[Static files] --> caddy["Caddy (target: static)"]
visitors([Visitors]) --> caddy
iframe(["The team's /preview iframe"]) --> preview["Preview server (target: preview)"]
preview -- "content API (token)" --> admin
forms(["Visitors' forms, checkout"]) --> public["API, role public<br>/api/v1/account/*, plugin routes with auth: 'public', CORS for the site"]
admin --> pg[(Postgres)]
public --> pg
Visitors only ever load static files (pages, assets, images copied into the build). The backend sees
the team, one build per publish, previews, MCP, and on the public role visitor-facing dynamic routes and the content
reads of server-rendered frontends (read tokens only).
Packages
Shared code lives in one workspace package, @shadestack/core (folder shade/), organised by feature
(the paths are inside shade/):
| Folder | What it holds |
|---|---|
kernel/ | Service context, errors, permissions, actions, common schemas |
kernel/db/ | The client, migrations, the test database, column helpers |
kernel/modules/ | The module contract and loader |
kernel/identity/ | The team_members and team_roles tables, the role and via enums |
kernel/coordination/ | The ports for work in flight in memory, leases, and messages between containers: announce, follow |
kernel/modules/ | The module switch's table, pausing a module, and the fault boundary that measures each module and pauses one that keeps failing |
kernel/providers/ | The provider registry (email, accounts) and provider settings |
business/ | The business module's parts (decision 0002), laid out as features are |
business/money/ | The money amount type, browser-safe |
business/mailing-lists/ | Modules' bulk mail lists, keyed to contacts; the Lists screen |
business/holds/ | N of a module's resource until an expiry, or a time range of it; the expiry sweep; waitlists |
business/time-rules/ | A module's opening hours: a week of periods and exceptions, browser-safe rules and a service |
features/contacts/ | One contact per person, always on; the People screen |
features/team/ | shared/ auth types and inputs; server/ team.sql.ts, team and roles services, crypto; admin/ login, account, team, roles and API token screens, useSession |
features/audit/ | shared/ audit types; server/ audit.sql.ts, recordAudit, listAudit; admin/ audit log |
features/media/ | shared/ media types; server/ media.sql.ts, media service, images, storage; admin/ media library, detail, focal point, picker, useMedia |
features/entries/ | shared/ collection definitions, fields, values, validation, table planner, built-in collections; server/ generated tables, collection service, mapping, filters, references, code generator; admin/ collection list and entry screens, EntryForm |
features/paths/ | shared/ public addresses, redirect paths, PublishedPageSummary; server/ public addresses, address sources (modules'), item paths (itemPathsOf), moves |
features/settings/ | shared/ settings and language types; server/ settings.sql.ts, settings service; admin/ settings screen |
features/content-delivery/ | shared/ public read models; server/ public read service, rebuilds, frontends; admin/ frontends screens |
features/data/ | shared/, server/: data sources; admin/: their texts |
features/preview/ | shared/ PreviewLink; server/ signing and reading preview tokens |
features/usage/ | server/ who uses what: media users, whether there is content; entries answers |
features/ai/ | server/ MCP server and tools, AI changes; admin/ AI changes screen |
features/email/ | shared/, server/, admin/: sending (SMTP or Brevo), the email log, the Email screen |
features/errors/ | shared/, server/, admin/: the error log and security alerts, the Errors screen |
features/consent/ | shared/, server/: consent categories (the banner is @shadestack/astro's) |
features/kv/ | server/: every module's kv, with atomic counters (moduleKv, the bridge's kv.*) |
features/privacy/ | shared/, server/, admin/: export and deletion per person |
features/retention/ | shared/, server/, admin/: deleting personal data after a set period |
features/users/ | shared/, server/, admin/: accounts and account roles (Better Auth) |
features/packages/ | shared/, server/, admin/: switching modules on and off, their settings, the guided turn-off, untrusted modules and server packages (the modules themselves live in their own repositories) |
module-sdk/ | @shadestack/module-sdk, its own package: what modules may use |
fields/ | One folder per field type: shared.ts (descriptor, validation, columns), server.ts (mapping, filters, references), admin/ (editor component); shared.ts and server.ts are the registries; references.ts finds links and media in stored JSON |
sdk/ | The typed read client for the site |
exports/ | The package entry points schema, services, plugins and tables (barrels over the features) and the list of the features' manifest parts |
shared/is browser-safe: types and input schemas only.server/holds tables (*.sql.ts), services and their tests.admin/holds the feature's admin screens:pages/(routes, Nuxt file naming),components/,composables/andutils/(auto-imported), andnav.ts, its entries in the sidebar (defineAdminNav: a section of the main sidebar or a settings group, order, label key, icon, path, the action needed, an optional count and keyboard shortcut; the shape of a module's sidebar entries), andentry-editor.ts, its parts of the entry editor (defineEntryEditorParts: a component in the header, next to Publish or above the form, given the editor's collection, entry id, language,saveandreload).apps/admin/modules/shade-modules.tsmounts them like the app's ownapp/folder and gathers the entries in#build/shade-feature-nav.mjs, which the layout shows, and the editor parts in#build/shade-entry-editor.mjs, which the entry editor shows. That is how presence and the Preview button reach the editor although entries sits below them. Core holds no Astro components: the header and footer, the responsive image, the consent banner and the icon are in@shadestack/astro(packages/astro/src/siteinshade-frontend).- Each field type's editor component lives in
shade/fields/<kind>/admin/;shade-modules.tsauto-imports them too. apps/admin/app/keeps the shell: layout and sidebar (its entries are the features'nav.ts), login guard, dashboard,components/field/FieldRenderer.vue(which picks a field's editor) withuseFieldIssues(what a form tells its fields), the instance's collections (useCollections), and what several parts share or assemble: the Settings screen (pages/settings.vue, the cards of a dozen parts on one page) andTakeDataModal(signing in again before a copy of the data leaves, for the audit export, backups and the instance export). The app assembles the modules, so it may use any part.- A screen puts its content in
AdminPage(apps/admin/app/components/AdminPage.vue), which is the sheet's full width. Fields and cards of forms and settings go inAdminFormGrid: columns of at least 22 rem that fill the width, a card or group staying whole in one column. Running text (theintro, a lead, a description) keeps a reading measure of about 70 characters with thereading-measureclass. - Every list screen uses the shell's list pieces (
apps/admin/app/components/list/):ListEmptyinUTable's#emptyslot (one empty state),ListPager(only with more than one page),ListErrorwith a retry when the request failed (never shown as an empty list) andListLoading. 20 rows a page for content, 50 for logs and rules. The empty and error states are checked with axe (e2e/tests/lists.spec.ts);app.config.tsgives subtle alerts' text the normal colours, since coloured text on their tint is below 4.5:1. - Every admin screen names the action it needs (
definePageMeta({ can }), checked bymiddleware/auth.global.ts), the same one its sidebar link requires, and a screen with a form asks before leaving unsaved changes (useUnsavedGuard; a settings screen throughuseSettingsForm, its draft and whether it changed). A request runs throughuseApiAction(busy while it runs, its failure as a toast with the API's message or on the form's fields) and a paginated list throughuseApiList. - Inside
shade/, files import each other directly by relative path, never throughexports/. Modules are the exception: they import SHADE only through@shadestack/module-sdk, never a path out of their own folder. - Every database object is declared in a
*.sql.tsfile of the part that owns it;drizzle.config.tsreads them all. A part imports its own tables directly and another part's through that part's front door (server/index.ts).exports/tables-all.tsgathers every table for those who assemble: the module SDK'stablesand core's tests.@shadestack/core/tables(exports/tables.ts) is a named list of the four tables the API's console commands read. The database client has no schema (no relationaldb.query).
The apps import by subpath:
| Import | What |
|---|---|
@shadestack/core/schema | The input schemas and types the API, the admin and the frontends import: a named list, so a shared/ name nothing outside core imports is not exported (exports/schema.ts). |
@shadestack/core/services | The services the API, the admin's server parts and the browser tests' servers call, plus context and errors: a named list, so a service nothing outside core calls is not exported (exports/core.ts). |
@shadestack/core/permissions | Permissions only; browser-safe. |
@shadestack/core/collections (/generate) | Collection definitions; the table generator: named lists, so a name nothing outside core imports is not exported (exports/collections.ts). |
@shadestack/core/db (/testing) | Database client and migrations (exports/db.ts, a named list); the throwaway test database. |
@shadestack/core/testing | What only tests use: tables to fill fixtures, test clocks, permission and module switches set by hand. The API's sources and the admin's screens never import it (pnpm lint). |
@shadestack/core/installed | Module contract and loader, a named list (exports/installed.ts). Core names no module; its tests use the fixture modules in shade/test/testing/fixtures/modules. |
@shadestack/module-sdk/server (/shared, /site, /testing) | The module SDK, its own package in shade/module-sdk/: what a module may use (Writing a module). |
@shadestack/core/fields | The field type registry (exports/fields.ts, a named list over fields/shared.ts); browser-safe. |
@shadestack/core/mcp, /sdk | MCP server, read client. |
Other packages (shade) | Responsibility |
|---|---|
apps/api | The API: a Hono server (see The API below). Owns the configuration, the runtime, start-up and the console commands. |
apps/admin | Nuxt 4 + Nuxt UI. app/: the admin screens, a single-page app calling /api (imports schema, collections, fields, core/permissions). Built to static files (nuxt generate → .output/public), served by the API; no server code. Its dev server forwards /api, /uploads and /health to the API. |
site/ (shadehq-dev/shade-site) | SHADE's own Astro site, a frontend in its own repository; only /preview and /preview/canvas are server-rendered. Imports @shadestack/core's sdk and schema, @shadestack/astro (the shade() integration, site, tree, the preview's content security policy), @shadestack/render, @shadestack/client/canvas (the website editor's canvas) and the installed modules' head parts (virtual:shade/module-sites). Its browser tests run against @shadestack/e2e's test instance. |
e2e | @shadestack/e2e: SHADE's browser tests (pnpm test:e2e; one spec without rebuilding: pnpm test:e2e:run <spec>), and the test instance (site-server.ts: a seeded database, the built API, a site built against it) that shade-site's and the modules' site tests use (siteE2eConfig, moduleSiteE2eConfig); its core content (site-content.ts) also fills the workspace's migration check (pnpm migrations:check). |
packages/svg | @shadestack/svg: the SVG an uploaded image may be, an allow-list of elements with the attributes each takes, which the media library checks SVG uploads against. No dependencies, so core checks uploads without the website editor's packages. |
The frontend kit moved to its own repository, shadehq-dev/shade-frontend (frontend/ in the SHADE workspace), on 24 November 2026 (decision 0016 point 12). Its packages are in packages/ there, with the starters in starters/ and the browser tests that need no instance in e2e/:
Kit package (shade-frontend) | Responsibility |
|---|---|
packages/client | @shadestack/client, for any framework: core's read client at its root, which needs none of the website editor's packages; with those as optional peers, a site's pages and the theme as CSS (@shadestack/client/render) and the website editor's canvas (@shadestack/client/canvas, /preview/canvas). |
packages/astro | @shadestack/astro: the shade() integration, the node tree's renderer (@shadestack/astro/tree), site parts and render helpers; SHADE's own site uses it. |
packages/next, packages/sveltekit, packages/nuxt | @shadestack/next, @shadestack/sveltekit, @shadestack/nuxt: the node tree's renderer (ShadeTree, on @shadestack/render) and read client per framework (Other frameworks). |
packages/tree | @shadestack/tree: the website editor's typed node tree: node types, events and actions in client islands, validation, schema versions and migrations, tree operations and comparison per node, and the canvas protocol between the editor and a frontend (@shadestack/tree/canvas). Framework-free; the editor's other foundations and the website module's content check build on it (Other frameworks). |
packages/expressions | @shadestack/expressions: the website editor's expressions, a typed tree, never code: the AST, the type checker, the approved functions, one interpreter and runtime, compilers to Astro/JSX, Vue and Svelte template code, and the fx bar's grammar. Framework-free, no dependencies; @shadestack/tree stores and checks its expressions (Other frameworks). |
packages/styles | @shadestack/styles: the website editor's styles: classes and local styles (by tree id and node id) with breakpoints, container queries, states and pseudo-elements, variables with light and dark modes, typed values from a property allow-list, the CSS compiler with its output check, the origin rules, a theme's tokens as default variables and as CSS (the theme itself is the website module's) and WCAG contrast. Framework-free, no dependencies (Other frameworks). |
packages/render | @shadestack/render: the website editor's rendering core: resolves a stored tree with its components, data, visitor (server islands only) and language into plain elements, client island templates and head data; the embed sanitiser, edit-mode markers, render limits, the islands' runtime, SHADE's accessible widgets (shade:dialog, tabs, menu, disclosure, accordion) and the conformance suite the four renderers (ShadeTree in @shadestack/astro, @shadestack/next, @shadestack/nuxt, @shadestack/sveltekit) are held to. Framework-free, on the tree, the expressions and the styles (Other frameworks). |
packages/interactions | @shadestack/interactions: the website editor's interactions: triggers (load, hover, click, in view, scroll progress, an island's action), target nodes, keyframes or timelines with typed values, breakpoint scopes and reduced motion, kept beside the trees by tree id; their validation against the trees and the styles, the page's JSON, and one small runtime on the Web Animations API (@shadestack/interactions/runtime, no imports). Framework-free, on @shadestack/tree and @shadestack/styles (Other frameworks). |
packages/a11y | @shadestack/a11y: the website editor's accessibility checker: checks a page's tree with its layout, components, styles and languages, inside components and through every branch (headings, alt texts, names and labels, first children, ids, landmarks, contrast in every mode, focus styles, the language of parts), and returns { errors, warnings }; errors (WCAG 2.1 AA failures, and what it can't read) block publishing, warnings (what WCAG doesn't require) don't. Framework-free, on @shadestack/tree and @shadestack/styles (Other frameworks). |
tree, expressions, styles, render, interactions and a11y are the website editor's packages: the website
module and the frontends build on them, core and the module SDK don't
(Core and the website module).
Rules (checked by pnpm lint: no-restricted-imports in eslint.config.mjs and apps/admin/eslint.config.mjs):
shared/depends on nothing but zod and othershared/parts. Anything shared crosses into the browser as a schema type.- Services never import an HTTP framework, Astro or
process.env. Everything they need arrives throughServiceContext. - Only the API reads the environment (
apps/api/src/config.ts, parsed once at start; where the values come from, the environment,SHADE_ENV_FILEor the development.env, isapps/api/src/env-file.ts). admin/andsite/parts, the admin shell and the site never import services or db. The admin calls/api; the site calls the content API through the sdk, so it can build anywhere.- Core never imports the website editor's packages (
@shadestack/tree,styles,expressions,render,interactions,a11y): nothing inshade/, the module SDK and core's tests included. - Client sites never use Nuxt UI. Pages style themselves with the site's styles and the theme's CSS variables only.
- In the repository the package exports TypeScript source; on npm it is built JavaScript with declaration files
(
pnpm release:packages, Releases). Nuxt, Astro and Vitest compile the source, and Node runs it as it is (its own type stripping) for the API in development, the console scripts, the worker threads and modules loaded from folders. So the code uses only syntax Node can strip (erasableSyntaxOnly: no enums, namespaces or parameter properties), and every relative import names its file, extension included (./context.ts,./blocks/index.ts):pnpm lintchecks it in SHADE (scripts/import-extensions.mjs) and the workspace'spnpm testin the modules and the site.apps/api/scripts/build.mjsbundles the API with esbuild (dist/server.mjs,dist/console/create-admin.mjs); sharp, which is native, stays outside the bundle and the image installs it for its own platform (apps/api/Dockerfile).
The kernel, the modules and the architecture test
Core is a small kernel and the modules around it (decision 0019). The layers it had until 2 December 2026 (kernel, foundation, business, content, content-delivery, management, entry) are gone. SHADE is still being restructured toward the shape decision 0019 plans, in steps; this section describes what the code has today, and what is not built yet is marked as planned.
- The kernel holds the database, the service context, errors, permissions, the vault, the registries, the module loader and the ports. It imports no module.
- Its runtime library is the kernel's files every module may use for errors, logging, traces, metrics, time, ids
and formats, such as
errors.ts,log.tsandtime.ts. They load only each other. It is a list in the map (RUNTIME_LIBRARYinscripts/architecture/map.ts) rather than a folder, so no import path changed. - A module is made of one or more parts and is either always on or switched per instance.
shade/exports/modules.tslists every module, its parts and whether it is always on:defineModule({ name, parts, always })(kernel/module.ts), pure data the test reads without running it, as it readsfeature.ts. Thecontentmodule, for example, is the partsentries,fields,pathsand the other content parts;businessis switched and holds money, tax, numbering and the other business parts. Until modules get folders of their own, each part keeps its folder and itsfeature.ts. - The entry points,
exports,module-sdkandsdk, assemble the packages and are in no module. - Permissions: the kernel keeps the mechanism (principals, classes, ceilings, grants, steps, token presets and
decide) and only its own action,modules.manage. Each module declares its own actions, what the editor and AI roles hold by default, what core's background work (the system) holds and its steps, in ashared/permissions.tsof one of its parts (defineModulePermissions,kernel/module.ts), in the shape of a module manifest'spermissionspart.shade/exports/permissions.tsgathers them (MODULE_PERMISSIONS,@shadestack/core/module-permissions) and every start registers them (registerModulePermissions); until thendecide,registerActionsandreservedNamesrefuse to answer. A module whose actions follow its data registers them as they come: content registers each collection's actions with their classes as the content model loads, and keeps field rules, entry limits and data tokens beside them. Only a module may lift a class on one surface, as content does for the AI's delete of anaiDeletescollection over MCP; a module never can. The module names core reserves (reservedNames()) are built from the modules, their parts and the namespaces they declare.
The rules, held by the architecture test:
- The kernel imports nothing outside the kernel, not even a type, and the runtime library loads nothing else of it.
- Every part is in exactly one module.
- A part is entered through its front door,
index.ts,shared/index.tsorserver/index.tsin its folder, and only a part itsfeature.tslists inneeds; that is how one module reaches another. The kernel's files are all front doors, and the entry points may reach anywhere. Every entry of the package's export map points at a front door, an entry point inexports/or the kernel. No module imports an entry point. - An always-on module needs a switched one only where the map's
ALWAYS_NEEDS_SWITCHEDnames the pair, with its reason, such ascontent → cache(saving an entry clears the modules' cache). A switched module stays loaded while off, so each pair is safe, and each is turned around (a registration or an event) as its modules are ported. The list only shrinks: a new pair fails the test, and so does a listed pair the code no longer has. - The admin's auto-imports count as imports. A part's admin file that uses another part's composable, util or
component by name, with no import statement, is held to its
needslike any import (the auto-imports are the admin's way into a part, so the front-door rule doesn't apply to them). Adeclare modulethat widens another part's types counts as a type-only import of that module: an event's payload is declared through the events part's front door,declare module '…/events/shared'. - The two sides of the wall never import or need each other: the team part and the accounts part. What both need is in
the kernel (the password hashing, the ids
TeamMemberIdandAccountId), or is put together by the API's controllers.pnpm lintalso runs a word check: no "user" on the team's side, no "group" on the accounts' side, and no bare "member" in the admin's English texts. - A module declares only actions and steps that start with one of its own namespaces, no namespace has two declarers
(the kernel counts as one), and no file of the kernel names a module's action, except where the map's
KERNEL_NAMES_MODULE_ACTIONnames the file with its reason (a list that only shrinks). - A module's code checks by name (
can,assertCan,decide) only its own actions, those of a module its parts need, and the shared gates a module marks for everyone (settings.readandsettings.update,content.read,private.read,errors.readanderrors.manage); any other pair is listed in the map'sMODULE_CHECKS_OTHERS_ACTIONwith its reason (a list that only shrinks). - Runtime imports between files form no cycles. Modules may need each other both ways: they start in one order the kernel sets, never in the order of their needs, so there is no rule on cycles between modules.
- Every part of a module declares itself in a
feature.tsat the root of its folder:export default defineFeature({ needs, tables, referenceable })(kernel/feature.ts).needslists the parts whose front doors it imports (the kernel is every part's),tablesthe tables it owns,referenceablethe ones another part's*.sql.tsmay hold a foreign key to (a front door exports no other table). Two more keys are about row-level security:policiesopens one of its tables to another module, with the verbs and the reason ({ table, to, verbs, why }), andunguardedleaves a table open to every module for reading, its writes staying its own (only the search index, kept that way byUNGUARDED_TABLESin the map). Whether a module can be switched off is inexports/modules.ts:always: falsewithswitch: true(decisions 0003 point 20.5 and 0019). To add a part: make its folder, add it tomap.tsand to a module inexports/modules.ts, and write itsfeature.ts; the architecture test says what is missing or wrong. - A part that must not import another offers a registry, sends an event, or takes a port on the service context instead.
- Row-level security (decision 0019 point 8.2) holds the same line in Postgres. Each table's owner is the module
whose part lists it (
kernelfor the kernel's six,package:<name>for a module's), and its policies pass a statement only when the scoped handle runs it as that owner in the one tenant,main. The owner's stepkernel/upgrades/row-security.tswrites them after every migration run, fromexports/row-security.ts(core's tables from each part'sfeature.ts) and the modules' manifests, and the start refuses a guarded table without row-level security. A module's tables are opened by the kernel toplugins(read and delete: the uninstall backup, the export, the clean-up), its collection tables tocontent, an account scope or profile table, or one whose rows go with an organisation, toaccounts, and the tables itskeptVersionsnames tocontentfor reading.contactsis opened for reading to each module whose tables refer to it. Modules never get a policy onaccounts: the SDK'sownedBy(column, { email })andownedByOrganisationread two narrow views the owner makes in the same step,accounts_for_packages(id,email) andorganisation_members_for_packages(organisation_id,account_id), which show rows only to a module whose tables refer to accounts or organisations, andnotInTrashreads a third,entry_trash_for_packages, shown to a module with collections. Nobody but the owner writes through them. Who may do what to which table is a committed snapshot,shade/test/kernel/upgrades/row-security.snapshot.json: a change to it shows in review. It guards against bugs, not hostile code: anything in the API's process, a trusted module included, could name another owner itself.
How the kernel keeps to this:
- Ports and actors. The service context's ports (
FilesDriverasctx.files,EmailDriver,RebuildTrigger) are defined inkernel/ports.tsand the actor types (Actor,Role,Via) inkernel/actor.ts; media, email, content delivery and users implement or re-export them. Where actors are stored is the kernel's too:kernel/identity/identity.sql.ts(users,team_roles, theroleandviaenums), so audit refers to a user without using the users part; signing in, tokens and managing the team stay in users. The ports for work in flight (leases, queue, messages, counters, cache) are declared there too; a part that changes what other containers keep in memory announces it after commit withkernel/coordination/follow.ts'sannounce(Redis and the ports). - Manifest parts. The manifest's core parts (name, routes, permissions, schedules, allowed sources, …) are in
kernel/modules/define.ts(CORE_PARTS). Every other part (settings, collections, publish checks, data sources, MCP tools, retention, personal data, consent, the admin's parts) is a feature part: the feature'smanifest.tsdeclares the key onShadeModuleand registers aManifestPart(kernel/modules/manifest-parts.ts) that checks and registers it.exports/manifest-parts.tsloads every feature'smanifest.ts, and the entries that load modules (@shadestack/core/installed, the core entry, the module SDK) load it first. A key no part owns is refused, so a part is never silently ignored. - Events. A part says what happened without knowing who listens (decision 0014): it declares its events with
defineEventand writes them withemitEventin the change's transaction (entries:entries.entry.published…, inentries/server/events.ts). Core's parts subscribe in code (subscribe), modules in the manifest parton; durable deliveries run on the worker from the outbox (features/events). - What entries asks of higher parts goes through
entries/server/outside.ts: content delivery registers which entries can be linked and how a linked entry's public path is found (setEntryLinks). Public media (media/server/public.ts) and the public language check (publicLanguage, settings) live in the lower parts that own them. - Date helpers (
localParts,zonedInstant) are the kernel's:kernel/time.ts. - What a part keeps (personal data, retention periods) is registered by that part, in its
server/kept-data.ts. - Feature parts work one way: checks first (each module's, then the catalog's), then
reset,registerandfinish; names follow one rule (kernel/modules/names.ts); registries refuse a name that is taken. The admin's module switch comes from the server's (GET /api/packages/catalog/switches: every installed module, and which are on), so untrusted modules and packages are switched there like the others. - Providers with settings register in one shape with the provider registry (
registerProviderSetup: configured, on, depends on), which the module manager and the providers' own guards read. - Tables: parts import their own tables and other parts' through their front doors; the aggregate of every
table is
exports/tables.ts, outside the kernel. What one part asked of another's table the wrong way round is now a question the higher part answers: users tells email an editor's language (setEditorLanguages), media tells settings a file's type (setMediaTypes), redirects forgets a deleted entry's public paths onentry.deleted.
Core has no runtime import cycles, and the kernel imports nothing from a module.
scripts/architecture/map.ts in the shade repository is the map: the kernel's runtime library, every part with its
folder and what it is for, the entry points and the always-on modules' needs of switched ones; exports/modules.ts
is the list of modules. test/scripts/architecture/architecture.test.ts (part of pnpm test) reads every import in
shade/ with the TypeScript compiler (with the names the admin auto-imports and the modules declare module widens)
and fails on an import across the kernel's boundaries, an import past a front door, a new runtime cycle, an import of
another part's table outside a *.sql.ts, code that disagrees with a part's feature.ts (an import of a part it
doesn't list in needs, a table it declares and doesn't list, a foreign key to a table that isn't referenceable, a
front door exporting such a table), a part in no module or in two, an always-on module needing a switched one the map
doesn't list, or a part missing from the map; canary cases prove each check can fail.
What breaks the rules today is listed in scripts/architecture/baseline.json: no imports past a front door, no
imports of another part's tables and no cycles. A new violation fails the test; when a cleanup fixes some, the test
fails until pnpm architecture:baseline takes them out, so the list only shrinks. That command never adds anything;
pnpm architecture:baseline --init rewrites it, and is only for changes to the rules, in review. Imports past a
front door and imports of another part's table are never listed: the test fails on one, and the command refuses to
run while there is one. The kernel's boundaries and the module checks have no baseline at all. A new part is a change
to map.ts and exports/modules.ts, reviewed like code.
- The baseline has no front-door or table lines left. A part reads only its own tables and asks the owner's services for the rest (a foreign key in a
*.sql.tsandexports/tables.tsare allowed; the team's two tables, declared in the kernel, are the team's:TABLE_OWNERSinmap.ts; decision 0003 point 20). Field kinds own what they produce (fields/plan.ts); the json field finds the links and media in its value withfields/references.ts, and the module that registers its check decides the rest.
Seeing the map: Haunt
Haunt (razerghost/haunt, a tool of its own, outside the SHADE workspace) is a desktop git client that draws a
TypeScript project in bands of parts, with every function, its calls and the imports between parts. It runs on your
own machine and updates when you save a file. Install it from its releases, then open the shade folder.
It reads SHADE's map from the code, not from a copy. haunt.config.json at the root of shade names
scripts/architecture/haunt.ts, which returns SHADE's bands (the entry points, each module, the kernel) and parts, which part a file is in, and every import
between parts as the architecture test judges it, with the imports baseline.json lists marked as known.
test/scripts/architecture/haunt.test.ts holds that to the test: the same modules and parts, and the same imports
breaking the same rules. Haunt only runs this script once you trust the folder; until then it draws SHADE by
workspace package, without the rules. The apps and the packages are drawn by workspace package either way.
The API
apps/api is laid out like Laravel:
Path (in apps/api/src/) | What it holds |
|---|---|
routes/api.ts | The admin API: every URL → controller action, with the group's middleware (body limit, same-origin, session); also the modules' editor routes |
routes/content.ts | The content API for the site build, /preview and other frontends (read token) |
routes/data.ts | The data API for other systems (data token) |
routes/user.ts | The account API (public role): accounts, module routes (the payments module's webhook among them) |
routes/mcp.ts | MCP (mcp token, rate limit) |
routes/web.ts | /health, /api/v1/openapi.json, /uploads, the admin's icons (/_nuxt_icon), and last the admin screens' files |
http/controllers/ | Thin actions per resource: parse input, call a service, return |
http/middleware/ | auth.ts (session and tokens), origin.ts (same-origin), protection.ts (rate limits, idempotency, webhook signatures), body-limit.ts |
http/router.ts | Route groups: a prefix and middleware for the routes written inside them |
http/openapi.ts | The OpenAPI document of the versioned API |
http/csp.ts | The admin screens' Content-Security-Policy |
http/client-ip.ts | The visitor's IP behind our own proxies |
http/errors.ts, input.ts, context.ts, env.ts | |
bootstrap/ | app.ts (the route groups per role), runtime.ts (with follow(): what other containers change, through Redis messages), start.ts, restart.ts (restart requests), content.ts |
console/ | create-admin, env-file (a new env file), generate-collections, module-keys and sign-module (signing sandbox packages) |
sandbox/ | Untrusted modules: a workerd process per module, the gate, the bridge, the watchdog |
redis/ | The Redis driver: the kernel's five ports on ioredis, its only import (Redis and the ports) |
config.ts | The environment, checked with Zod |
env-file.ts | Where it comes from: the environment, SHADE_ENV_FILE (checked), the development .env |
server.ts | Its own server: start-up, listen, graceful shutdown (pnpm --filter @shadestack/api dev) |
A route is protected by the group it is written in: there are no lists of paths that skip a check. The services
stay in shade/features/*.
Request flow
sequenceDiagram
accTitle: A request's path from an admin screen to the database
accDescr: A Vue page in apps/admin/app/pages calls $fetch('/api/collections/posts/123'). The route in apps/api/src/routes/api.ts runs action show in apps/api/src/http/controllers/collections.ts; the group's middleware, withSession(), gives it a ServiceContext with db, actor, via, files and rebuild. The action parses params, body and query with a schema, then calls the core service in shade/features/entries/server/collections.ts. The service checks permission with assertCan(ctx.actor, action), validates with parseInput(Schema, input), writes in ctx.db.transaction and adds an audit entry with recordAudit, through Drizzle to Postgres (shade/kernel/db). On an error, onError turns a ShadeError into an HTTP status and an ApiErrorBody: NOT_FOUND 404, FORBIDDEN 403, UNAUTHORIZED 401, VALIDATION 422, CONFLICT 409.
participant page as Vue page<br>(apps/admin/app/pages)
participant route as Route and action<br>(apps/api)
participant service as Service<br>(shade/features/entries/<br>server/collections.ts)
participant db as Postgres<br>(shade/kernel/db)
page->>route: $fetch('/api/collections/posts/123')
Note over route: route (apps/api/src/routes/api.ts)<br>→ action show (apps/api/src/http/controllers/collections.ts)<br>group middleware: withSession()<br>→ ServiceContext { db, actor, via, files, rebuild }
Note over route: 1. parse params/body/query with a schema<br>(param/body/query helpers)
route->>service: 2. call the core service
Note over service: 1. assertCan(ctx.actor, action): permission check<br>2. parseInput(Schema, input): validation<br>3. ctx.db.transaction(tx => …): writes<br>4. recordAudit(tx, …): audit entry
service->>db: Drizzle
route-->>page: onError: ShadeError → HTTP status + ApiErrorBody<br>(NOT_FOUND 404, FORBIDDEN 403, UNAUTHORIZED 401,<br>VALIDATION 422, CONFLICT 409)
Routes stay thin: parse, call, return. If a route grows logic, it belongs in core.
Who may call what is tested as a whole, so a check that goes missing fails a test:
shade/test/contract/service-access.test.tsfinds every function@shadestack/core/servicesand the module SDK export whose first parameter is a context or a database (by its type, so{ db }andDbOrTxcount too) and holds it to its line inshade/test/contract/service-access.ts: it refuses nobody, and an editor whose role grants nothing, before it reads or writes anything, or the line says why it needs no actor (signing in, a module's shared service, core's own jobs), or, for one taking a database and no actor (internal), why its callers check first.apps/api/test/sweep/access.test.tscalls every route the app serves (an untrusted module's too) as nobody, a visitor, an editor, an editor with a custom role, each kind of token (data tokens that may only read, or whose owner may only read) and an admin, and compares the answers withapps/api/test/sweep/access-table.ts, one line per route. Some routes are called again on a second collection, on real rows or with a real MCP call, each a lineMETHOD /path#variant. A new route needs its line there; review it as you would the route. The sweep runs in four parts side by side (access-2.test.tstoaccess-4.test.ts, fromroutes/testing/access-sweep.ts); the first one also checks that the table and the app list the same routes.
Environment
All variables are documented in .env.example. In development every app reads the repo-root .env
(loadDevEnvFile in the API's config.ts, nuxt dev --dotenv for the admin, process.loadEnvFile in
drizzle.config.ts; the site reads its own .env, then SHADE's next to it). pnpm dev starts the API (port 4000)
and the admin's dev server (port 3000, SHADE_API_URL), which forwards /api, /uploads and /health to the API so
the browser sees one origin; the SHADE workspace's pnpm dev adds the site (port 4321). In production, Coolify
injects them.
pnpm dev runs the apps through pnpm's parallel runner, which has two traps on Windows: it takes Node flags such as
--env-file itself, and tsx watch hung under it without a word. So the API loads .env in code and its dev
script uses Node's own watcher and type stripping (node --watch src/server.ts). pnpm dev:check (scripts/dev-check.mjs) runs the real
pnpm dev, waits until the API and the admin answer and stops them; run it after changing a dev script or a dependency
that starts with the apps. The API logs each start-up step (database, migrations, modules, jobs), says what to check
when it cannot reach the database.