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

SHADE
Writing a plugin

Module SDK and tooling

The module SDK

A module uses SHADE only through the module SDK, the package @shadestack/module-sdk, and otherwise only its own folder and packages such as drizzle-orm and zod. Behind the SDK core can change without breaking modules. Lint enforces it: no import leaves the module's folder, and no other SHADE package is used, which is how a module in its own repository works. Every name the SDK offers is in its contract (see The SDK's promise), so the SDK only changes on purpose. To build a client's module from start to finish, follow Build a client module.

EntryFile in shade/module-sdk/For
@shadestack/module-sdk/serverserver.tsThe manifest and server/: defineModule, the service context, assertCan, conditionsOf, errors, recordAudit, column helpers (teamMemberReference for a column referring to a team member, accountReference and ownedBy for data that belongs to an account, inScope and assignAccountRole for account roles, collectionReferences for generated collection tables), the content services (listEntries, getEntry, createEntry, saveEntry, publishEntry, unpublishEntry, deleteEntry, listMedia, getMedia, uploadMedia), the lookups a json field's check makes with the database alone (findMediaTypes, findDataSource, dataSourceParameterIssues, findPublishedForms, findVisitorRoute), actAsModule for a data source that reads with the module's own grants, assertModuleAdmin for the routes a settings section calls, published entries, the versions waiting to be published (versionsAwaitingPublish), settings, isSitePath, and the email and payments services. Not core's tables: module code reaches core's data through services. Includes everything in shared.
@shadestack/module-sdk/sharedshared.tsshared/ and admin/: browser-safe types and schemas, defineCollection, and ActionRegistry, to which a module adds its permission names (declare module '@shadestack/module-sdk/shared' { interface ActionRegistry { 'my-plugin.read': true } }).
@shadestack/module-sdk/sitesite.tssite/: SiteHeadProps, plus shared. A site part imports the responsive Image from @shadestack/astro/site (the kit's; the SDK no longer gives it, 24 November 2026, decision 0016 point 12).
@shadestack/module-sdk/testingtesting.tsTests only (*.test.ts, e2e/; shade-module build refuses shipped code that imports it): testInstance(plugins, options) (a migrated test database with the modules installed and on, their collections, permissions and the site's settings: { db, owner, ctx(role), close() }, owner being the database owner's handle for a test's own set-up and checks), runQueuedJobs (the due jobs, one try each, as the worker runs them: how a test runs the on handlers a change caused), the test database, core's tables to seed and check an instance, the vault, the module loader and switch, setModuleSettings(db, plugin, settings) and grantCapability(db, plugin, capability, params?) (a module's stored settings and agreed capabilities, without writing core's tables), and resetting permissions and collections. It also gives core's services a test drives an instance with (entries, modules, payments, privacy, retention, redirects, the audit log); those follow core and are less stable than the rest of the SDK.
@shadestack/module-sdk/test-databasetest-database.tsA module's vitest.config.ts: moduleTestConfig(), the vitest settings every module shares, and testDatabase(), SHADE's test server for its Postgres tests.
@shadestack/module-sdk/contractcontract.tsThe contract data (SDK_CONTRACT, from contract.json) and the warnings about a module (sdkImportsOf, deprecatedUses, deprecationWarningsOf, experimentalNoticeOf and the like), for tools such as a module hub or a CI linter. SHADE's own release checks are not part of it. A module rarely needs it.

The website editor's names (the tree and style builders, the starter helpers, checkComponent) are not the module SDK's: they are the website module's own, in The website module's SDK.

The SDK is its own package even while it lives in shade/module-sdk/ (shade depends on it), so the modules in this repository import it exactly as modules in their own repositories will. If a module needs something the SDK does not offer, add it to the SDK on purpose (the entry file, the contract and this table), not as a direct import.

The SDK's promise

The SDK's names are a contract: shade/module-sdk/contract.json lists every name a module may rely on, with since, the SHADE version that added it:

  • each entry point's exports, values and types alike;
  • the manifest's parts (manifest: name, requires, uses, collections, admin, …);
  • the admin host's names a module's admin screens use without importing them: admin host imports (useFetch, useCan, apiErrorMessage, …), admin host Vue imports (ref, computed, …) and admin host components (AdminTopBar, FieldForm, FieldRenderer, the field editors and RelativeTime).

sdk.test.ts holds the SDK to it: a name the SDK has that the contract doesn't list fails, so does one listed and gone. Changing the SDK:

  • adding a name: add it to contract.json with since (SHADE's version, shade/kernel/version.ts) and its kind (value or type), then pnpm sdk:changelog;
  • removing or renaming a name: first deprecate it, deprecated: { in: '<version>', use: '<new name>' }, and put a /** @deprecated … */ tag on its declaration (the test checks the two agree, so editors and type checks flag its use). It keeps working for at least one minor version; then list it as removed: '<version>', no earlier than the next minor version (from SHADE 1.0, only in a major version), and take it out;
  • a module that uses a deprecated name gets a warning naming it, when shade-module build packages it and when the API loads it (a warn line: The shop module uses listEntries from @shadestack/module-sdk/server, deprecated since SHADE 0.2.0; use findEntries instead. It keeps working until at least SHADE 0.3.0.). The API sees the manifest's parts and the SDK's names a package's module.mjs imports; the build also sees the admin host's names its screens use. Types are seen only by the type check, through the @deprecated tag.

Experimental manifest parts. A name marked experimental: true in the contract works, but may change in a minor version, from 1.0 too: its shape may change without notice, and it may go one minor version after its deprecation instead of waiting for a major one. In 0.1 these manifest parts are experimental: consent, contractAfter, dataMigrations, processes, searchText, on, shares, requires, export, sandbox, provides, alerts and oauth. A module that sets one gets a notice naming it and the parts, from shade-module build (Notice: The shop module uses the experimental manifest part "requires". It may change in a minor version of SHADE.) and in the API's log when it loads the module (an info line). From 1.0, give such a module a shade range within the minor version you tested (~1.4.0), and read the changelog's "Experimental" list before you update. Experimental parts lists every experimental part with the modules that use it.

Money (experimental). Work with money amounts (Money, made by money) from @shadestack/module-sdk/shared instead of floats: money(1250, 'EUR') is an integer of minor units with an ISO 4217 currency. addMoney, subtractMoney, sumMoney and multiplyMoney refuse to mix currencies; scaleMoney takes a share rounded once, and allocateMoney splits a money amount over weights so the parts always add up to the whole (shipping over VAT rates, a refund over invoice lines). vatInGross, netOfGross and vatOnNet work VAT with a rate of at most one decimal. Rounding (Rounding, each function's rounding) is 'half-up' (half away from zero) by default, and 'half-even' is available when a rule asks for it. formatMoney(value, 'nl-NL') writes a money amount in the locale's way and parseMoney('1.250,50', 'EUR', 'nl-NL') reads what an admin typed, or gives null. The shop module is the first account. formatMoney takes { amount, currency }, SHADE's money type.

The changelog, shade/module-sdk/CHANGELOG.md, says per SHADE version what was added, marked experimental, deprecated and removed, with the release's notes (releases in the contract, for what names can't say). It is written from the contract by pnpm sdk:changelog, and sdk.test.ts fails while the two differ.

From the first release on, pnpm release:packages also compares contract.json with the last release's, read from its tag: a name that release listed must still be listed, with the same kind and since, deprecated or removed as above (Releases).

The SHADE versions a module works with

SHADE and the SDK share one version (SHADE_VERSION, in shade/kernel/version.ts, the SDK's, core's and the packages' package.json; tests keep them equal), but for the Next.js, Nuxt and SvelteKit adapters, which have versions of their own (Releases). A module says which versions it works with in its manifest, as npm writes ranges: shade: '^0.1.0'. The loader refuses to start with a module made for another version, naming both. Ranges are full versions: ^1.4.0, ~1.4.0, 1.4.2, >=1.4.0 <2.0.0, alternatives with ||, and *. A pre-release comes before its release, as in npm: 1.4.0-beta.1 is not ^1.4.0.

  • From 1.0, removing or changing a name of the contract is a major version: ^1.4.0 is a promise that the module keeps working on every 1.x from 1.4, unless it uses an experimental part, which a minor version may change.
  • Before 1.0 (now), a minor version may still break the SDK, so ^0.1.0 means 0.1.x only. The contract applies all the same: every name is listed, none goes without a deprecation kept for a minor version, every change is in the changelog.

The field is optional for modules in this repository, which move with core, and required for server packages.

Publishing the SDK and the packages

The SDK, @shadestack/core and @shadestack/svg (in shade), and the frontend kit (in shade-frontend: @shadestack/client, astro, next, nuxt, sveltekit, and render, tree, expressions, styles, interactions and a11y they use) have publishConfig with access: public. SHADE's version covers only core, the SDK and svg; the kit has one version line of its own, with next, nuxt and sveltekit on their own lines inside it (Releases); they are published to npm, public, under the @shadestack scope, so frontends and modules install them with no .npmrc or token. They stay private in the workspace, so a stray pnpm publish refuses them; the release script publishes them:

pnpm release:packages                             # stage, pack and check every package; publish nothing
pnpm release:packages --publish                   # the release runner: the same, then publish the repository's packages
pnpm release:packages --publish --adapter next    # in shade-frontend: publish only that adapter, at its own version

Without --publish it is always a dry run (--dry-run says so explicitly). The registry is npm's public one, https://registry.npmjs.org/, unless --registry <https URL> names another; the token comes from the runner's npm configuration (//registry.npmjs.org/:_authToken=…), never from the repository. A package whose publishConfig.access isn't public is refused. Each package is staged as its folder with exactly the files its entry points reach, and its dependencies at the versions its own package.json gives (workspace: → that package's version). The SDK, made of core's files, depends on @shadestack/core at SHADE's exact version and imports core through it, never a copy: staging rewrites its imports of core's files to @shadestack/core/<entry> where core's exports give the file (@shadestack/core/installed), else to @shadestack/core/internal/<path>, which @shadestack/core has only as published, for the SDK (not a name for modules: the SDK's entry points are the contract). Its /site entry gives only types (Image is the kit's); only the test database's scripts are copied in (scripts/). The tarball is checked: SHADE's version (an adapter's own, with a SHADE range that holds SHADE's version and a changelog section for it), no workspace: left, every relative import inside the package, every other one declared, no file of another published package in it, and each package it imports through a dependency at SHADE's exact version that gives what it imports. Each package goes out built: JavaScript with declaration files, its exports { types, default }, no TypeScript source, so a module's scripts and shade-module itself run on plain Node from node_modules (which strips no types there); every run imports every entry and runs shade-module help from the packed tarballs to prove it. Nothing is published by hand: a version tag starts the release workflow on GitHub Actions, which publishes with provenance. Core, the SDK and svg are on npm as pre-releases under the next tag (npm install @shadestack/module-sdk@next); 0.1.0 isn't out (Releases).

The SHADE workspace

shadehq-dev/shade-workspace holds SHADE, the frontend kit, the docs, the site and the official modules as git submodules (shade/, frontend/, docs/, site/, modules/<name>/) with one pnpm workspace over them, so the modules use the module SDK straight from shade/. The workspace itself is private and this section is for SHADE's maintainers; a tested route for outside module authors comes later. Of the repositories it gathers, shade, shade-docs, shade-site, shade-frontend, shade-programs, shade-desk and the official modules except project and discord have been public since 4 December 2026. Their CI still runs inside this workspace.

git clone --recurse-submodules https://github.com/shadehq-dev/shade-workspace.git
cd shade-workspace && pnpm install
pnpm dev        # SHADE and its site, every modules/<name> with a module.ts loaded from its folder (SHADE_DEV_MODULES)
pnpm test       # every plugin's tests and the site's unit tests;  pnpm package: every plugin's package
pnpm typecheck  # every plugin, the site (astro check) and the plugins' admin screens (.vue, with the admin's nuxt typecheck)
  • CI: each module's repository, shade-site and the workspace have a workflow that checks out the workspace with the commit under test in it, installs from the workspace's lockfile (--frozen-lockfile: that lockfile locks them all), and runs pnpm typecheck, pnpm test and the repository's browser tests. They need a repository secret SHADE_WORKSPACE_TOKEN that may read the private repositories.
  • The workspace's checks are SHADE's guard for what it doesn't see itself: run pnpm typecheck and pnpm test here (and pnpm test:e2e in site/) when a change to SHADE touches what the site or the modules use. The admin screens of the modules are type-checked by loading every modules/<name> as a dev module into nuxt typecheck.
  • Install from the workspace, never inside shade/, which keeps a workspace of its own for working on SHADE alone.
  • The workspace installs exactly SHADE's versions: its pnpm-lock.yaml is written from shade/pnpm-lock.yaml by pnpm sync-lockfile (SHADE's packages moved under shade/), then pnpm install adds only the modules' own. Run it whenever shade/ moves to a commit with other dependencies.
  • The submodule pointers record which commits belong together. A change across repositories is a branch and pull request in each, merged together, then the pointers moved to the merged commits.
  • SHADE itself never names a module; only the workspace knows the full set.

Starting a module repository

shade-module init opening-times [--out <folder>]   → ./shade-plugin-opening-times

writes a module repository that loads in development mode, passes validation and packages as it is: package.json (depending on the SDK from npm in SHADE's range, "@shadestack/module-sdk": "^0.1.0", with no .npmrc; before 0.1.0 that range names the pre-release, such as ^0.1.0-next.2; a module developed inside the SHADE workspace switches it to "workspace:^"), module.ts with a setting, a permission, a public route and a signed-in one, an admin page with a sidebar entry, shared/schema.ts adding its permission name to the SDK's ActionRegistry, server/routes.ts and server/service.ts (its services start with assertCan), the admin texts in English and Dutch, a test, a tsconfig.json, a .gitignore (keys, dist and .data stay out) and a README with the commands for working on it, packaging and signing. The name must be one a module may have (kebab-case, not one of core's). Put the new repository in the workspace's modules/ folder, list it in SHADE_DEV_MODULES, and pnpm dev.

The template is shade/module-sdk/tools/template.ts; template.test.ts loads a new module in development mode, validates and packages it, and checks its texts have the same keys in both languages.

Its texts

A module's admin texts are translation keys under its camelCase name in <admin.locales>/en.json and nl.json; <name>.plugin.title and .description name it on the Modules screen. <name>.actions.<rest> names each of its actions (shop.orders.read → shop.actions.orders.read: "View orders") in the role picker, the token list and the audit log, beside its title; <name>.accountRoles.<role> and <name>.abilities.<rest> name its account roles and what they allow in an account's Roles. What has no text reads as words ("Orders refund"), never as its id. Its definitions (collection and field labels, help, choices) and the fixed error messages its server code sends are written in English and translated next to them (core's messages all go by key; a module's may still go by sentence until 1.0):

  • labels.nl.json: English → Dutch for its definitions' texts;
  • errors.nl.json: English → Dutch for its fixed messages (notFound, validation and the like, and issue messages).
  • A message with a value in it goes by key: the helper takes { key, params } first, the English sentence after it (for the log and other clients), and the key is one of its admin texts under its own name, in both languages:
    throw conflict({ key: 'invoices.errors.alreadySent', params: { number } }, `Invoice ${number} was already sent`)
    // admin/locales/en.json: { "invoices": { "errors": { "alreadySent": "Invoice {number} was already sent" } } }
    

    checkModuleTexts refuses a key that is not under its name, or that its admin texts lack.

The admin looks there after its own files (apps/admin/app/utils/module-texts.ts): built-in and development modules' at start (modules/shade-installed-modules.ts), server packages' from the API. A module carries every text it shows, also those core translates too. checkModuleTexts(plugin, dir) from @shadestack/module-sdk/testing (shade/module-sdk/tools/texts.ts) lists what is missing or left over, the same checks core runs on its own (apps/admin/test/checks/labels.test.ts, messages.test.ts, which use it too); a module's module.test.ts expects it to be empty.

Its browser tests

A module's Playwright tests run against SHADE's own test instance with the module installed as a package, as a client's instance would have it (shade/e2e/modules.ts, plugin-config.ts):

// e2e/playwright.config.ts                      // e2e/site.config.ts
import { moduleE2eConfig } from '@shadestack/e2e/module-config'    // moduleSiteE2eConfig
export default moduleE2eConfig(new URL('..', import.meta.url))
  • pnpm test:e2e runs e2e/*.spec.ts in the admin, signed in as SHADE's test admin (SHADE's own sign-in step); pnpm test:site runs e2e/site/*.spec.ts on SHADE's built site (site/ in the workspace). Helpers: @shadestack/e2e/helpers (setUpEmail), @shadestack/e2e/site-paths, and @shadestack/e2e/a11y's expectAccessible(page, { exclude, disable }) (axe, WCAG 2.1 A and AA, failing on any violation), which the official modules run on their starter components (the cart, empty and filled, the order page, the booking form sent with and without its details). exclude leaves out parts you do not own; disable switches rules off for one check, each with its reason ({ 'color-contrast': 'why' }).
  • The scripts run Playwright through SHADE's e2e/run.ts, which waits for the machine's browser tests lock first, so only one browser run goes at a time (Tests): "test:e2e": "node node_modules/@shadestack/e2e/run.ts test --config e2e/playwright.config.ts", and test:site the same with e2e/site.config.ts.
  • The harness sets SHADE_E2E_MODULES to the module's folder: it is packaged with shade-module build, signed with a key made for the run and trusted by it only, and stored as installed (switched off) before the API starts.
  • e2e/site-seed.ts (export async function seedSite(ctx)) puts its content on the site once the API has loaded the packages (their tables exist), before the site is built. A module whose pages are the website module's installs it first: moduleSiteE2eConfig(new URL('..', import.meta.url), { plugins: [new URL('../../website', import.meta.url)] }) (and moduleE2eConfig the same way for its admin tests); the seeds run in that order, so its seed adds its pages to the website module's website-pages. SHADE's own site installs it with siteE2eConfig(…, { plugins }).
  • SHADE's admin and API are built first by the run itself (node shade/scripts/e2e-build.mjs, which builds each only when it changed since its last build, or copies the build of the same inputs from the machine's cache; not in CI, which brings the build job's output). The API's database starts as a copy of the test slot's migrated template, so only the first run after a change of SHADE's migrations migrates. The tests run on SHADE's test Postgres container, started for them (Docker must be running), or on SHADE_TEST_DATABASE_URL, and the API on SHADE's test Redis (redis-test, started for them too, or E2E_REDIS_URL; every instance has Redis, Redis and the ports); a module's Postgres unit tests get the same server from moduleTestConfig() in @shadestack/module-sdk/test-database: export default defineConfig(moduleTestConfig()) in its vitest.config.ts. It sets the tests (test/**/*.test.ts), the timeouts, the test server (testDatabase(), which also passes on the checkout's test slot, SHADE_TEST_SLOT, so its tests make and replace only that slot's migrated template), how many test files run at once (about half the cores, or SHADE_TEST_WORKERS) and the module's own module cache, node_modules/.vitest-cache. Vitest's default is one folder at the workspace root, which every run clears when the lockfile changes, so the workspace's pnpm test, which runs the modules and the site in parallel, would have them remove it under each other. A module that needs more spreads the result into its own defineConfig. A test database's db connects as the running role shade_app, so row-level security applies in tests as it does in production. Row-level security lets a statement touch a module's tables only when it runs as the module, so a test reads and writes them through the module's context (the testing entry's moduleContext) or, for fixtures and checks of its own, test.owner; a statement on test.db itself sees no rows. test.owner is the owner's handle for a test's own DDL, and loadModules from the testing entry migrates a test database as its owner by itself (The database's roles).
  • A test of two writes at once holds a table lock in a transaction of its own with holdLock(db, sqllock table …) from the testing entry, waits with untilWaiting(db, sessions, …running) until the other writes queue behind it and reads how each ended with outcomeOf(promise).
  • A test that builds a context with rate limits gives it extra: { counters: memoryCounters() } from the testing entry: the same fixed windows as the Redis counters, kept in memory, so a new instance of them starts empty.
  • A browser test of a module signs in and makes team members with signIn and createTeamMember from @shadestack/e2e/helpers.

Development mode: a module from its own folder

A module in its own repository is developed against a running SHADE without installing it. List its folder in the repository's .env, comma-separated, relative to the repository root:

SHADE_DEV_MODULES=../shade-plugin-appointments

pnpm dev then loads it as if it were installed: the API imports its module.ts (loadDevModules in shade/kernel/modules/dev.ts) and logs development: appointments 0.2.0 from …, and the admin's dev server mounts its pages and texts and compiles its CSS classes (apps/admin/app/assets/css/dev-plugins.css, written on every start and ignored by git). Its migrations come from its own folder.

  • A folder's module replaces a server package of the same name, so a module can be worked on while the instance has its package.
  • The folder needs its dependencies installed (in the workspace, @shadestack/module-sdk comes from shade/).
  • Node runs the folder's TypeScript as it is (its own type stripping, no build step): every relative import names its file, extension included (./server/routes.ts), and the code uses only syntax Node can strip (no enums, namespaces or parameter properties; erasableSyntaxOnly in the module's tsconfig.json, as shade-module init writes it).
  • Its site part renders in astro dev too: site/astro.config.mjs passes the folders to shade({ devModules }).
  • Its collections work too: their tables come from its migrations, like a package's.
  • Development only: the code is unsigned, so the API refuses to start with SHADE_DEV_MODULES when NODE_ENV=production, and the admin's build never reads it.

Packaging and signing

An instance installs a module as one file, a package. The SDK's command, shade-module, makes and signs it; a module repository has it through its dependency on @shadestack/module-sdk (in this repository: node shade/module-sdk/bin/shade-module.mjs).

shade-module build [folder] [--out <folder>] [--release]  → <name>-<version>.shade-module.json (--release: a direct fetch is an error)
shade-module sign <package> --name <key name> [--key <private key file>]
shade-module keys --out <private key file>                → the public key for SHADE_TRUSTED_MODULE_KEYS (never overwrites a file)
shade-module collections [folder]                         → server/collections.generated.sql.ts (see Collections from plugins)
  • What a package holds (format: 2; sandbox packages are format 1): the name, version, the SHADE versions it works with and its description, and files, which mirror the module's folder so installing is unpacking them:
    • module.mjs: the manifest and all server code, bundled into one ES module with esbuild. The module's own code and npm packages are inside it; @shadestack/module-sdk, zod and drizzle-orm stay outside, because their values cross between the module and core and must be the instance's own;
    • its admin pages compiled for the admin to load at runtime (admin-dist/, see the section above), with its admin texts (the admin.locales folder); the .vue sources are not shipped;
    • changelog, when the module has a CHANGELOG.md: each ## <version> section's notes, the newest 30 versions, each at most 4000 characters (a longer one is refused). It is signed with the rest, and the consent screen of an update shows the versions after the installed one;
    • its migrations folder, and site/ and shared/ as they are: the site compiles them with its own build.

    Tests, node_modules and .data are left out. build refuses a module whose shipped code (the bundle's own files, the site, shared and admin sources) imports the SDK's test entries, @shadestack/module-sdk/testing or test-database (accountRouteContext makes an account route's context, which only SHADE makes on an instance), naming each file; tests, e2e/ and helpers only tests import may.
  • What it may do (capabilities): the manifest's capabilities declaration resolved (resolveCapabilities), each capability with its need, parameters and lines; beside it the actions its own actor may perform (uses) and the packages bundled into module.mjs (bundled, name@version, for the approval flow's advisory check). build refuses a manifest whose parts need a capability or a line it does not declare, naming each (its manifest needs the http capability for GET /wishlist (public): add capabilities.http); shade-module capabilities prints the declaration the manifest needs. The signature covers them, the consent screen is generated from them, and the API refuses to load a package whose module.mjs needs anything they leave out (logged as not loading the <name> package: its module.mjs needs what its signed capabilities do not declare …). A package built before the declaration, with signed abilities instead, is refused: build it again.
  • What build refuses: a module without shade (the SHADE versions it works with), and one validateModule refuses (collections without their generated tables among them).
  • Signing is an Ed25519 signature over the package without its signature, under a key name. The private key comes from --key or, in CI, from the secret SHADE_MODULE_SIGNING_KEY; it is never in a repository. An instance trusts the public key by name in SHADE_TRUSTED_MODULE_KEYS; a package changed after signing is refused.
  • Installing a server package: see Installing a trusted module above.

The code is shade/module-sdk/tools/package.ts (buildModulePackage, signModulePackage), tools/admin.ts (compileAdminPages) and tools/cli.ts, with their tests next to them: packaging appointments, its compiled page (no imports left, reading the host) and stylesheet, importing the unpacked module.mjs, the refusals, and signing round trips with a fresh key, also through the command as a repository's CI would.

Keeping a signing key

For anyone who signs modules: the project for the official modules, an operator who builds them from source and signs them with their own key, an agency or author who gives signed modules to operators, or an operator who signs modules made in-house. A key that is lost can sign nothing new, and a key that leaks lets anyone sign, so plan for both from the start.

  • Two key pairs from the start: a main one and a backup, each under its own name (rg-main and rg-backup, for example): shade-module keys --out rg-main.private.pem, then --out rg-backup.private.pem.
  • Both public keys on every instance. SHADE_TRUSTED_MODULE_KEYS takes several named keys: rg-main=<public key>,rg-backup=<public key>. Sign day to day with the main key only (--name rg-main).
  • The private keys apart. The main one encrypted in a password manager; the backup offline somewhere else, on an encrypted USB stick or printed (as text or a QR code) in a safe place: an Ed25519 key is short. Never in a repository, as a plain file in a cloud folder, or on a server.
  • The public keys are not secret. Keep them with the instances' configuration, and note each key's fingerprint: the 8 characters the Modules screen shows for it (in its technical details).
  • Test the backup once: sign a test package with it (--name rg-backup --key rg-backup.private.pem) and install it on a development instance.
  • The main key lost: sign with the backup at once; the instances need no change, since they trust it already. Then make a new backup key and add its public key everywhere.
  • The main key leaked: remove it from SHADE_TRUSTED_MODULE_KEYS on every instance (its packages stop loading at the next start), sign the modules again with the backup and install those packages, and make a new backup key.

Installing a trusted module

A signed package installs on the Modules screen (see Managing modules) and runs after the next restart. How it runs:

  • Next to the modules it builds on. A package carries its manifest's requires, signed. Installing refuses (VALIDATION, naming both) a package that requires a module with a range not within one major version, or whose required module is not installed or is of a version outside its range, and an update that an installed module requires with a range the update is outside of. The consent screen lists the modules it builds on, with their versions, and which of their shared collections it uses.
  • Consented to. The consent screen is generated from the package's capabilities: each capability in plain words with its lines (its routes, account roles, shared collections…), its parameters and what it keeps, a switch for each optional one, and what an update asks for that the installed version did not marked. Beside them, each action its own actor may perform (uses), in plain words. Installing sends what the admin agreed to (accepted: { capabilities: { <name>: { on } }, uses }); installModulePackage refuses (VALIDATION) unless it names every capability that asks again and every new use, so an update that asks for more is consented to again, and it refuses a package that requires a capability a trusted module may not have or this SHADE does not offer yet, in one sentence. What was agreed is kept per capability (module_capabilities).
  • Stored as signed. module_packages keeps the whole file, signature included (shade/features/packages/server/packages.ts). Every start works its trust out again (trustOf) against SHADE_TRUSTED_MODULE_KEYS, so taking a key out stops its packages from loading. Nothing in the package is read for its trust: one with a trust, trusted or approval key is refused.
  • Unpacked and imported at start (apps/api/src/module-packages.ts): each package into MODULE_PACKAGES_DIR/<name>@<version>/ (emptied every start), its module.mjs imported, then loaded. A package whose manifest needs more than its signed capabilities and uses is left out with the reason capabilities (unlistedCapabilities), and so is one whose required modules are missing, of another version or left out themselves (withRequirementsMet, reason requires), with the modules that build on it; the rest start. A development folder (SHADE_DEV_MODULES) replaces a package of the same name. A module that uses a deprecated name of the SDK is logged, by name.
  • On the instance's own modules. A package bundles everything except SHARED_MODULES (shade/features/packages/shared/packages.ts): @shadestack/module-sdk/server and /shared, zod, drizzle-orm and drizzle-orm/pg-core. A Node resolve hook (module.registerHooks, in apps/api/src/installed/package-imports.ts) sends a package's imports and requires of them to the API's own copies in src/installed/shared-modules/, and refuses the SDK's testing entries however they are reached; the production build (scripts/build.mjs) emits those as files of their own with code splitting, so they share one copy with server.mjs. Permissions and tables live in module state, so a second copy would not work. Installing refuses a package that imports any other bare module.
  • After a restart. The admin's restart request is a row in instance_restarts, announced on the restart channel; every API process that started before it stops gracefully (followRestartRequests in bootstrap/restart.ts, from server.ts), in production only (config.restartOnRequest), and Coolify or Docker starts it again. Each process checks the row at once on the message, and every 60 seconds in case the message was lost (Redis and the ports).
  • Its admin screens and site part load at runtime too: see the next section.