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 →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.
<!-- <output> writes a value as text, escaped; a computed attribute is escaped too. A URL from data is
checked: a javascript: one becomes "#". A missing value writes nothing; default gives one. -->
<h2><output store.name></h2>
<p><output store.tagline></p>
<p title=store.tagline>The tagline again, in a title: hover it.</p>
<ul>
<for p in products>
<li><a href=p.url><output p.name></a> <small class="muted"><output p.url></small></li>
</for>
</ul>
<p>First price, in cents: <output products[0].price>; its rating: <output products[0].rating>; its status: <output products[0].status></p>
<p>A product that is not there: [<output products[9].name>]</p>
<p>The note: <output default(note, "(none)")></p>
<h2>Ana & Co</h2>
<p><b>Shoes</b> made by hand in Porto</p>
<p title="<b>Shoes</b> made by hand in Porto">The tagline again, in a title: hover it.</p>
<ul>
<li><a href="/p/tenis-azul">Tênis Azul</a> <small class="muted">/p/tenis-azul</small></li>
<li><a href="#">Bota <Couro></a> <small class="muted">javascript:alert(1)</small></li>
<li><a href="/p/sandalia-rio">Sandália Rio</a> <small class="muted">/p/sandalia-rio</small></li>
<li><a href="/p/mocassim">Mocassim Lã</a> <small class="muted">/p/mocassim</small></li>
</ul>
<p>First price, in cents: 8900; its rating: 4.6; its status: ACTIVE</p>
<p>A product that is not there: []</p>
<p>The note: (none)</p><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.
<!-- let binds a value for what is inside it; if, elsif, else; for with an index, and over a range;
match on a value (an enum, by its names). -->
<let low 3>
<ol>
<for p, i in products>
<li>
<h3><output i + 1>. <output p.name></h3>
<if p.stock == 0>
<Badge tone="bad">Sold out</Badge>
<elsif (p.stock <= low)>
<Badge tone="warn">Only <output p.stock> left</Badge>
<else>
<Badge tone="ok">In stock</Badge>
</if>
<match p.status>
<case "ACTIVE"><span>On sale</span></case>
<case "DRAFT"><span>Coming soon</span></case>
<default><span>Archived</span></default>
</match>
<span title=p.rating><for n in 1..5><if (n <= p.rating)>★<else>☆</if></for></span>
</li>
</for>
</ol>
</let>
<ol>
<li>
<h3>1. Tênis Azul</h3>
<span data-m-270290e3 class="badge ok">In stock</span><span>On sale</span><span title="4.6">★★★★☆</span>
</li>
<li>
<h3>2. Bota <Couro></h3>
<span data-m-270290e3 class="badge warn">Only 2 left</span><span>On sale</span><span title="4.1">★★★★☆</span>
</li>
<li>
<h3>3. Sandália Rio</h3>
<span data-m-270290e3 class="badge bad">Sold out</span><span>On sale</span><span title="3.8">★★★☆☆</span>
</li>
<li>
<h3>4. Mocassim Lã</h3>
<span data-m-270290e3 class="badge ok">In stock</span><span>Coming soon</span><span title="4.9">★★★★☆</span>
</li>
</ol>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.
<!-- Arithmetic; + joins text; comparisons and logic are words (eq neq lt lte gt gte and or not: < would be
markup); an inline if; object and array literals; a list's count; indexes. -->
<let up (stats[0].value - stats[0].previous)>
<dl>
<dt>Visits, this week and last</dt>
<dd><output number(stats[0].value)> and <output number(stats[0].previous)></dd>
<dt>More by</dt>
<dd><output number(up)> (<output number(up * 100 / stats[0].previous, 1)>%)</dd>
<dt>A day, on average</dt>
<dd><output number(stats[0].value / days.count)></dd>
<dt>Goal reached?</dt>
<dd><output (signups >= goal)></dd>
<dt>Past three quarters of it, and not there yet?</dt>
<dd><output (signups >= goal * 3 / 4 && !(signups >= goal))></dd>
<dt>So we are</dt>
<dd><output (if signups >= goal then "on target" else "behind")></dd>
<dt>Text joined with numbers</dt>
<dd><output "Team " + (trim(team)) + ", " + regions.count + " regions"></dd>
</dl>
</let>
<let plan {name: "Pro", seats: 8, zones: ["eu", "us"]}>
<p><output plan.name>: <output plan.seats> seats in <output join(plan.zones, " and ")></p>
</let>
<p>Busy days: <for d in days>
<if (d.visits > 8000 || d.label == "Mon")><b><output d.label></b> </if>
</for></p>
<dl>
<dt>Visits, this week and last</dt>
<dd>48,210 and 41,980</dd>
<dt>More by</dt>
<dd>6,230 (14.8%)</dd>
<dt>A day, on average</dt>
<dd>6,887</dd>
<dt>Goal reached?</dt>
<dd>false</dd>
<dt>Past three quarters of it, and not there yet?</dt>
<dd>true</dd>
<dt>So we are</dt>
<dd>behind</dd>
<dt>Text joined with numbers</dt>
<dd>Team Night Shift, 4 regions</dd>
</dl>
<p>Pro: 8 seats in eu and us</p>
<p>Busy days: <b>Mon</b> <b>Thu</b> <b>Fri</b> </p>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.
<!-- Every function of Motus's own, called as Jai calls: the value first, its arguments after it. -->
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>uppercase(team)</code></td>
<td><output uppercase(team)></td>
</tr>
<tr>
<td><code>lowercase("ÁGUA FRIA")</code></td>
<td><output lowercase("ÁGUA FRIA")></td>
</tr>
<tr>
<td><code>trim(team)</code></td>
<td>[<output trim(team)>]</td>
</tr>
<tr>
<td><code>length(trim(team))</code></td>
<td><output length(trim(team))></td>
</tr>
<tr>
<td><code>default(owner, "nobody yet")</code></td>
<td><output default(owner, "nobody yet")></td>
</tr>
<tr>
<td><code>join(regions, " · ")</code></td>
<td><output join(regions, " · ")></td>
</tr>
<tr>
<td><code>truncate(note, 28)</code></td>
<td><output truncate(note, 28)></td>
</tr>
<tr>
<td><code>first(regions)</code></td>
<td><output first(regions)></td>
</tr>
<tr>
<td><code>last(regions)</code></td>
<td><output last(regions)></td>
</tr>
<tr>
<td><code>money(revenue, "eur")</code></td>
<td><output money(revenue, "eur")></td>
</tr>
<tr>
<td><code>money(revenue, "usd")</code></td>
<td><output money(revenue, "usd")></td>
</tr>
<tr>
<td><code>money(revenue, "brl")</code></td>
<td><output money(revenue, "brl")></td>
</tr>
<tr>
<td><code>date(updated)</code></td>
<td><output date(updated)></td>
</tr>
<tr>
<td><code>date(updated, "yyyy-mm-dd hh:nn")</code></td>
<td><output date(updated, "yyyy-mm-dd hh:nn")></td>
</tr>
<tr>
<td><code>plural(incidents.count, "incident", "incidents")</code></td>
<td><output incidents.count> <output plural(incidents.count, "incident", "incidents")></td>
</tr>
<tr>
<td><code>paragraphs(note)</code></td>
<td><output paragraphs(note)></td>
</tr>
<tr>
<td><code>where(incidents, "open", true)</code></td>
<td><for i in where(incidents, "open", true)><output i.title>; </for></td>
</tr>
<tr>
<td><code>number(stats[0].value)</code></td>
<td><output number(stats[0].value)></td>
</tr>
<tr>
<td><code>number(2 / 3, 2)</code></td>
<td><output number(2 / 3, 2)></td>
</tr>
<tr>
<td><code>percent(signups, goal)</code></td>
<td><output percent(signups, goal)>%</td>
</tr>
<tr>
<td><code>"/s?q=" + url("a b&c")</code></td>
<td><output "/s?q=" + url("a b&c")></td>
</tr>
<tr>
<td><code>css(accent)</code></td>
<td><output css(accent)></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>uppercase(team)</code></td>
<td> NIGHT SHIFT </td>
</tr>
<tr>
<td><code>lowercase("ÁGUA FRIA")</code></td>
<td>água fria</td>
</tr>
<tr>
<td><code>trim(team)</code></td>
<td>[Night Shift]</td>
</tr>
<tr>
<td><code>length(trim(team))</code></td>
<td>11</td>
</tr>
<tr>
<td><code>default(owner, "nobody yet")</code></td>
<td>nobody yet</td>
</tr>
<tr>
<td><code>join(regions, " · ")</code></td>
<td>Lisbon · Recife · Austin · Osaka</td>
</tr>
<tr>
<td><code>truncate(note, 28)</code></td>
<td>Friday was the best day yet.…</td>
</tr>
<tr>
<td><code>first(regions)</code></td>
<td>Lisbon</td>
</tr>
<tr>
<td><code>last(regions)</code></td>
<td>Osaka</td>
</tr>
<tr>
<td><code>money(revenue, "eur")</code></td>
<td>€43.182,50</td>
</tr>
<tr>
<td><code>money(revenue, "usd")</code></td>
<td>$43,182.50</td>
</tr>
<tr>
<td><code>money(revenue, "brl")</code></td>
<td>R$ 43.182,50</td>
</tr>
<tr>
<td><code>date(updated)</code></td>
<td>13/10/2026</td>
</tr>
<tr>
<td><code>date(updated, "yyyy-mm-dd hh:nn")</code></td>
<td>2026-10-13 14:00</td>
</tr>
<tr>
<td><code>plural(incidents.count, "incident", "incidents")</code></td>
<td>3 incidents</td>
</tr>
<tr>
<td><code>paragraphs(note)</code></td>
<td>
<p>Friday was the best day yet.<br>The newsletter went out at nine.</p>
<p>Sign-ups trail last week: the form lost a field on Tuesday.</p>
</td>
</tr>
<tr>
<td><code>where(incidents, "open", true)</code></td>
<td>Checkout slow in Osaka; Card payments failing; </td>
</tr>
<tr>
<td><code>number(stats[0].value)</code></td>
<td>48,210</td>
</tr>
<tr>
<td><code>number(2 / 3, 2)</code></td>
<td>0.67</td>
</tr>
<tr>
<td><code>percent(signups, goal)</code></td>
<td>78.9%</td>
</tr>
<tr>
<td><code>"/s?q=" + url("a b&c")</code></td>
<td>/s?q=a%20b%26c</td>
</tr>
<tr>
<td><code>css(accent)</code></td>
<td>#7c3aed position: fixed</td>
</tr>
</tbody>
</table><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.
<!-- Components: typed props (a Jai type by name, [] T, string, int, bool, html), defaults, the children
the caller put inside, and an html prop filled with <@name>. Defined at the top of a file. -->
<defcomp Card | product: Product, currency: string, featured: bool = false, badge: html = "" |>
<article class=(if featured then "card featured" else "card")>
<header>
<h3><output product.name></h3> <output badge>
</header>
<p><Price cents=product.price currency=currency /></p>
<children />
</article>
</defcomp>
<defcomp Shelf | title: string, items: [] Product, currency: string |>
<section>
<h2><output title></h2>
<for p, i in items>
<Card product=p currency=currency featured=(i == 0)>
<@badge><if p.stock == 0><Badge tone="bad">Sold out</Badge></if></@badge>
<p class="muted"><output truncate(p.about, 60)></p>
</Card>
</for>
</section>
</defcomp>
<Shelf title=("New at " + store.name) items=products currency=store.currency />
<section>
<h2>New at Ana & Co</h2>
<article class="card featured">
<header>
<h3>Tênis Azul</h3>
</header>
<p><span class="price">€89,00</span></p>
<p class="muted">A canvas sneaker in deep blue, stitched sole, cotton laces. …</p>
</article>
<article class="card">
<header>
<h3>Bota <Couro></h3>
</header>
<p><span class="price">€219,00</span></p>
<p class="muted">Ankle boots in vegetable-tanned leather. Its name has a tag …</p>
</article>
<article class="card">
<header>
<h3>Sandália Rio</h3>
<span data-m-270290e3 class="badge bad">Sold out</span>
</header>
<p><span class="price">€54,00</span></p>
<p class="muted">Cork footbed, two straps, made for long walks by the water.</p>
</article>
<article class="card">
<header>
<h3>Mocassim Lã</h3>
</header>
<p><span class="price">€125,00</span></p>
<p class="muted">A wool loafer for cold floors. Not on sale yet.</p>
</article>
</section>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.
<!-- Three levels of style. A root <style> is every element's. A component's <style> is its own elements'
(scoped): rules nest (& is the outer selector), var(name) reads its props, var(pointer.x) and the
like the browser's. An element's style= is that one node's (a value from data: made CSS's). -->
<style>
:root { --track: #e9e2d5; --good: #2f7d46 }
@media (prefers-color-scheme: dark) { :root { --track: #34302a } }
.board { display: grid; gap: 14px; max-width: 520px }
</style>
<defcomp Meter | label: string, pct: number, tone: string = "#2563eb" |>
<style>
.meter {
display: grid;
gap: 6px;
.track { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden }
.fill {
width: calc(min(var(pct), 100) * 1%);
height: 100%;
background: var(tone, gray);
transition: width .4s ease;
&:hover { filter: brightness(1.15) }
}
.done & .fill { background: var(--good) }
@media (max-width: 420px) { font-size: 13px }
}
.lean { translate: calc(var(pointer.x) * .01px) 0 }
</style>
<div class="meter">
<span><output label> <b><output number(pct, 0)>%</b></span>
<div class="track">
<div class="fill lean"></div>
</div>
</div>
</defcomp>
<div class=(if signups >= goal then "board done" else "board")>
<Meter label="Sign-ups toward the goal" pct=(signups * 100 / goal) tone="#c2410c" />
<for s in stats>
<Meter label=(s.label + ", against last week") pct=(s.value * 100 / s.previous) />
</for>
<p style="margin: 0; font-size: 13px; opacity: .75">An element's own style, as written.</p>
<p style=("border-left: 4px solid " + (css(accent)) + "; padding-left: 8px")>From data, made CSS's: <code>
<output css(accent)>
</code></p>
</div>
<style>
:root { --track: #e9e2d5; --good: #2f7d46 }
@media (prefers-color-scheme: dark) { :root { --track: #34302a } }
.board { display: grid; gap: 14px; max-width: 520px }
</style>
<div class="board">
<div data-m-fc00292e style="--m-fc00292e-0:78.916667;--m-fc00292e-1:#c2410c;" class="meter"><span data-m-fc00292e>Sign-ups toward the goal <b data-m-fc00292e>79%</b></span>
<div data-m-fc00292e class="track">
<div data-m-fc00292e class="fill lean"></div>
</div>
</div>
<div data-m-fc00292e style="--m-fc00292e-0:114.8404;--m-fc00292e-1:#2563eb;" class="meter"><span data-m-fc00292e>Visits, against last week <b data-m-fc00292e>115%</b></span>
<div data-m-fc00292e class="track">
<div data-m-fc00292e class="fill lean"></div>
</div>
</div>
<div data-m-fc00292e style="--m-fc00292e-0:93.577075;--m-fc00292e-1:#2563eb;" class="meter"><span data-m-fc00292e>Sign-ups, against last week <b data-m-fc00292e>94%</b></span>
<div data-m-fc00292e class="track">
<div data-m-fc00292e class="fill lean"></div>
</div>
</div>
<div data-m-fc00292e style="--m-fc00292e-0:120;--m-fc00292e-1:#2563eb;" class="meter"><span data-m-fc00292e>Orders, against last week <b data-m-fc00292e>120%</b></span>
<div data-m-fc00292e class="track">
<div data-m-fc00292e class="fill lean"></div>
</div>
</div>
<p style="margin: 0; font-size: 13px; opacity: .75">An element's own style, as written.</p>
<p style="border-left: 4px solid #7c3aed position: fixed; padding-left: 8px">From data, made CSS's: <code>#7c3aed position: fixed</code></p>
</div>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.
<!-- A region is a part of the page kept or replaced alone. A link or a form inside it (or one naming it:
region="results") shows its <loading> at once while the request goes; transition= says how it moves
(fade, slide, rise, scale: view transitions, reduced motion respected). -->
<defcomp Spinner | label: string |>
<span class="spinner" role="status"><output label></span>
</defcomp>
<form method="get" action="/search" region="results">
<input name="q" placeholder="Search shoes" aria-label="Search"> <button>Search</button>
</form>
<region id="results" transition="rise">
<loading><Spinner label="Searching…" /></loading>
<ul>
<for p in products>
<li><a href=("/p/" + p.id)><output p.name></a></li>
</for>
</ul>
</region>
<region id="cart" transition="fade">
<p><output cart> <output plural(cart, "item", "items")> in your cart</p>
</region>
<form data-jw-busy="#results" data-jw-placeholder="#results => motus-loading-results" data-jw-delay="0" method="get" action="/search"><input name="q" placeholder="Search shoes" aria-label="Search">
<button>Search</button>
</form>
<jw-region id="results" hash="aa1ca9f41b4335e0" data-jw-transition="rise">
<ul>
<li><a data-jw-busy="#results" data-jw-placeholder="#results => motus-loading-results" data-jw-delay="0" href="/p/1">Tênis Azul</a></li>
<li><a data-jw-busy="#results" data-jw-placeholder="#results => motus-loading-results" data-jw-delay="0" href="/p/2">Bota <Couro></a></li>
<li><a data-jw-busy="#results" data-jw-placeholder="#results => motus-loading-results" data-jw-delay="0" href="/p/3">Sandália Rio</a></li>
<li><a data-jw-busy="#results" data-jw-placeholder="#results => motus-loading-results" data-jw-delay="0" href="/p/4">Mocassim Lã</a></li>
</ul>
</jw-region>
<template id="motus-loading-results"><span class="spinner" role="status">Searching…</span></template>
<jw-region id="cart" hash="592a95e4464ddfcc" data-jw-transition="fade">
<p>2 items in your cart</p>
</jw-region>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.
<!-- A frame written once, its routes inside it: each route's params typed (Post_Params: id is an int),
its values (route.title, a <@name>'s HTML) readable above them; can= asks for a permission, else=
where to go instead; <redirect>, <status>; "*" any other path. -->
<header>
<b><output title></b> · <output route.title>
<nav><output route.actions></nav>
</header>
<routes transition="fade">
<route "/" title="All posts">
<ul>
<for p in posts>
<if !p.draft>
<li><a href=("/posts/" + p.id)><output p.title></a></li>
</if>
</for>
</ul>
</route>
<route "/posts/:id" |{id}: Post_Params| title=("Post #" + id)>
<@actions><a href="/">All posts</a></@actions>
<for p in posts>
<if p.id == id>
<h2><output p.title></h2>
<output paragraphs(p.body)>
</if>
</for>
</route>
<route "/drafts" title="Drafts" can="posts.write" else="/">
<for p in where(posts, "draft", true)>
<p><output p.title></p>
</for>
</route>
<route "/stats" title="Stats" can="stats.read">
<let published where(posts, "draft", false)>
<p><output posts.count> posts, <output published.count> published.</p>
</let>
</route>
<route "/old">
<redirect to="/" />
</route>
<route "*" title="Not found">
<status code=404 />
<p>Nothing at this address.</p>
</route>
</routes>
At /
<header><b>Field Notes</b> · All posts
<nav></nav>
</header>
<jw-region id="routes" hash="8777b18540340745" data-jw-transition="fade" data-jw-routes>
<ul>
<li><a href="/posts/1">Templates that know your types</a></li>
<li><a href="/posts/2">Pages in parts</a></li>
</ul>
</jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template>At /posts/2
<header><b>Field Notes</b> · Post #2
<nav><a href="/">All posts</a></nav>
</header>
<jw-region id="routes" hash="8393f819641563bd" data-jw-transition="fade" data-jw-routes>
<h2>Pages in parts</h2>
<p>A region is a part of the page kept or replaced alone.</p>
<p>Navigation sends only the regions that changed.</p>
</jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template>At /drafts
<header><b>Field Notes</b> · Drafts
<nav></nav>
</header>
<jw-region id="routes" hash="cbf29ce484222325" data-jw-transition="fade" data-jw-routes></jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template>At /stats
<header><b>Field Notes</b> · Stats
<nav></nav>
</header>
<jw-region id="routes" hash="6b8238682c383ba4" data-jw-transition="fade" data-jw-routes>
<p>3 posts, 2 published.</p>
</jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template>At /old
<header><b>Field Notes</b> ·
<nav></nav>
</header>
<jw-region id="routes" hash="cbf29ce484222325" data-jw-transition="fade" data-jw-routes></jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template>At /nope
<header><b>Field Notes</b> · Not found
<nav></nav>
</header>
<jw-region id="routes" hash="25dc063cef78d022" data-jw-transition="fade" data-jw-routes>
<p>Nothing at this address.</p>
</jw-region>
<template id="motus-route-c91d661a5a" data-jw-outlet="routes" data-jw-route="/">
<ul></ul>
</template>
<template id="motus-route-ab4bfed46c" data-jw-outlet="routes" data-jw-route="/posts/:id"></template>
<template id="motus-route-ae964fd487" data-jw-outlet="routes" data-jw-route="/drafts"></template>
<template id="motus-route-37e3ca3358" data-jw-outlet="routes" data-jw-route="/stats">
<p><jw-skel></jw-skel> posts, <jw-skel></jw-skel> published.</p>
</template>
<template id="motus-route-04b27d4030" data-jw-outlet="routes" data-jw-route="/old"><redirect to="/"></redirect></template>
<template id="motus-route-c91d6b1a5a" data-jw-outlet="routes" data-jw-route="*"><status></status>
<p>Nothing at this address.</p>
</template><routes whole> makes each route a whole page — its own document, no region, no in-place navigation — and <status code=404 /> its answer.
<!-- <routes whole>: each route is the whole page, its own document; no frame around them, no region. -->
<routes whole>
<route "/">
<!doctype html>
<html lang="en">
<head>
<title><output title></title>
</head>
<body>
<h1><output title></h1>
<p><output author.bio></p>
<p><a href="/about">About the author</a></p>
</body>
</html>
</route>
<route "/about">
<!doctype html>
<html lang="en">
<head>
<title>About · <output title></title>
</head>
<body>
<h1><output author.name></h1>
<p><a href=author.site><output author.site></a></p>
</body>
</html>
</route>
<route "*">
<status code=404 />
<!doctype html>
<html lang="en">
<head>
<title>Not found</title>
</head>
<body>
<h1>Not found</h1>
</body>
</html>
</route>
</routes>
At /
<!doctype html>
<html lang="en">
<head>
<title>Field Notes</title>
<style>:root {
color-scheme: light dark;
--kit-ink: #1f1d1a;
--kit-muted: #6f6a60;
--kit-line: #e5dfd4;
--kit-bg: #fffdf9;
--kit-accent: #c2410c;
--kit-ok: #2f7d46;
--kit-warn: #9a5b00;
--kit-bad: #b42318;
}@media (prefers-color-scheme: dark) {
:root { --kit-ink: #ece6da; --kit-muted: #a59d8f; --kit-line: #34302a; --kit-bg: #171512; --kit-accent: #ff8a5c; --kit-ok: #6fcf8e; --kit-warn: #f2b45c; --kit-bad: #ff8b80; }
}body { margin: 0; padding: 18px; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--kit-ink); background: var(--kit-bg); }h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }a { color: var(--kit-accent); }code { font: 13px ui-monospace, Menlo, monospace; }table { border-collapse: collapse; }td, th { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--kit-line); vertical-align: top; }input, button, textarea { font: inherit; color: inherit; }input, textarea { padding: 6px 8px; border: 1px solid var(--kit-line); border-radius: 6px; background: transparent; }button { padding: 6px 12px; border: 1px solid var(--kit-line); border-radius: 6px; background: transparent; cursor: pointer; }.muted { color: var(--kit-muted); }jw-skel{display:inline-block;min-width:3em;height:.85em;border-radius:4px;background:currentColor;opacity:.12;vertical-align:middle}jw-skel.w{min-width:8em}</style>
</head>
<body>
<h1>Field Notes</h1>
<p>Writes about tools that stay out of the way.</p>
<p><a href="/about">About the author</a></p>
</body>
</html>At /about
<!doctype html>
<html lang="en">
<head>
<title>About · Field Notes</title>
</head>
<body>
<h1>Inês Duarte</h1>
<p><a href="https://example.com/ines">https://example.com/ines</a></p>
</body>
</html>At /nope
<!doctype html>
<html lang="en">
<head>
<title>Not found</title>
</head>
<body>
<h1>Not found</h1>
</body>
</html><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 form calls an action: it posts to its own page, the call and its fixed arguments signed in its URL
(in a preview, not signed: it posts nowhere); its inputs get the checks the action's notes say
(Comment_Add: name @Required @MaxLength(40)). optimistic= shows the change before the answer. -->
<let post posts[0]>
<h2><output post.title></h2>
<ul id="comments">
<for c in post.comments>
<li>
<b><output c.name></b> <span><output c.text></span>
<form call=Comments.erase(id = c.id) optimistic="remove"><button>Remove</button></form>
</li>
</for>
</ul>
<form call=Comments.add(post = post.id) optimistic="add" into="comments">
<input name="name" placeholder="Your name" aria-label="Your name">
<input name="text" placeholder="Say something kind" aria-label="Comment">
<button>Comment</button>
</form>
</let>
<h2>Templates that know your types</h2>
<ul id="comments">
<li data-jw-item><b>Rui</b> <span>The build error on a typo saved me a deploy.</span>
<form action="/play?_a=Comments.erase%3Fid%3D11.preview" method="post" data-jw-optimistic="remove">
<button>Remove</button>
</form>
</li>
<li data-jw-item><b>Mia</b> <span>And the error says which members exist. <3</span>
<form action="/play?_a=Comments.erase%3Fid%3D12.preview" method="post" data-jw-optimistic="remove">
<button>Remove</button>
</form>
</li>
</ul>
<form action="/play?_a=Comments.add%3Fpost%3D1.preview" method="post" data-jw-placeholder="#comments +> motus-add-37"><input required maxlength="40" name="name" placeholder="Your name" aria-label="Your name"><input required maxlength="500" name="text" placeholder="Say something kind" aria-label="Comment">
<button>Comment</button>
</form>
<template id="motus-add-37">
<li><b><jw-field name="name"></jw-field></b> <span><jw-field name="text"></jw-field></span>
<form optimistic="remove">
<button>Remove</button>
</form>
</li>
</template><if can("guestbook.write")>
<form call=Guestbook.sign() optimistic="add" into="entries" class="panel sign">
<label class="field">Your message
<textarea name="message" rows="3" placeholder="What would you build with typed templates?"></textarea>
</label>
<div class="row"><button class="btn accent">Sign the guestbook</button></div>
</form>
<else>
<form call=Rooms.join() class="panel join">
<label class="field">Your name, to sign as
<input name="name" placeholder="Ana" autocomplete="nickname">
</label>
<div class="row">
<button class="btn">Join as a guest</button> <span class="small muted">An account of your own, here only.</span>
</div>
</form>
</if>
<region id="book" transition="rise">
<let lines Guestbook.list()>
<if !lines>
<p class="empty">No one has signed this room's guestbook yet.</p>
</if>
</let>
<ul id="entries" class="entries">
<for e in Guestbook.list()>
<li class="entry">
<span class="n">#<output e.number></span>
<b><output e.name></b>
<if e.mine>
<form call=Guestbook.erase(id = e.id) optimistic="remove">
<button aria-label="Remove your entry">Remove</button>
</form>
<else>
<span></span>
</if>
<p><output e.message></p>
</li>
</for>
</ul>
</region>Guestbook :: struct {
Line :: struct { id: int; number: int; name: string; message: string; mine: bool; }
// The room's last entries, newest first.
list :: () -> (lines: [] Line = .[]) {
room := motus_mounted(Rooms.At).room;
me := principal().user;
rows: [] Guest_Entry;
rows = where(Guest_Entry, #code it.room == room, order_by = "number", descending = true, limit = 30);
lines := NewArray(rows.count, Line,, allocator = temp);
for rows lines[it_index] = .{it.id, it.number, it.name, it.message, me != 0 && it.author == me};
return lines;
} @Call @Async
sign :: (p: struct { message: string; @Required @MaxLength(280) }) -> (done: Motus_Done = .{}) {
room := motus_mounted(Rooms.At).room;
who := profile();
name := ifx who.rows.count then who.rows[0].name else "A guest";
user := principal().user;
for transaction() {
last := where(Guest_Entry, #code it.room == room, order_by = "number", descending = true, limit = 1);
number := ifx last.count then last[0].number + 1 else 1;
created := create(Guest_Entry, .{room = room, number = number, author = user, name = name, message = trim(p.message)});
}
return .{notice = "Signed. It is on the wall too."};
} @Action @Async @Permission(guestbook.write)
erase :: (p: struct { id: int; }) -> (done: Motus_Done = .{}) {
user := principal().user;
gone := false;
for transaction() {
entry := find(Guest_Entry, p.id);
if entry && entry.author == user gone = delete(Guest_Entry, p.id);
}
if !gone return .{error = "Only your own entries are yours to remove."};
return .{notice = "Removed."};
} @Action @Async @Permission(guestbook.write)
}
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.
<div class="chips" role="group" aria-label="Price">
<span class="mute">Price</span>
<button type="button" on:click=(pick.price = 0) aria-pressed=(if pick.price == 0 then "true" else "false")>Any</button>
<for p in m.prices>
<button type="button" on:click=(pick.price = p) aria-pressed=(if pick.price == p then "true" else "false")>
<output money(p, "eur")>
</button>
</for>
</div>
<div class="stage">STAGE</div>
<div class="rows" role="group" aria-label=(section_name(pick.section) + " seats")>
<for row in m.rows>
<div class="row">
<span class="rn"><output row.name></span>
<for s in row.seats>
<state picked = false>
<label class=(if s.state == "sold" then (if picked then "seat sold lost" else "seat sold") else (if s.state == "held" then (if picked then "seat held lost" else "seat held") else (if picked then "seat picked" else (if ((pick.price != 0 && pick.price != s.price) || (pick.step && !s.step_free)) then "seat dim" else (if s.fresh then "seat fresh" else "seat"))))) data-aisle=s.aisle title=s.label>
<input type="checkbox" bind=picked name="seats" value=s.code disabled=(s.state != "free") aria-label=s.label>
</label>
</state>
</for>
<span class="rn"><output row.name></span>
</div>
</for>
</div>
<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.
<form buyer: Buyer class="checkout" call=Box.pay(buyer, event = e.code)>
<div class="who panel">
<h2>Who is coming</h2>
<field buyer.name label="Name on the tickets" autocomplete="name" />
<field buyer.email label="Email for the tickets" type="email" autocomplete="email" />
<label>How many of them are students? <input type="number" bind=q.students min="0" max=h.count></label>
Buyer :: struct { // (the checkout's form, a typed one: <form buyer: Buyer ...>, its fields drawn from these notes)
name: string; @Required @MaxLength(80)
email: string; @Required @MaxLength(120)
}
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.
<div class="switch" role="radiogroup" aria-label="Show as">
<label><input type="radio" bind=layout value="cards"> Cards</label>
<label><input type="radio" bind=layout value="list"> List</label>
</div><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 live region: when rows its render read change, the engine renders it again, as the viewer, and
pushes it to the page (an app on the platform; an edge page's, by the edge's hub). In a preview there
is no engine behind it: a region like any other. -->
<region live id="comments" transition="fade">
<for p in posts>
<if p.comments>
<h3><output p.title></h3>
<ul>
<for c in p.comments>
<li><b><output c.name></b>: <output c.text></li>
</for>
</ul>
</if>
</for>
</region>
<jw-region id="comments" hash="8c93ee921fd07805" data-jw-transition="fade">
<h3>Templates that know your types</h3>
<ul>
<li><b>Rui</b>: The build error on a typo saved me a deploy.</li>
<li><b>Mia</b>: And the error says which members exist. <3</li>
</ul>
<h3>Rendering at the edge (draft)</h3>
<ul>
<li><b>Leo</b>: Waiting for this one.</li>
</ul>
</jw-region><region id="wall" live transition="rise">
<loading>
<ul class="notes">
<li class="ghost-note"></li>
<li class="ghost-note"></li>
<li class="ghost-note"></li>
</ul>
</loading>
<!-- tour:switch -->
<div class="switch" role="radiogroup" aria-label="Show as">
<label><input type="radio" bind=layout value="cards"> Cards</label>
<label><input type="radio" bind=layout value="list"> List</label>
</div>
<!-- /tour:switch -->
<let rows edge query Guest_Entry where room == room order by number desc after :before limit 12>
<if rows>
<ol class=(if layout == "list" then "notes list" else "notes")>
<for e in rows>
<li class="note">
<i>#<output e.number></i>
<b><output e.name></b>
<p><output e.message></p>
</li>
</for>
</ol>
<else>
<p class="quiet">Nothing on the wall for this room yet. <a href=("/rooms/" + room)>Write the first entry</a>.</p>
</if>
<div class="pager">
<if (before < 1000000000)>
<a class="btn ghost sm" href=("/wall?room=" + room) region="wall">Newest</a>
</if>
<if rows.count == 12>
<a class="btn ghost sm" href=("/wall?room=" + room + "&before=" + rows[11].number) region="wall">Older →</a>
</if>
</div>
</let>
</region>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.
// The page's parameters, from its query string (?room=garden&before=12): what the edge reads.
Wall_Query :: struct {
room := "lobby";
before := 1_000_000_000; // (entries numbered below this one: the page after)
layout := "cards"; // (cards or a list: a state variable of the edge page, bound by its switch, drawn in the browser)
}
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.
<region id="census" transition="rise">
<loading>
<div class="census waiting">
<span class="skeleton-row"></span>
<span class="skeleton-row"></span>
<Busy label="Counting the guestbooks…" />
</div>
</loading>
<let c Site.census()>
<table class="census">
<thead>
<tr>
<th>Room</th>
<th>Entries</th>
</tr>
</thead>
<tbody>
<for r in c.rooms>
<tr>
<td><a href=("/rooms/" + r.id)><output r.title></a></td>
<td class="n"><output number(r.entries)></td>
</tr>
</for>
</tbody>
</table>
<p class="small muted">Counted after a <output c.waited> ms pause: <output c.total> <output plural(c.total, "entry", "entries")> in all.</p>
</let>
</region>census :: () -> (census: Census = .{}) {
sleep(900);
rooms := Wall.rooms();
total := 0;
for rooms total += it.entries;
return .{rooms, total, 900};
} @Call @Async
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").
Rooms :: struct {
At :: struct { room: string; } // (the mount's :room)
// Before every call and action of the entry, and its first render: which room.
enter :: (p: At) -> (done: Motus_Done = .{}) {
if p.room == "main" return .{redirect = "/rooms/lobby"};
for ROOMS if it.id == p.room return .{};
return .{error = tprint("There is no room '%'. Try the lobby.", p.room)};
} @Enter @Async
Here :: struct {
id: string;
title: string;
about: string;
others: [] Room_Def;
me: string; // (the guest's name: "" a visitor)
}
here :: () -> (here: Here = .{}) {
here: Here;
id := motus_mounted(At).room;
others: [..] Room_Def;
others.allocator = temp;
for ROOMS {
if it.id == id { here.id, here.title, here.about = it.id, it.title, it.about; }
else array_add(*others, it);
}
here.others = others;
if signed_in() {
who := profile();
if who.rows.count here.me = who.rows[0].name;
}
return here;
} @Call @Async
// A guest account (its own tenant: its owner holds guestbook.write), signed in at once; then the room
// again (the page as it is now: the form to sign).
join :: (p: struct { name: string; @Required @MaxLength(32) }) -> (done: Motus_Done = .{}) {
secret := random_token();
made := sign_up(tprint("guest-%@motus-site.invalid", slice(secret, 0, 20)), secret, trim(p.name), tenant_name = tprint("% (a guest)", trim(p.name)));
if made.status return .{error = made.error};
return .{redirect = tprint("/rooms/%?_n=%", motus_mounted(At).room, url_encode(tprint("Welcome, %. Sign away.", trim(p.name))))};
} @Action @Async
leave :: () -> (done: Motus_Done = .{}) {
gone := sign_out();
return .{redirect = tprint("/rooms/%", motus_mounted(At).room)};
} @Action @Async
}
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.
routes :: () {
get("/visitor", visitor_id);
formats(accept = .FORM, respond = .HTML);
if !same_origin() { error(403, "cross-site form submission refused"); return; }
motus_mount("/rooms/:room", TEMPLATE_views_rooms, .[Rooms, Guestbook], TEMPLATE_views_layout);
motus_mount("/wall", TEMPLATE_views_wall, .[Wall], TEMPLATE_views_layout, models = .[type_info(Guest_Entry)], params = Wall_Query); // (its rows fetched at the edge: made in two places)
motus_mount("/", TEMPLATE_views_site, .[Site, Play], TEMPLATE_views_layout); // (last: every other path is its)
} @Handler @Durable(Memory)
routes :: () {
get("/seed", seed);
get("/signup", signup_page);
post("/signup", signup);
get("/login", login_page);
post("/login", login);
post("/logout", logout);
get("/me", me);
if begins_with(router().remaining, "/team/") && context.pass.request.method == "POST" { router().remaining = slice(router().remaining, 5, router().remaining.count - 5); team(); return; }
post("/restock", restock);
post("/orders/refund", refund);
get("/", home);
motus_mount("/parts", TEMPLATE_views_parts, .[Catalog], TEMPLATE_views_shell, models = .[type_info(Part)], params = Parts_Query);
motus_mount("/orders", TEMPLATE_views_orders, .[Catalog], TEMPLATE_views_shell, models = .[type_info(Order), type_info(Order_Line)], params = Orders_Query);
} @Handler
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.