Compiled against your types
A template reads a Jai struct. Every name, member, prop, function and call is checked when the app builds: a typo stops the build with its line, its column and the members that do exist.
See it →Streaming · a working demo
The census below waits 900 ms before it counts. The page did not wait: its frame and the census's loading state came in the response's first chunk, and the census filled in when its call answered.
| Room | Entries |
|---|---|
| The lobby | 0 |
| The garden | 0 |
Counted after a 900 ms pause: 0 entries in all.
A template language for Jaiweb
Motus is HTML plus a few elements — output, let, if, for, match, components, regions, routes — compiled against the Jai types your app already has. A misspelled member is a build error, not a blank on the page.
In one screen
A template reads a Jai struct. Every name, member, prop, function and call is checked when the app builds: a typo stops the build with its line, its column and the members that do exist.
See it →A compiled template is plain data: a small program that reads the view in place. The same VM runs it in the server, in a WebAssembly build of the app, and in a Cloudflare worker.
See it →Typed props, defaults, children, <@slot> fills. Styles at the root, scoped to a component (nesting with &, props as var(name)), or on one element.
A region is replaced alone on navigation, its <loading> shown at once. A first render streams the frame, then each region; a live one renders again when the rows it read change.
An entry's <routes> are its pages, their params typed. Its data comes from controller procedures called as expressions; its forms call @Actions, whose notes check the inputs.
bind= ties a control to the URL's state, <state> keeps the page's, on:click= writes either, a typed form holds a Jai value. The compiler draws in the browser what it can, asks origin for the parts only origin can draw, alone.
An edge page is made in two places: origin's part once, the request's part at the edge. Each part is cached by what it read and purged when that changes, so a write drops only what it touched.
See it →Mistakes are build errors
These three templates are compiled right now, against the playground's Shop. Under each is what the compiler answered: the message a build stops with, line and column first.
In an app the templates compile with the program (motus_program, an entry's motus_mount), so a template that no longer fits its type is caught before anything runs.
Small programs
Static HTML merges into single literals, constants fold, a branch on a constant keeps only the branch taken. What is left is a few instructions, serialized as plain data for a worker or a WebAssembly unit to run.
Where next
Tour
Each example is a .mot file of this site, compiled when the site was built by the compiler the playground uses (a store's rules: no scripts, CSS checked), and rendered now by the VM with a sample's data. The parts that need a server are working pages of this site.
<output x> writes a value as text, escaped. A computed attribute (title=store.tagline) is escaped too, and an href or src from data is checked: the javascript: URL in the data became #. A value that is not there writes nothing. A member noted @Html in Jai is the one way to insert HTML: what the program made, never what a visitor typed.
<let name value> binds for its children only. <if> takes a bool (a number is not a condition; a text or a list is, when not empty), with <elsif> and <else>. <for p, i in products> gives the index too; 1..5 is a range. <match> compares with each <case>; on an enum, by its names, checked.
Expressions are Jai's: == != < <= > >= && || !, + - * / %. In a tag, outside parentheses, a > ends the tag, so a comparison with > goes in parentheses: <if (stock > 0)> (the compiler refuses the slip <if stock > 0>). + adds numbers or joins text; (if a then b else c) is an inline condition; {a: 1} and [1, 2] are literals. Every expression has a type at compile time: cart == "3" is an error.
Functions are called: money(price, "eur"), default(owner, "nobody yet"), truncate(note, 28). These are Motus's own. An app's procedures are functions too: any top-level procedure of a .jai the template <load>s or a module it <import>s, called by its bare name with whole numbers, floats, bools and text, run at once as the page renders.
<defcomp Card | product: Product, featured: bool = false |> declares a component and its props: string int number bool html, a Jai type by name, or a list [] T. A prop with a default may be left out; one without is required. <children /> is what the caller put inside; <@badge>…</@badge> fills an html prop. Giving a Store where a Product goes is a compile error.
A file's top-level <style> is every element's. A component's <style> is scoped: each selector's last part gets the component's data-m- attribute. Rules nest; & is where the outer selector goes, and a @media inside a rule keeps it. var(pct) reads a prop: the CSS is the same for every render, the value rides on the element as a CSS variable, so a live change animates with the CSS's own transition.
var(pointer.x), var(pointer.y), var(scroll.x), var(scroll.y), var(scroll.progress), var(viewport.width) and var(viewport.height) are the browser's: the client writes them on the page's root once a frame, only when a style reads one. This page's top bar follows scroll.progress; the light on the home page follows the pointer. In the preview below there is no script, so they stay 0.
A <region id="results"> is a part of the page the browser keeps or replaces alone: a navigation or an action's answer sends only the regions whose hash changed. Its <loading> shows at once while a request that changes it goes — a link or form inside it, or one naming it with region="results". transition is fade, slide, rise or scale: a view transition, off when motion is reduced. Open “The HTML it rendered” to see what the client reads.
An entry is mounted at a path; its <routes> say what shows under it. A route binds its parameters to a Jai struct, <route "/posts/:id" |{id}: Post_Params|>, so id is an int (a path where id is not one is not this route). Its other attributes are values readable anywhere — route.title above the routes, so the frame is written once. can= asks for a permission: refused, else= says where to go instead, or the page is a 403. The example is rendered at six paths; in the playground, can() answers yes to what ends in .read.
<routes whole> makes each route a whole page — its own document, no region, no in-place navigation — and <status code=404 /> its answer.
<form call=Comments.add(post = post.id)> posts to its own page, the action's name and fixed arguments signed in the URL (the preview leaves them unsigned and posts nowhere). The other fields come from the inputs, checked by the action's notes — @Required @MaxLength(40) — which also become the inputs' required maxlength="40". An input the action does not take is a compile error. optimistic="remove" and optimistic="add" into="comments" show the change before the answer: for an add, the list's own item is the template, the form's fields in it.
A page's state lives in one of three places, and the template says which. The URL's query: a route's parameter a control binds, <input bind=q> (a checkbox, a radio with its value=, a select's options alike); typing writes q in the address, without a history step. The page: <state open = false>…</state>, scoped as a <let>, one for each row in a loop (by its id), kept across every update of the page; only the browser reads it. A form: its state a value of a Jai type (below).
An element's events write state: on:click=(open = !open), on:click=(price = p), on any element; on:click=Cart.add(sku = p.sku) calls an action. The element that triggers says when and how often: debounce=300, throttle=200, edge="leading", requests="latest" (the default for drawing: a newer one cancels the older), "first" (the default for actions: no double submits), "queue", "all".
A change of state draws, in the browser, what the browser can compute from it (the template's own code, compiled from it: no request), asks origin for the parts it reaches that only origin can draw, each alone, and only else the page whole. The page carries no script of the app's: the runtime is the same for every app.
<form buyer: Buyer call=Box.pay(buyer, event = e.code)> declares the form's state, a value of a Jai type, sent whole to the action whose argument it is (posted as buyer.name, buyer.email). <form Buyer call=X.y> is a form whose action takes the type itself (its state named it); = note.draft gives a starting value, origin's, and note := n.draft takes its type from the action.
<field buyer.name /> draws one member: a label (label=, else the member's name) and its control from its type: a text, a number, a yes/no checkbox, an enum's select, @Multiline a textarea, @Hidden a hidden field; its other attributes are the control's. <fields /> draws the members not placed, <fields after=buyer.name /> those declared after one (before=). Any control binds a member (<input bind=buyer.email>), and anything reads one: <output buyer.name> is drawn in the browser as it is typed.
The action's notes are the checks: @Required, @MaxLength(80) become the controls' required maxlength="80", checked in the browser, then again at origin when it is sent, a refused field marked in place. @Private members are never drawn nor sent. Taken by its action, the form starts again from its starting value.
The compiler reads a template once and records, for every node and expression, what it reads: state, the request, origin's data. Then it cuts the page into parts. A local part reads state and nothing only origin has: its code is the template's, translated for the browser, origin's values it needs lifted into the page beside it. A server part reads state through origin (a call given it): origin renders it alone when asked. An edge part reads the request on an edge page: the edge makes it. What no part can hold (a route's values, the <title>) makes the page whole.
Each state variable gets a plan: the local parts and attributes to draw, the server parts to fetch, or the page whole and why. motus graph prints it for a template; the parts are keyed by the graph, so a part's HTML stands alone in a live push, a fill or a parts answer.
On an edge page a parameter a control binds is a state variable as well: the wall's Cards and List switch is drawn in the browser, the address following; the rest of what it reaches is the page again, made and cached at the edge.
<region live id="wall"> is a live view: the engine keeps what its render read (index ranges of the rows), and when a commit changes those rows it renders the region again, as the viewer, and pushes it to the page, which morphs it in. Nobody says what to watch or when to push.
Where it runs: on the Jaiweb platform, a sandboxed app's live regions are pushed by the engine to signed-in viewers; an edge page's are kept current at the edge by a hub, for every viewer. This site runs alone (./motus_site), where the engine keeps the wall's live region current itself; run ./edge.sh, open the wall through the edge, sign a guestbook in another window, and the wall updates in place.
To watch it happen, open the wall with ?_jw=debug (see how it flows): the debug panel's Flow draws the write, the view's render again (at origin, or at the edge's hub after origin's purge) and the push to the page, each as a pulse along its path, with why it happened.
A template may read an app's models directly: <let rows query Guest_Entry where room == room order by number desc after :before limit 12>. Every query is one index range: the compiler plans it on the model's indexes, and a query no index serves does not compile (it says which @Index would). Its rows are read in place, as the model's struct. Queries are for edge pages and Motus_Flows' own pages; the wall is one. In an edge page, where the rows are read is the template's to say: a query is origin's, its rows baked into the part origin makes once; <let rows edge query ...> makes them a part of their own, fetched at the edge for each request and cached apart from the frame. A query that reads the request (the wall's room, its cursor) must say edge. <let rows edge lazy query ...> reads nothing where it is bound: the render reads it where it first uses its rows (a branch not taken never does), a part of its own at the edge, its region drawn by the rows' shape until they come; refined before it is read (<let newest lazy query rows limit 1 single>), it is still one query. A query inside a <for> over another's rows, reading the row (where order_number == o.number), is an include: read with its collection, once for each row, in the same part: one trip, never a cascade. A query reads its model's public columns; fields reads only those the template reads (followed into components and includes), fields(name, price) those named. The columns are its cache key's too, so it is a choice. A member noted @Private (a password's hash) is never read by a template nor fetched by its queries, and a record is never written whole into a page: a form's argument or an edge wrapper's prop is a value (m.id), not the record. For debugging, <debug><output m></debug> writes it whole (its members, never the @Private ones), drawn only for the product's staff and never cached: in an edge page, a staff's request goes to origin, the page whole.
A page whose frame is all there but whose regions wait on calls answers at once: the frame, each waiting region as its skeleton (its <loading>), then each region as its calls answer, sent down the same response as a <template jw-fill>. Nothing in the template asks for it: the census below waits 900 ms on purpose.
An entry mounted under a path with parameters (/rooms/:room) may have one procedure noted @Enter: it runs before anything under it, every call and every action, each request. Answering redirect goes there instead; error is a 404. Calls and actions read the parameters with motus_mounted(Rooms.At).
@Permission(guestbook.write) on an action (or a call) is checked before it runs: refused, the answer is 401 (nobody signed in) or 403. In the rooms a visitor joins as a guest — an account of their own, which holds the permission — and the template asks the same question with can("guestbook.write").
A template with a query said edge is made in two places; nothing else says so. What reads the request (its parameters, who asks) or the rows of a query said edge is the edge's; the rest is origin's, made once with its calls answered, as the residual program the edge keeps. A wrapper the page calls with children (the wall's <Page>) is a fragment of its own, shared by every page with it. Each part is a URL kept in the colo's cache and the CDN's, purged by tag when a write touches what it read: signing the lobby's guestbook drops the lobby's wall pages and the rooms' counts, nothing else.
A page that reads nothing of who asks is public; one that reads @Session members or can() is decided at the edge, from the session's home there. Without an edge in front — this server alone — origin makes the page whole.
Any page with ?_jw=debug says how it was made, and its debug panel's Flow draws it: through ./edge.sh, the wall shows each part coming from the colo's cache, the CDN's tiers or origin's stream, the edge rendering it, and, when a guestbook is signed, origin's purge by tag, the colo and the tiers dropping it, and the hub rendering the wall again and pushing it. A room is made at origin and passes through the edge.
Streaming · a working demo
The census below waits 900 ms before it counts. The page did not wait: its frame and the census's loading state came in the response's first chunk, and the census filled in when its call answered.
| Room | Entries |
|---|
Counted after a
A template and its data, compiled and rendered by the server as you type, under a store's rules.
Integrations
Motus lives in this repository as sdk/Motus (the language and its VM) and sdk/Motus_Flows (entries, calls, actions, edge pages). The code below is from apps in this repository, read from their files when this site was built.
A part of an app — a dashboard, a site — is one template mounted at a path with the controllers whose procedures it calls. Argoshot mounts five. @Call procedures are its reads, @Action ones its forms'. The template compiles with the program: a misspelled call, an argument of the wrong type, a field the action does not take, is a build error.
Emails, invoices, a fragment to push: motus_program(TEMPLATE_x, View) compiles with the program, so its errors are build errors, and motus_render(*program, *view) renders. The campaigns app sends its emails this way.
A merchant's store template is text, compiled when it is saved with untrusted = true: no scripts, no event handlers, no frames, forms post to the store, CSS checked. Its errors go back with their lines; the program is serialized and kept. This site's playground compiles visitors' templates the same way, and renders them within limits.
motus_mount(path, template, controllers, library, models = ..., params = ...): the models are what its queries read, params a struct of the query string's parameters the template reads by name, the controllers answer origin's part. The catalog example serves 20,000 parts this way; sdk/Motus/edge holds the worker.
Next
The plan is one standalone package around the same compiler and VM, built for wasm32, with two functions: compile(source, schema), which compiles a template against a description of its data and returns a program or its errors with lines and columns, and render(program, json), which renders a program with data given as JSON. Each host wraps those two.
The compiler and VM of Motus, freestanding, exporting compile and render. The VM already runs in WebAssembly (the edge worker's motus_edge.wasm); what it lacks is the compiler beside it and a schema in place of Jai's type information.
The core with typings, for Node, Deno, Bun and workers: templates compiled at build time against a schema of your types, rendered on the server or at the edge.
The same .wasm, run by wasmtime behind a typed wrapper: a program compiled once and rendered per request, its errors surfaced at build time from a build.rs.
A template handler for .mot files that compiles each view against a schema of its locals and renders through the core, so a view that no longer fits its data fails in CI, not in production.
Today motus_compile_with takes a Jai *Type_Info: the names a template reads, their types and their layout in memory all come from it, and the VM reads the view in place. A compile driven by a schema — JSON Schema in, the same checks out, the data laid out from JSON — is the piece the package needs, and it does not exist yet.
For agents
This repository ships a Claude Code skill at .claude/skills/motus/SKILL.md: a short, precise brief on the language, the Jai side of an entry, and the mistakes worth avoiding. With it, an agent writes templates that compile the first time, and checks them before it says it is done.
Its description, which Claude Code reads to decide when to load it:
motus check, motus fmt, build.
A skill is a folder. Claude Code finds the ones under .claude/skills/ of the repository it works in, and loads one when a task matches its description: here, any .mot file, an entry, a component's styles, or the Jai a template calls.
Copy the folder into the other repository's skills.
Keep its paths true. It sends the agent to sdk/Motus/module.jai, sdk/Motus_Flows/entries.jai, the Motus tests, examples/argoshot and tools/motus/motus. In a repository that vendors Jaiweb at its root they resolve as they are; elsewhere, edit those lines to where Jaiweb is.
Ask for the work. “Add a usage page to the dashboard entry, with the last 30 days as a chart”: the agent reads the skill, writes the .mot and its controller, runs motus check and motus fmt, then builds.
404
There is no page at this address. The tour and the playground are where most things are.