On this page
- 1How add-ons work
- 2Package structure
- 3Create your first add-on
- 4Modules
- 5Settings and secrets
- 6Data from the server
- 7Visitors, conditions and page access
- 8Layouts, admin pages and text checkers
- 9Your own routes, storage and MCP tools
- 10The kit
- 11On, off and uninstall
- 12Build add-ons with AI
- 13Rules and checklist
In short
- An add-on is an ordinary EmDash plugin built with @nuustudio/sdk. It imports only the SDK, never NuuStudio.
- NuuStudio picks up what it registers: modules, settings, data, display conditions, dynamic content, page access, layouts and admin pages.
- Start with npx @nuustudio/sdk create, or let your AI coding agent build it with the NuuStudio add-on skill.
1. How add-ons work
An add-on is an EmDash plugin that also registers builder parts with NuuStudio. The CMS does what it already does well: your plugin's routes, storage, permissions, hooks and MCP tools. NuuStudio picks up the builder parts. NuuStudio's own Members and Grammar are add-ons built this way.
An add-on can contribute any of these:
| You write | NuuStudio does |
|---|---|
modules | Insert panel (own category if you like), settings with the built-in controls and shared design groups, canvas preview and inline editing, site render, only-the-assets-used loading, the AI Builder's and MCP clients' module catalog |
settings | A form in Settings → Add-ons. Secrets are encrypted by the CMS and only a hint ever reaches the browser |
server.dataProviders | Run on your server before a page renders, and for builder previews, with your settings (secrets decrypted). 8-second timeout; a failure never breaks the page |
server.viewer | Who is visiting (for example a signed-in member), resolved once per request |
ruleTypes | Display conditions (Conditions → Visitor), answered on the server from the viewer |
dynamicSources | Dynamic Content entries from the viewer, with a sample in the builder |
pageAccess | Options in Page Settings → Who can see this page, with your sign-in module on the no-access page |
layouts | Starter layouts in the builder's Library |
adminPages | Links in NuuStudio's sidebar to your plugin's admin pages, drawn with NuuStudio's admin components |
client.textCheckers | Spelling, grammar and style underlines and the Proofread panel |
privateCookies | Pages requested with these cookies are never shared-cached |
Where the code runs. Your add-on registers twice: on the server (the plugin entry, which also brings data providers and the viewer) and in the admin (the admin entry, for the builder). The registry lives on globalThis, so the order things load in doesn't matter. A module's render() runs on the server for the site and in the builder for the canvas; its runtime runs in the visitor's browser.
The kit. Add-ons never import NuuStudio. NuuStudio lends its helpers at runtime instead (style groups, the form field builder, icons, responsive CSS, rule matching, site integrations, admin components), so add-on modules look and behave like built-in ones and keep working across NuuStudio updates.
2. Package structure
| File | What it is |
|---|---|
src/addon.ts | defineAddon({...}): modules, settings and everything else the builder needs. Shipped to the browser: no secrets, no CMS imports, no Node APIs. |
src/server.ts | Data providers and the viewer. Server only: secrets and network calls go here. |
src/index.ts | The EmDash plugin: emdashAddon(addon, { package, server, plugin }). Exports the descriptor factory for astro.config.mjs and createPlugin. |
src/admin.ts | The builder side (EmDash runs every plugin's admin entry): registerAddon(addon), plus your admin pages. |
package.json points main at the built server entry (dist/index.mjs, built with tsdown) and exports ./admin as src/admin.ts, which EmDash bundles into its admin. The add-on depends on @nuustudio/sdk and has emdash as a peer dependency.
3. Create your first add-on
The scaffolder writes a working add-on (a module, a settings form, a server data provider and both entries) that typechecks and builds as is:
npx @nuustudio/sdk create acme-countdown --label "Countdown" --package @acme/nuu-countdown
cd acme-countdown pnpm install pnpm build
Add it to your site next to NuuStudio, then restart:
// astro.config.mjs
import { nuuStudio } from "@nuustudio/emdash";
import { acmeCountdown } from "@acme/nuu-countdown";
emdash({ plugins: [nuuStudio(), acmeCountdown()] }) Open NuuStudio → Settings → Add-ons: your add-on is listed and On. Its module is in the builder's Insert panel. If it says Check install, only one side registered it: the plugin is missing from astro.config.mjs, or its admin entry didn't load.
4. Modules
A module is plain data plus a few functions. render() returns an HTML string and runs on the server and in the builder canvas, so it can't touch the DOM: escape every value with esc() and pass URLs through safeUrl(). NuuStudio wraps it in the module element and adds the shared design groups (spacing, background, border, shadow, animation, visibility…) on its own.
// src/addon.ts
import { addonData, defineAddon, esc } from "@nuustudio/sdk";
export default defineAddon({
id: "acme-countdown",
label: "Countdown",
modules: [{
name: "acme-countdown", // the id, or "<id>-something"
label: "Countdown",
icon: "clock",
category: "interactive",
description: "Counts down to a date",
defaults: { title: "Launch in", date: "" },
groups: [
{ id: "cd_content", label: "Content", tab: "content", open: true, fields: [
{ key: "title", label: "Title", type: "text" },
{ key: "date", label: "Ends", type: "date" },
] },
{ id: "cd_look", label: "Numbers", tab: "design", fields: [
{ key: "number_color", label: "Number color", type: "color", hover: true },
] },
],
// NuuStudio's own Heading Text group, styling this element
design: { heading: " .cd-title" },
inlineEdit: [{ key: "title", selector: ".cd-title" }],
render: (s, ctx) =>
`<h3 class="cd-title">${esc(s.title)}</h3><div class="cd" data-to="${esc(s.date)}"></div>`,
css: (s, sel, out) => {
if (s.number_color) out.add(`${sel} .cd`, { color: s.number_color });
},
baseCss: ".cd{font:600 2rem/1 system-ui;font-variant-numeric:tabular-nums}",
// A function body, run per instance with el and Dash. ES2018, no imports.
runtime: `
var box = el.querySelector(".cd"), to = Date.parse(box.getAttribute("data-to"));
var first = el.firstElementChild;
function tick() {
if (Dash.alive && !Dash.alive(el, first)) return clearInterval(t);
var s = Math.max(0, Math.floor((to - Date.now()) / 1000));
box.textContent = Math.floor(s / 86400) + "d " + Math.floor(s % 86400 / 3600) + "h " + Math.floor(s % 3600 / 60) + "m";
}
var t = setInterval(tick, 1000); tick();`,
ai: { hint: "Use for launches and sale deadlines. Set title and date." },
}],
});- Names. The add-on id (lowercase, hyphens) is also the EmDash plugin id. Module names are the id or start with
<id>-. Built-in modules never have a hyphen, so nothing clashes. - Fields: text, textarea, richtext, code, url, number, range, select, buttons, toggle, color, image, gallery, video, icon, font, align, spacing, corners, date and repeater.
responsiveadds tablet and phone values,hovera hover value,showhides a field until it applies. - Design targets.
design: { heading, text, button }gives your elements NuuStudio's own typography and button groups. - Runtime. A function body string run once per instance with
elandDash, in ES2018. Stop timers whenDash.alive(el, first)turns false: the builder re-rendered the module. - Categories. Use a built-in one, or your own id with a
categoryLabel(Members uses “Members & Checkout”). - AI.
ai.hinttells NuuStudio's AI Builder and MCP clients when and how to use the module. Your module's fields are in the module catalog automatically.
To use NuuStudio's style groups, form fields or icons, make modules a function of the kit:
// Build modules with NuuStudio's kit (field groups, form fields, icons)
modules: (kit) => [{
name: "acme-countdown",
// …
groups: [
{ id: "cd_content", label: "Content", tab: "content", fields: [/* … */] },
kit.fields.textGroup("number_text", "Numbers", "number"),
kit.fields.buttonGroup("button"),
],
design: { number: " .cd", button: " .cd-button" },
render: (s, ctx) => `${kit.html.icon("clock")}<div class="cd"></div>`,
}],5. Settings and secrets
Declare fields and NuuStudio draws the form in Settings → Add-ons. They're saved as your plugin's EmDash settings, so EmDash's own plugin settings page shows them too.
settings: {
description: "Where the dates come from",
fields: [
{ key: "feedUrl", label: "Feed URL", type: "url" },
{ key: "apiKey", label: "API key", type: "secret", description: "Stored encrypted" },
{ key: "timezone", label: "Time zone", type: "select", options: [{ value: "local", label: "Visitor's" }, { value: "utc", label: "UTC" }] },
],
},secret values are encrypted at rest and never sent back to the browser: the form only shows that one is saved and its last four characters. Read them on the server: data providers and the viewer get them decrypted in ctx.settings, your routes through ctx.settings.get().
6. Data from the server
A module asks for data with data(); a provider in src/server.ts answers on your server before the page renders, and again for live previews in the builder. The result reaches render() through addonData(ctx).
// src/addon.ts (the module asks for data)
data: (s) => ({ provider: "upcoming", args: { limit: Number(s.limit) || 3 } }),
render: (s, ctx) => {
const events = addonData<{ title: string }[]>(ctx); // undefined while loading
return events ? events.map((e) => `<p>${esc(e.title)}</p>`).join("") : "";
},
// src/server.ts (answers on the server)
import type { NuuAddonServer } from "@nuustudio/sdk";
const server: NuuAddonServer = {
dataProviders: {
upcoming: async (args, { settings, editor, entry }) => {
const res = await fetch(String(settings.feedUrl), {
headers: { authorization: `Bearer ${settings.apiKey}` }, // decrypted here only
signal: AbortSignal.timeout(5000),
});
return (await res.json()).slice(0, Number(args.limit));
},
},
};
export default server;Providers time out after 8 seconds. A failing provider leaves addonData(ctx) empty and is logged; it never breaks the page.
7. Visitors, conditions and page access
A viewer tells NuuStudio who is visiting. It runs once per request on the server. Your rule types (display conditions), dynamic sources and page access options are answered from it, and modules can read it with addonViewer(ctx, id). Pages that use them are sent private, no-cache.
// src/server.ts: who is visiting (never return secrets)
viewer: async ({ request }) => {
const token = /(?:^|;\s*)acme_session=([^;]+)/.exec(request.headers.get("cookie") ?? "")?.[1];
return token ? await lookUpCustomer(token) : null; // e.g. { tier: "gold", name: "Alex" }
},
// src/addon.ts
ruleTypes: [{
id: "acme-loyalty-tier", label: "Loyalty tier", icon: "award", section: "Visitor",
operators: ["any", "none"], value: "text", placeholder: "gold, silver",
evaluate: (rule, viewer) => getKit()?.rules.text(rule.operator, [viewer?.tier ?? null], rule.values) ?? null,
}],
dynamicSources: [{
id: "acme-loyalty-name", label: "Customer name", group: "Customer", kinds: ["text", "html"],
resolve: (viewer) => viewer?.name ?? "",
sample: "Alex Morgan",
}],
pageAccess: {
options: [{ value: "gold", label: "Gold customers" }],
check: (value, _arg, viewer) => viewer?.tier === value,
},
privateCookies: ["acme_session"], Page access options are stored as <id>:<value>[:<argument>]. Visitors who don't qualify get the Theme Builder's No access page, or a built-in page with your noAccess() sign-in module and join link. If the add-on is removed, the page stays closed rather than opening up.
8. Layouts, admin pages and text checkers
Starter layouts appear in the builder's Library next to the premade ones (Members ships a “Checkout page”):
layouts: [{
id: "acme-countdown-launch",
name: "Launch page",
category: "Countdown",
description: "A hero with a countdown",
build: (id) => ({
version: 1,
sections: [{ id: id(), type: "section", settings: {}, rows: [
{ id: id(), type: "row", layout: "4_4", settings: {}, columns: [
{ id: id(), type: "column", settings: {}, modules: [
{ id: id(), type: "module", name: "acme-countdown", settings: { title: "We launch in" } },
] },
] },
] }],
}),
}],Admin pages are your plugin's EmDash admin pages, drawn with NuuStudio's admin components from the kit and linked from NuuStudio's sidebar:
// src/admin.ts
import { getKit, registerAddon } from "@nuustudio/sdk";
import * as React from "react";
import addon from "./addon";
registerAddon(addon);
function Dashboard() {
const ui = getKit()!.ui!;
const h = React.createElement;
return h(ui.Page as any, null,
h(ui.AdminShell as any, { title: "Countdown" },
h(ui.Group as any, { icon: "clock", title: "Upcoming launches" }, "…")));
}
export const pages = { "/countdown": Dashboard };
// src/addon.ts: listed in NuuStudio's sidebar
adminPages: [{ path: "/countdown", label: "Countdown", icon: "clock" }],
// src/index.ts: an EmDash admin page of your plugin
plugin: { admin: { pages: [{ path: "/countdown", label: "Countdown", icon: "clock", group: "NuuStudio" }] } },Text checkers add underlines and Proofread panel findings (Grammar is one):
// src/admin.ts: a text checker for the Proofread panel
registerAddon(addon, { client: { textCheckers: [{
id: "acme-style",
label: "Acme house style",
check: async (text, { lang }) =>
text.includes("e-mail")
? [{ offset: text.indexOf("e-mail"), length: 6, message: 'Write "email"', kind: "style", replacements: ["email"], ruleId: "acme:email" }]
: [],
}] } });9. Your own routes, storage and MCP tools
Everything else is plain EmDash: pass it in plugin, exactly as you would to definePlugin(). Routes answer at /_emdash/api/plugins/<id>/<route>.
// src/index.ts
import { emdashAddon } from "@nuustudio/sdk/emdash";
import addon from "./addon";
import server from "./server";
const plugin = emdashAddon(addon, {
package: "@acme/nuu-countdown",
server,
plugin: {
storage: { launches: { indexes: ["date"] } },
routes: {
"launches/next": {
public: true,
handler: async (ctx) => (await ctx.storage.launches.query({ limit: 1 })).items[0] ?? null,
},
},
hooks: { "plugin:uninstall": async ({ deleteData }, ctx) => { /* clean up elsewhere */ } },
},
});
export const acmeCountdown = (options = {}) => plugin.descriptor(options);
export const createPlugin = plugin.createPlugin;
export default createPlugin;Call your routes from a module's runtime with Dash.addon(), never a hard-coded path:
// in a module's runtime
Dash.addon("acme-countdown").post("launches/next", {}).then(function (r) {
if (r.ok) el.querySelector(".cd").setAttribute("data-to", r.body.data.date);
});10. The kit
Inside modules: (kit) => … the kit is the argument; elsewhere getKit() returns it once NuuStudio has loaded.
| Member | What |
|---|---|
fields.textGroup(id, label, prefix, extra?, { headingLevel? }) | A text style group (font, size, color, alignment…) for keys starting with prefix. Target it with design[prefix]. |
fields.buttonGroup(prefix?, label?) | The full button style group. |
forms.builderFields() | The Contact Form's field builder (types, widths, masks, validation, conditions) as repeater item fields. |
forms.fieldHtml(field, index, nodeId, showLabels, marks?) | One built form field as HTML; forms.engineJs is the form engine to put first in your runtime. |
html.icon(name, className?), html.part(ctx, id, index?) | An icon from the builder's set as inline SVG; click-to-edit marks for parts of a module. |
css.prop(settings, key, cssProp, out, { sel, hoverSel? }, transform?) | A setting as a CSS property, with its tablet, phone and hover values. css.color(value, ctx) resolves global colors. |
rules.text(operator, actual, values) | Answer a text rule exactly like built-in conditions (is, contains, matches…). |
server.deliver({ event, … , targets }) | Send an event to the site's integrations (webhook, Mailchimp, Kit…). server.settings(id) and server.storage(id, collection, indexes) for code outside your routes. |
ui.Page, ui.AdminShell, ui.Group, ui.Field, ui.Toggle, ui.Modal, ui.useToast… | NuuStudio's admin frame and controls for your admin pages (browser only). |
11. On, off and uninstall
- On / off is the plugin's EmDash state, switched in Settings → Add-ons or EmDash's Plugins screen. When it's off, NuuStudio ignores everything the add-on registers and its routes answer 404. Its elements stay on pages with their settings (the site leaves them out, the builder marks them) and come back when it's switched on. Don't add your own on/off setting.
- Uninstall (Settings → Add-ons) can delete the add-on's data: the storage collections you declared, its settings and its key-value data, after your
plugin:uninstallhook. Then it turns the plugin off and shows the steps to remove it from the site's code. - Install is a code change: the package, its line in
astro.config.mjs, a restart or redeploy. Add-ons run inside page rendering, so they ship with the site rather than being installed at runtime.
12. Build add-ons with AI
The NuuStudio add-on skill teaches AI coding agents (Claude Code and other agents that read Agent Skills) the whole contract, the workflow (scaffold, build, verify) and the common pitfalls. Add it to your project:
mkdir -p .claude/skills/nuustudio-addon curl -o .claude/skills/nuustudio-addon/SKILL.md https://nuu.studio/skills/nuustudio-addon/SKILL.md curl -o .claude/skills/nuustudio-addon/REFERENCE.md https://nuu.studio/skills/nuustudio-addon/REFERENCE.md
It also ships with the SDK:
cp -R node_modules/@nuustudio/sdk/skill/nuustudio-addon .claude/skills/
Then ask your agent things like:
- “Make a NuuStudio add-on with a pricing calculator module. The rates come from a settings field, and the total updates as visitors move the sliders.”
- “Add a “Loyalty tier” display condition and a “Customer name” dynamic source to our add-on, reading the customer from our acme_session cookie.”
- “Our add-on's module doesn't show up in the Insert panel. Find out why and fix it.”
Read the skill: SKILL.md and REFERENCE.md. AI assistants without skills can read llms-full.txt, which summarizes the same rules. Your site's MCP server stays for using NuuStudio (building pages); add-ons are code, so agents build them in your project.
13. Rules and checklist
- Ids: module, rule type, dynamic source and layout ids are your add-on id or start with
<id>-. - Nothing secret in
src/addon.ts: it ships to the browser. Secrets, network calls and Node APIs go insrc/server.tsor your routes. - Escape everything
render()outputs, and never return secrets from a viewer: it can reach the page. - Runtime: ES2018, no imports, your routes through
Dash.addon(). - API version:
defineAddonsetsapiVersion: 1; NuuStudio refuses add-ons for a version it doesn't speak.
Before you ship:
pnpm typecheckandpnpm buildpass.- Settings → Add-ons lists it as On (not “Check install”).
- The module is in the Insert panel, renders on the canvas, and its settings work.
- A published page renders it on the live site, with the provider's data.
- Switched off, its routes answer 404 and its modules leave the page; switched back on, everything returns.
- No errors in the browser console or the server log.
Questions? Email hello@nuulab.com. Nuulab Systems LLC, Texas, USA.