Skip to content

Documentation

Dashboard Widget Development

Hub for building, packaging, and publishing SveltyCMS dashboard widgets — self-contained marketplace-portable packages.

11/5/2026
5 min read Edit on GitHub

This section is how to build a dashboard card. How the grid loads and places cards is Dashboard system.

The admin Dashboard is a widget-based grid. Each widget is a self-contained package living in its own kebab-case folder under src/routes/(app)/dashboard/widgets/<folder>/. Packages are discovered at build time by Vite import.meta.glob — no manual registration, no runtime filesystem scans.

Core commerce packages (freemium, 14-day trial): Commerce Orders (commerce-orders) and Commerce Inventory (commerce-inventory). They read the optional ecommerce preset collections and stay empty on a non-store CMS. Catalog data can be imported with Smart Importer (WooCommerce / Shopify). Product map: E-Commerce Overview.

📚 Documentation Map

Guide Description
Architecture Folder structure, widget.json manifest, registry, and licensing.
Development Step-by-step guide to building your own dashboard widget.
Marketplace Publishing dashboard widgets to marketplace.sveltycms.com.

🗂️ Package Layout (1 folder = 1 widget)

Every dashboard widget must ship a co-located .mdx file that describes the widget — the marketplace uses it for the package listing card and detail page:

src/routes/(app)/dashboard/widgets/
  system-health/
    index.svelte    # Entry component (fixed name)
    widget.json     # Marketplace manifest (required)
    readme.mdx      # Marketplace description (REQUIRED, fixed name)
  logs/
    index.svelte
    widget.json
    readme.mdx
  commerce-orders/   # freemium, 14-day trial
    index.svelte
    widget.json
    readme.mdx
  • Folder — kebab-case package id (system-health, logs, last5-content).
  • Component — always index.svelte. The folder id is the registry key saved in user layouts, so renaming the implementation file never breaks saved dashboards.
  • widget.json — machine-readable metadata for the marketplace, the in-app catalog, and telemetry.
  • <component>.mdx — human-readable marketplace description: features, licensing, data source, and metadata. Required for every package.

🔍 How Discovery Works

Layer Mechanism
Client registry +page.svelte — optional widgets; picker from page data; Svelte chunk only when added / visible
Server widget picker +page.server.ts — widget.json via getInstalledDashboardWidgets() (no Svelte eval)
Saved layout Hydrated in load() from system.preferences; client skips /api/system-preferences on first paint
Manifest registry manifest-registry.ts — import.meta.glob("./*/widget.json")
Telemetry Reports installed package ids via the manifest registry
Marketplace catalog Local packages appear in GET /api/marketplace (offline-first merge)

Drop a new folder into widgets/, restart the dev server, and the widget appears in the picker — the same flow a marketplace install uses.


🛡️ Runtime contract (sandbox, storage, settings)

Every widget rendered by BaseWidget receives a per-tile scope (widget-scope.svelte) so packages never have to forward settings, tenant, or user props through their own signatures.

Concern Contract
Endpoint safety endpoint / sandbox.fetch only allow same-origin /api/... paths. Encoded traversal (%2E%2E, %2f, double-encoded %252e) is rejected before fetch runs. Network calls use sandboxedWidgetFetch (15s timeout, CSRF headers, sanitized headers).
Errors HTTP failures throw WidgetHttpError; 4xx responses are not retried. One crashing widget is isolated by <svelte:boundary> and offers Retry/Remove.
Storage Use sandbox.storage (or createWidgetStorage(id, tenantId, userId)). Keys are scoped to svelty_wgt:{tenant}:{user}:{widget}: and capped at 256 KB per widget instance with TTL expiry. The legacy flat widget_cache_* key is still read for migration, but new data is only written to the scoped key.
Settings The header gear opens widget-settings-modal (title, refresh rate, grid size). Saves send only { customLabel, pollInterval }; the page merges them into the persisted settings, so widget-specific settings such as collectionId survive. A persisted settings.pollInterval overrides the package default after reload.
RBAC widget.json may declare requiresPermission and/or requiresAdmin. The server filters the picker and existing layouts re-check at runtime (checkWidgetAccess) — an installed-but-forbidden widget renders an access-denied tile instead of calling its endpoint. dashboard:read and system:dashboard are aliases.
Global refresh dashboardEvents.triggerRefreshAll() fans out with 10–80 ms jitter and stays pending until every mounted widget reports completion (10s safety timeout).
Layout presets DASHBOARD_PRESETS (Overview, Monitoring, Editorial, Governance, Minimal) only include installed packages; replacing a non-empty dashboard asks for confirmation first.
Note

The widget sandbox is a client-side guardrail, not an authorization boundary. Every /api/dashboard/... route still enforces dashboard:read (or the system:dashboard alias), its license gate, and tenant scoping server-side. Treat requiresPermission/requiresAdmin as UI narrowing on top of that server check.


🧪 Testing Policy

  • Shell tests (tests/unit/routes/dashboard-page-server.test.ts) assert the registry shape, never a fixed widget list — the catalog is install-specific.
  • Runtime helpers (tests/unit/dashboard/dashboard-runtime.test.ts) cover picker mapping, CMS-range filtering, layout unwrap, and hidden-tab poll gating.
  • Widget defaults are unit-tested in tests/unit/dashboard/widget-defaults.test.ts.
  • Sandbox / storage / presets / contracts are covered by dashboard-sandbox.test.ts, dashboard-storage.test.ts, dashboard-presets.test.ts, and dashboard-contract.test.ts.
  • BaseWidget interactions (fetch, cache, settings, close, resize) run in tests/unit/components/dom/base-widget-interaction.test.ts — use bun run test:unit:components.
  • Per-widget tests live in the widget’s own folder (widgets/<folder>/tests/) — optional but encouraged for marketplace submissions.

Related

dashboardwidgetsdevelopmentmarketplace
Was this page helpful?