On this page
An optional tenant-facing feature is a plugin: a declarative manifest in one compiled catalog, switched on per organization by an installation row, guarding a page, a menu item and a data route.
When to use#
Use a plugin for a switch that gates a tenant-facing surface (ADR 0002 D5). A switch that changes platform behaviour (sign-in method, theme, BYOK) is a column on the organization; a licensed entitlement (white label, LDAP) stays where its own ADR put it. A data source is a plugin of kind: 'connector' and follows Add a data source; an external app is kind: 'satellite' (Connect a satellite app). Identity, tenancy, row-level security, roles, warehouse, i18n and audit are never plugins. There is no dynamic or third-party loading: plugins compile into the build.
The contract#
- Manifest schema:
pluginManifestSchemainpackages/plugin-host/src/manifest.ts, strict, parsed at module load; cross-field rules reject a field on the wrongkind. Every field is in Plugin development. - Catalog:
PLUGIN_REGISTRYinpackages/plugin-host/src/registry.ts(features, connectors, satellite in one file). - Gate:
isPluginEnabledForOrg,getEnabledPluginIdsForOrg,getDisabledNavItemsForOrginpackages/plugin-host/src/gate.ts; pure decisionresolveEnabledinresolve.ts. - Ledger: table
org_plugin_installations(enabled,is_active,status,valid_to;configis reserved with no reader or writer). - Page entitlement:
requirePlugin(id)(apps/web/src/server/plugin-guard.ts),requireAdminTenantPlugin(apps/web/src/server/admin-org-context.ts).
How registration works#
The manifest is appended to MANIFESTS in registry.ts and validated when the module loads, so a malformed one fails the build. A missing installation row means off. Rows are written by reconcilePluginRows (apps/web/src/server/org-blueprints/reconcile-plugins.ts) from the organization's shape on blueprint apply, on domain activation and on every deploy, and never override a super admin's manual row. defaultEnabled: true is valid only where the shape runs a home domain.
Add one#
- Print the snippets:
pnpm tsx scripts/scaffold-plugin.ts <id> <category> [navItemId ...](writes nothing; features only). - Paste the manifest into
MANIFESTSinpackages/plugin-host/src/registry.ts. List it in the blueprints that want it instead of usingdefaultEnabled: truewithout a home domain. - Add
plugins.<camelId>.nameand.descriptiontopackages/i18n/src/messages/vi.tsanden.ts. - Check each
navItemIdexists inORG_MENU_ITEMS(apps/web/src/lib/rbac.ts); add it toMENU_ITEM_LABEL_KEYSto make it renamable. - Add the router in
apps/web/src/server/routers/<feature>.tson a dedicated procedure when no core page reads it (aschatProceduredoes); otherwise keeporgProcedure. - Add pages under
apps/web/src/app/(dashboard)/<feature>/; each dedicated page callsawait requirePlugin('<id>')first. - Add tables and policies in
packages/schema/src/tables/(schema changes need the migration, row-level security,is_sampleand index review in the rootAGENTS.md). - Declare the page's report-surface manifest beside it and run
pnpm surfaces:generate. - Run the checks below, then deploy: the reconcile writes each organization's row, no backfill is needed.
Guards#
pnpm tsx scripts/audit/plugin-manifest-validity.ts(inaudit:all): ids, dependency graph acyclic, one owner per pillar, family rules.scripts/audit/plugin-page-guard.py(inaudit:all): every gated page calls the guard unless allow-listed with a reason.- Tests:
packages/plugin-host/src/manifest.test.ts,apps/web/src/__tests__/reconcile-plugins.test.ts(idempotent reconcile). - Gate:
pnpm run typecheck && pnpm run lint && pnpm run audit:all && pnpm --filter @yng/web build(a cached typecheck can pass on stale output).
Operating it#
- A super admin toggles the plugin at
/admin/orgs/<slug>/plugins; enabling never cascades todependsOnand a plugin is off while a dependency is off. - An installation also carries plan, validity and status: a row past
valid_toor notactiveortrialis off (installBlockReason,resolve.ts). - Never rename an
id: it is the persisted installation key. Add a new plugin and bumpversionfor changes. Legacy ids resolve through aliases in the gate. - Disabling never deletes what the plugin wrote; purging is a maintenance script.
Where it stops#
- Entitlement is enforced at the page and menu layers, not on shared routers: a caller could read a disabled plugin's API for the caller's own organization (an entitlement gap, not a tenant-isolation gap; row-level security still scopes rows). A dedicated router closes it.
- Per-plugin settings have no mechanism yet:
configwaits for its first consumer and a manifest-declared settings schema. registry.tsholds every family in one file; adding a connector there is a table row, adding a feature is a manifest block.- Third-party or runtime plugins are out of scope.