Skip to content
MSO CloudDocumentation

Add an optional feature (plugin)

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: pluginManifestSchema in packages/plugin-host/src/manifest.ts, strict, parsed at module load; cross-field rules reject a field on the wrong kind. Every field is in Plugin development.
  • Catalog: PLUGIN_REGISTRY in packages/plugin-host/src/registry.ts (features, connectors, satellite in one file).
  • Gate: isPluginEnabledForOrg, getEnabledPluginIdsForOrg, getDisabledNavItemsForOrg in packages/plugin-host/src/gate.ts; pure decision resolveEnabled in resolve.ts.
  • Ledger: table org_plugin_installations (enabled, is_active, status, valid_to; config is 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#

  1. Print the snippets: pnpm tsx scripts/scaffold-plugin.ts <id> <category> [navItemId ...] (writes nothing; features only).
  2. Paste the manifest into MANIFESTS in packages/plugin-host/src/registry.ts. List it in the blueprints that want it instead of using defaultEnabled: true without a home domain.
  3. Add plugins.<camelId>.name and .description to packages/i18n/src/messages/vi.ts and en.ts.
  4. Check each navItemId exists in ORG_MENU_ITEMS (apps/web/src/lib/rbac.ts); add it to MENU_ITEM_LABEL_KEYS to make it renamable.
  5. Add the router in apps/web/src/server/routers/<feature>.ts on a dedicated procedure when no core page reads it (as chatProcedure does); otherwise keep orgProcedure.
  6. Add pages under apps/web/src/app/(dashboard)/<feature>/; each dedicated page calls await requirePlugin('<id>') first.
  7. Add tables and policies in packages/schema/src/tables/ (schema changes need the migration, row-level security, is_sample and index review in the root AGENTS.md).
  8. Declare the page's report-surface manifest beside it and run pnpm surfaces:generate.
  9. 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 (in audit:all): ids, dependency graph acyclic, one owner per pillar, family rules.
  • scripts/audit/plugin-page-guard.py (in audit: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 to dependsOn and a plugin is off while a dependency is off.
  • An installation also carries plan, validity and status: a row past valid_to or not active or trial is off (installBlockReason, resolve.ts).
  • Never rename an id: it is the persisted installation key. Add a new plugin and bump version for 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: config waits for its first consumer and a manifest-declared settings schema.
  • registry.ts holds 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.