All concepts
18 — Concept

App domains

A second process goes into the app you already have, as a domain beside its plugins: the same slots and namespaces, one line per list, and one boundary check over both.

One app, many domains

A business that runs one process on the kit soon wants a second: expenses after purchase orders, leave requests after timesheets. From kit 0.47.0 the second process goes into the app it already has, as another domain, not into a new copy. The people, the organisations, the roles, sign-in, the knowledge base, the agents and the audit trail are already there, and an agent can work across both processes in one run, because both sets of tools belong to the same person.

The rule for where code goes is one sentence. A domain holds this app's own concepts and logic: its orders, its leave requests, the rules for approving them. A plugin is a reusable capability that works across domains and across apps: single sign-on, analytics, a CMS, a connector to an outside system.

A unit is a plugin or a domain

Both are units. Each has an id that doubles as its namespace, the same slots (routes, tables, jobs, events, tools, agents, prompts, pages, permissions) and the same naming rules, and every registry in the app reads them through one list: the installed plugins first, then the domains. The difference is how they arrive.

DomainPlugin
Holdsthis app's own processa capability other apps want too
Livesin place, under apps/web/src/<id>/in its own git repository, copied in
Wired byone line in each of the app's own lists, written by handpnpm plugin add, which writes the barrel lines
Manifestnoneplugin.json, with its requirements
Kit upgradesnever touch itnever touch it; it has its own releases

A domain is declared with defineDomain and listed in src/app.ts and its four twins, one each for the pages, the tables, the shared contracts and the command line. Those lists belong to the app: a kit upgrade creates them empty in a copy that has none and never writes to them again.

Why not a plugin for everything. A plugin carries a manifest, a repository and an install step, which is the right price for something several apps share. For a process only this app has, that is ceremony with nothing to show for it. A domain keeps the same boundaries and drops the packaging.

How two domains talk to each other

Each kind of coupling has one rule. When something happened, one domain emits an event and the other handles it, with no import between them. When one domain needs a synchronous read or command from another, it calls that domain's public.ts, which takes the caller's context so the owner's rules apply, and only when its dependsOn names the other domain. From kit 0.48.0 dependsOn may name an installed plugin too, so a domain that reads from one says so, and each function in public.ts is wrapped in definePublic, which refuses the call while the owner is switched off for that organisation. When an agent needs both, it is one run: its tools already hold every unit's tools for the person who started it.

The kit ships two example domains in a fresh copy. example-hr holds leave requests and an approval event. example-sales holds leads, refuses to assign one while its owner is on leave by asking example-hr, releases leads when leave is approved, and has an agent that uses both domains' tools. They exist to be read and deleted, and an upgraded copy never receives them.

One boundary check over every unit

A test and pnpm plugin check run the same boundary check over plugins and domains together. It fails a domain that reaches into another domain's internals, or into one its dependsOn does not list; a cycle between domains; a plugin that imports a domain; a table outside its unit's namespace; and two units that claim the same table, job type, event or route. pnpm plugin add runs the id and table half before it copies anything, so a plugin cannot land on top of a domain's names.

It also fails a domain's public function that is not wrapped in definePublic, and a domain's schedule that fires more than once an hour or loops over organisations by hand instead of using perTenantTask, which the kit runs once per organisation and skips where the domain is off. It warns when a domain imports a plugin its dependsOn does not list. A plugin gets the same three as warnings for now, so nothing already published breaks.

A domain cannot add sign-in methods, single sign-on policies, public sites or a new /api prefix: identity and public hosts stay plugin capabilities.

Roles inside a domain

By default a domain's permissions are the organisation's roles. From kit 0.48.0 an admin can also give a group a role inside one domain or plugin: member or admin. A grant raises the group's members for that unit's own subjects and nothing else. The finance team can run expenses without becoming organisation admins, and no grant ever reaches members, billing or another unit. In code, ctx.isUnitAdmin answers for the unit and ctx.isAdmin still answers for the organisation, so each check says which it means.

Every agent run and chat thread records the unit that owns it, so a domain's admins see that domain's runs, approve its agents' requests and get its notifications, beside the organisation's admins. With no grants, everyone sees exactly what they saw before.

Who can open it, and turning it off

Each unit has an access mode per organisation. tenant, the default, opens it to everyone in the organisation. groups opens it only to the groups that hold a grant in it, and to the organisation's admins. A unit someone cannot open is gone for them: its pages, nav, cards and settings tabs are hidden, its routes answer 404, and chat, agents and MCP get none of its tools or knowledge. A domain can declare groups as its default in code.

The kill switch turns a unit off for one organisation, admins included. The kit enforces it, not each author: queued runs are cancelled at their next step, its jobs and event handlers are skipped, and its public functions, scheduled tasks and public routes refuse. That is what definePublic and perTenantTask are for.

Budgets per domain

Spend and concurrency are checked as a chain: the run, then its agent, then its domain, then the organisation. A domain declares a daily cost ceiling and a cap on active runs in code, an agent can do the same, and an organisation's admin may lower either but never raise it above what the code says. Every metered AI call records its unit, so a domain's spend today is one number. The kit's own chat gets daily caps per organisation and per person. Leave them unset and nothing is capped that was not before.

One screen for all of it

Settings → Domains opens on a diagram of how every domain and plugin reads from the others, drawn from their dependsOn, with any unit that is switched off dimmed. Each unit then has its own view: the groups granted a role in it, its access mode, its on/off switch, its budget override, and what it depends on and what depends on it. Turning off a plugin that a domain reads from asks first and names the domain. With nothing set, the screen says everyone keeps their organisation role.

Every unit's agents and tools, in one inventory

From kit 0.49.0, Settings → Domains → Agents and tools lists every unit, core first: its tools and what each may do (write, send data out, read content into a model, need approval), its agents and the autonomy tier of the tools they are given, its scheduled tasks and events, the functions it publishes to other units and which units call them, and what it depends on in both directions. From there an admin can lower the autonomy tier of an agent or a whole unit for the organisation. From kit 0.51.0 each tool that sends data out also shows how it answers the trifecta: the URLs its source rule allows, or the reason recorded for accepting where its data goes. The same list is an admin API and rocketflare agents inventory. Turning a unit off now also covers sign-in: an identity plugin that is off for an organisation signs nobody in there and holds no single sign-on requirement over it, so its people, admins included, can still sign in with the kit's own methods.

An app-owned plugin stays a plugin

A copy made before domains existed may hold its own processes as plugins in its own tree. They keep working, and each is already a unit. Moving one into a domain is the owner's choice, and the kit's concepts document has the recipe: copy the trees out, remove the plugin, declare the domain and list it. It keeps the id and every table name, so there is no migration and no data to move.