Skip to content
Spools
Documentation
On this page

Layouts

The CRM's own pages suit most of the work: a list, a board, a record with its fields and its timeline. A layout is for the rest: a page that follows how your business works instead of how a CRM is usually drawn. You write it in crm.config.json, under ui, and Spools draws it with its own kit of components.

  • A page of your own at /pages/<key>, in the sidebar: "Today", "Pipeline", "Jobs to order".
  • An object's record page, laid out as that record's story, for everyone or for some roles.

The classic pages stay. A Spool with no ui is exactly as it was, and a record page that has a layout still offers the classic one a click away.

Layouts are written in OpenUI Lang, a small language for describing an interface that both people and coding agents write well. Spools uses the open-source language and renderer, with a kit, tools and checks of its own. Nothing is generated while someone uses the CRM: a layout is text in your config, reviewed and committed like the rest.

A first page#

json
"ui": {  "pages": {    "pipeline": {      "label": "Pipeline",      "icon": "handshake",      "layout": [        "root = Page([stats, Row([Input(\"q\", \"Search deals\", \"search\", $q), NewRecord(\"deals\")], \"between\"), list], \"wide\")",        "$q = \"\"",        "deals = Query(\"records\", {object: \"deals\", q: $q, sort: {field: \"closeDate\", dir: \"asc\"}}, {rows: [], total: 0})",        "won = Query(\"records\", {object: \"deals\", where: {stage: \"won\"}, limit: 1}, {rows: [], total: 0})",        "stats = Row([Stat(\"Deals\", deals.total), Stat(\"Won\", won.total)])",        "list = Card([Records(\"deals\", deals.rows, [\"value\", \"stage\", \"closeDate\"], \"No deals match.\")], \"Deals\")"      ]    }  }}

Add the page's route file once, whatever number of pages you write:

tsx
// src/routes/_crm/pages.$page.tsximport { createFileRoute } from '@tanstack/react-router'import { customPage } from '@swirls/spools/pages/custom'export const Route = createFileRoute('/_crm/pages/$page')(customPage)

Run bun run crm:gen, and "Pipeline" is in the sidebar. crm:gen says when the route file is missing and when a layout will not draw as written.

Key Required Description
label yes What the sidebar and the browser tab call the page.
layout yes The layout, as one string or as its lines. Lines keep the config readable: one statement a line.
icon no An icon name, as an object's icon.
nav no false leaves the page out of the sidebar, to be reached by a link.
roles no The roles whose sidebar lists it. Without it, everyone's. The page still opens for anyone with its address.

The sidebar's order#

ui.nav puts the links above the records in the order you want, and leaves out the ones you don't use:

json
"ui": {  "nav": {    "order": ["home", "pages.today", "entry.approvals", "tasks"],    "hide": ["workflows"]  }}
Key Description
order These first, in this order. Every other link follows in its usual place, so you name only what you move.
hide Left out of the sidebar. Presentation only: the page still opens for anyone with its address.

A link is named by:

  • one of the CRM's own pages: home, tasks, notes, files, reports, workflows, marketing, integrations, team;
  • pages.<key> for a page of your own (ui.pages);
  • entry.<key> for a link a module or your app adds, by the key of its sidebar entry.

A link someone isn't shown anyway (Team for someone who isn't an admin, a page for a role they don't hold) is skipped. A page that isn't in ui.pages, a name that is none of these and a link named twice are refused when the config is checked. ui.nav works without any layout.

pages is then a reserved address: an object can't have the key pages in a Spool that has pages of its own.

A record page#

json
"ui": {  "records": {    "deals": {      "roles": ["sales"],      "layout": [        "root = Page([header, Stages(deal.record, \"stage\"), Columns([main, side], \"2:1\")], \"wide\")",        "deal = Query(\"record\", {object: $object, id: $id}, {record: {}, activities: [], tasks: [], notes: [], related: {}})",        "header = RecordHeader(deal.record, [\"value\", \"owner\"])",        "main = Stack([Card([Fields(deal.record, [\"title\", \"value\", \"closeDate\", \"company\"], 2)], \"Deal\"), Card([Timeline(deal.activities, 8)], \"What has happened\")])",        "side = Stack([RecordActions(deal.record), Card([Tasks(deal.tasks, deal.record)], \"To do\"), Card([Notes(deal.notes, deal.record)], \"Notes\")])"      ]    }  }}

ui.records.<object> replaces that object's record page. With roles, only people holding one of them get it, and everyone else keeps the classic page. No route file is needed: the record page you already have draws it.

A "Classic view" link on the layout opens the page as it always was (?view=classic), and a "Custom view" link there leads back. Nothing is lost by laying a page out: every field, tab and panel is still on the classic page.

The language in a minute#

A layout is statements, one a line: name = Expression. root is the page.

text
root = Page([title, list])title = Heading("Jobs to order")jobs = Query("records", {object: "projects", where: {stage: "ordering"}}, {rows: [], total: 0})list = Records("projects", jobs.rows, ["client", "value"])
  • Arguments go by position, not by name: Stat("Won", won.total). Optional ones are left off the end.
  • Query(tool, arguments, defaults) reads the CRM. The page draws at once with the defaults and fills in when the answer comes. It reads again whenever a $variable in its arguments changes.
  • Mutation(tool, arguments) changes something when a button runs it: Button("Mark won", Action([@Run(win), @Refresh(), @Alert("Marked won", "success")])). The steps run in order and stop at a Mutation that fails, so the alert is raised only when it worked.
  • $variables hold what someone typed or chose: $q = "", then Input("q", "Search", "search", $q).
  • @ functions work on what a Query gave: @Count, @Sum, @Avg, @Min, @Max, @Round, @Filter, @Sort, @First, @Last, @Each, and Spools' own @Money and @Day.
  • Conditions: won.total > 0 ? list : Empty("Nothing won yet").

A statement nothing refers to is not drawn. bunx spools ui prompt prints the whole language, with this Spool's objects and fields: see Writing layouts with an agent.

What a layout knows#

Variable Where What it is
$me everywhere The id of whoever is signed in.
$today everywhere Today, as 2026-12-03.
$object record pages The object's key: "deals".
$id record pages The record's id, for Query("record", {..., id: $id}).

Tools#

What Query and Mutation name. Each one calls the server function the CRM's own pages use for the same thing.

Tool For Takes Gives
record Query object, id record, activities, tasks, notes, and related: the records of other objects that point at it, by "<object>.<field>".
records Query object, where?, q?, sort?, limit? rows and total, how many match in all.
summary Query object, by?, sum?, where?, top?, fields? groups, and count, sum and weighted over every record that matches.
me Query nothing id, name, email, roles.
update_record Mutation object, id, values id.
create_record Mutation object, values id.
run_action Mutation object, id, action message. Runs one of the object's actions.
create_task Mutation title, dueDate?, object?, id? id. The task is for whoever is signed in.
add_note Mutation object, id, body, title? id.

records in full:

  • where keeps the records whose fields equal the values given. A list means any of them, "@me" is whoever is signed in, and a relation is matched by id: {stage: ["won", "ordering"], owner: "@me", client: $id}. A field the object hasn't is refused. For more than equality, a field takes {op, value}: one of the questions the list page's filters ask, by the kind of field. {closeDate: {op: "inNext", value: 30}}, {amount: {op: "gte", value: 10000}}, {status: {op: "notIn", value: ["received"]}}, {dueDate: {op: "before", value: $today}}, {client: {op: "empty"}}. A question a field can't be asked is refused too.
  • q searches the object's searchable fields, as the list page's search box does.
  • sort is {field, dir}, dir being "asc" or "desc".
  • limit is 50 unless you say, and 200 at most. total counts every match, so a Stat needs no more than limit: 1.

summary in full. records is a page of an object's records; summary is all of them, counted:

  • by is the field whose values are the groups: a select, user, relation, boolean or text field. Each group has value, label (the option's label, the teammate's name, the related record's title), color, count, sum and rows. A select's groups are its options in the config's order, the empty ones too, so a pipeline keeps its shape; when where names values of that field, only those. Any other field's groups are the values found, largest first. Records that hold nothing are a last group, "None". Without by there are no groups, only the totals.
  • sum is a number or currency field to add up, for each group and over all of them. When the select's options have a probability, each group also has weighted, its sum by that chance, and the summary their total.
  • where is records' own. {owner: "@me"} keeps a summary to whoever is signed in.
  • top brings each group's largest few records with it (largest sum first, 10 at most, none unless you ask), with their title and the fields you name (6 at most), for a Funnel to open.
  • capped is true when more than 10,000 records matched: the numbers are then of the newest 10,000, and the page should say so.
text
open  = Query("summary", {object: "deals", by: "stage", sum: "amount", where: {stage: ["proposal", "negotiation"], owner: "@me"}, top: 5, fields: ["closeDate"]}, {groups: [], count: 0, sum: 0, weighted: 0})tiles = Row([Stat("Open deals", open.count, @Money(open.sum), "number", "/deals"), Stat("Weighted", open.weighted, "", "currency")])bars  = Funnel(open.groups, "deals", "currency", ["closeDate"])

It reads through the same list the records tool does, a page at a time with only the fields it counts by, so it counts what its reader may see and nothing else.

A record carries its relations as the related record (deal.record.company.name) and as <field>Id. A relation's records come the other way through related: job.related["payments.project"] is the payments whose project is this job. related holds up to 25 of each; for all of them, or to sort and count them, ask with records: Query("records", {object: "payments", where: {project: $id}}, {rows: [], total: 0}).

The kit#

Thirty-five components, Spools' own. They use the CRM's colours and controls, so a layout looks like the rest of the CRM and follows your theme.

Layout#

Component What it draws
Page(children, width?, title?, subtitle?) The root. width is narrow (a form), content (the default), wide or full.
Stack(children, gap?) Children one under another. gap is sm, md or lg.
Row(children, align?) Children side by side, wrapping. align is start, center, end or between.
Columns(children, widths?) Columns that stack on a narrow screen. "2:1" makes the first twice the second.
Card(children, title?, action?) A bordered panel, with an optional heading and a control beside it.
Section(title, children, open?, count?) A titled group that folds away.
Tabs(tabs) and Tab(label, children, count?) Tabs, one shown at a time.
Divider() A thin line.

Text and numbers#

Component What it draws
Heading(text, level?) A heading, level 1 to 3.
Text(text, tone?) Plain text. tone is default, muted, danger or success.
Badge(text, color?) A pill, in one of the colours select options use.
Stat(label, value?, hint?, format?, to?) One number with its label. format is number, currency or percent; to makes the tile a link to a page of the CRM.
Stats(groups, show?, format?) A tile for each group of a summary: its label and count, with its sum under it. show "sum" puts the sum first.
Funnel(groups, object, format?, fields?, hideEmpty?, empty?) A summary as bars, one for each group in order, with its sum and count. A group that came with rows opens to list them, each a link to its record.
Empty(text) A quiet line for when there is nothing to show.

Records#

Component What it draws
RecordHeader(record, fields?) The record's title, with the few fields that sum it up.
RecordActions(record) Write an email, log a call or meeting, add a note or task, and the object's own actions.
Field(record, field, label?) One field with its label, edited in place: the same control as the classic page.
Fields(record, fields, columns?) Several fields, each edited in place, in one or two columns.
Value(record, field) A field as it is shown, without its label and not editable.
Stages(record, field) The record's place in a select field's options, as steps in order. Choosing a step moves it.
Steps(steps, records, stops?) One line of steps that a record and the records it leads to move along. Read only.
Records(object, rows, fields?, empty?) A list of records, each a link to its page, with a few fields as columns.
RecordLink(record, label?) A link to a record's page.
Timeline(activities, limit?, empty?) Activities, newest first.
Tasks(tasks, record?) Tasks, open ones first, ticked off in place. With record, one can be added for it.
Notes(notes, record?) Notes as cards. With record, one can be added and each opened.
Files(record) The record's files.
Panels(record) The panels modules put on this object's record pages.

Field, Fields, Stages, Tasks and Notes save what someone changes themselves, and the page reads its data again. They show nothing to edit to someone who may not change the record.

Stages is one record's place in one field's options. Steps is for a story that crosses objects: a deal, then the job it became. Each step is {label, on}, and on names the values that put a record on it by "<object>.<field>". Give records in the order the story goes: the last one that is on a step says where things stand, and one that is missing or still loading is passed over. stops are values that end the line early, with what to say. Reaching the last step marks every step done.

text
deal = Query("record", {object: "deals", id: $id}, {record: {}})line = Steps([{label: "Lead", on: {"deals.stage": ["new", "contacted"]}}, {label: "Proposal", on: {"deals.stage": ["proposal"]}}, {label: "Contract", on: {"deals.stage": ["won"], "projects.stage": ["signed"]}}, {label: "Install", on: {"projects.stage": ["installing"]}}, {label: "Paid", on: {"projects.stage": ["complete"]}}], [deal.record, deal.record.project], {"deals.stage": {lost: "This deal was lost."}, "projects.stage": {cancelled: "This job was cancelled."}})

On the job's page the deal comes the other way: [job.related["deals.project"], job.record].

Controls#

Component What it draws
Button(label, action?, variant?, confirm?) Runs an action. variant is default, primary or danger; confirm asks first.
Link(label, to) A link to a page of the CRM ("/deals", "/pages/today") or a web address.
NewRecord(object, label?, preset?) Opens the object's new-record form. preset fills fields in.
Input(name, placeholder?, type?, value?) A text box bound to a $variable. type is text, number, date or search.
Choice(name, options, value?) A dropdown bound to a $variable. Each option is a value, or {value, label}.

Actions and functions#

Name What it does
@Run(ref) Runs a Mutation, or reads a Query again.
@Set($v, x) Sets a $variable. @Reset($v) puts it back.
@Navigate(to) Goes to a page of the CRM by its path: "/deals/<id>", "/pages/today".
@Refresh() Reads every Query on the page again.
@Alert(text, tone?) Raises an alert over the page. tone is info, success, warning or danger.
@OpenUrl(url) Opens a web address in a new tab, or a CRM path in this one.
@Money(n) An amount as money: @Money(12400) is "$12,400".
@Day(date) A date as people read one: @Day("2026-12-03") is "Dec 3, 2026".

A link or a navigation goes to a path of the CRM or to an http, https, mailto or tel address, and nowhere else. @ToAssistant, which the language also has, does nothing in a layout.

Your own components#

When the kit hasn't what a page needs, add a component of your own in src/spool.ui.ts(x):

tsx
import { z } from 'zod'import { defineLayoutComponent, defineSpoolUi } from '@swirls/spools/ui/slots'const Balance = defineLayoutComponent({  name: 'Balance',  description: 'What is still owed on a job, with a bar showing how much is paid.',  props: z.object({ total: z.number(), paid: z.number() }),  Component: ({ props }) => <BalanceBar total={props.total} paid={props.paid} />,})export const ui = defineSpoolUi({ components: [Balance] })

A layout then calls Balance(job.record.price, @Sum(payments.rows.amount)). The props are a zod object: its keys, in order, are the component's arguments, and its description is what spools ui prompt tells an agent. A component can't take the name of one of the kit's, and two can't share a name. To draw children the layout passes, give the prop to renderNode.

Checking and writing layouts#

sh
bunx spools ui check            # what is wrong with each layoutbunx spools ui check --strict   # and a component the kit hasn't is an errorbunx spools ui prompt           # what to give a coding agent

ui check exits 1 when a layout will not draw as written: no root, a component given what it can't take, a name used and never defined, a tool that doesn't exist, a Query naming a tool that changes things (a Query runs whenever the page draws). A component it doesn't know is taken to be one of yours unless you say --strict. bun run crm:gen runs the same checks and warns.

In the browser, a layout draws what it can. What it can't (a tool that refused, a component that failed) is listed in a strip above the page, by statement.

Writing layouts with an agent#

bunx spools ui prompt prints everything an agent needs to write a layout for this Spool: the language, the kit's signatures, the tools, and your objects with their fields and options. Give it to your coding agent with what the page is for:

sh
bunx spools ui prompt > layouts-prompt.txt

Then put what it writes under ui and run bunx spools ui check.

Security#

A layout is presentation. It decides what a page shows and where, and never who may see or change what.

  • Every tool is one of the CRM's own server functions. Role access, record scopes, record rules, hooks, the timeline and automations apply to a layout's reads and changes as they do to the classic pages. There is no other way from a layout to the data.
  • roles on a page or a record layout chooses who is shown it. It keeps nothing from anyone: use a role's access for that.
  • A layout can't run code. It names components and tools that exist; it has no script, no HTML and no address outside the CRM's own paths and ordinary web links.
  • A layout is part of your config, so it is reviewed, committed and deployed like the rest, and nothing a record holds can change it.

Where things are#

What File
The ui schema and its checks crm/layouts.ts
The kit's names, arguments and descriptions crm/openui/specs.ts
The tools' names and shapes crm/openui/tools.ts
spools ui check and the prompt crm/openui/check.ts, cli/ui.ts
What draws each component, and the renderer crm/ui/openui/components.tsx, render.tsx
What each tool does crm/ui/openui/tools.ts, server/layouts.ts
The pages pages/custom.tsx, views/record-layout.tsx