Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HTML over the wire with Maud, Tailwind v4, Basecoat, HTMX, and Alpine

Slabs renders HTML directly in Rust without Node.js, npm, webpack, Vite, or a separate client-side single-page application layer. Every browser library in the stack is MIT-licensed and embedded directly into the slabs-http binary.

Why zero Node and zero JSON state duplication

Splitting a web app into a Rust JSON backend plus a React or TypeScript frontend doubles every change. You maintain duplicate types, duplicate validation, client-side routing, cache invalidation, and a Node build pipeline.

In Slabs, the server owns the database, validation, authorization, and HTML rendering in one file. When an agent writes a slab, rustc type-checks the SQL parameters, Rust variables, and Maud HTML markup in the same compilation unit.

How the five frontend pieces fit together

  1. Maud (maud! macro in slabs-html) compiles HTML templates directly into Rust code that appends to a String. Every interpolated value is HTML-escaped at compile time. PreEscaped is omitted from slabs::prelude::* on purpose so raw HTML requires an explicit slabs::html::PreEscaped import, and untrusted Markdown runs through html::render_markdown(&text).
  2. Tailwind CSS v4 runs as a single standalone native binary via mise with zero node_modules. assets/input.css contains @import "tailwindcss"; and @source "../slabs";, so slabs css scans every slab file and outputs a minified assets/styles/app.css served at a content-hashed /assets/{hash}/styles/app.css URL with Cache-Control: public, max-age=31536000, immutable.
  3. Basecoat UI (/_slabs/vendor/basecoat.min.css and basecoat.min.js) ships shadcn-style CSS tokens (--background, --foreground, --card, --border, --muted, --primary) and semantic HTML classes (.btn, .card, .input, .badge) with no React or Radix dependency.
  4. HTMX 2, SSE, and Idiomorph (/_slabs/vendor/htmx.min.js, htmx-ext-sse.js, idiomorph-ext.min.js) drive partial page updates (hx-get, hx-post, hx-target, hx-push-url), out-of-band updates (htmx::oob, htmx::oob_replace, htmx::oob_delete), live server pushes (sse-connect, sse-swap), and DOM diffing (hx-swap="morph:innerHTML"). html::document enables hx-ext="morph" on <body> and @view-transition { navigation: auto; } in <head>.
  5. Alpine.js 3 (/_slabs/vendor/alpine.min.js) and native HTML elements handle transient browser-only state such as keyboard shortcuts (@keydown.window), dropdown toggles, and copy buttons. Modals and popovers use native <dialog> and the HTML popover attribute instead of custom focus-trap libraries.

Safe JSON embedding and guarded redirects

Two slabs-html helpers prevent common frontend injection and redirect bugs:

  • json_script("boot-data", &payload)? serializes structured data into <script type="application/json" id="boot-data"> and escapes <, >, &, U+2028, and U+2029 so user strings cannot break out of the script tag.
  • htmx::redirect(path) and htmx::flash_redirect(...) verify that path is a safe relative path and fall back to "/" on open-redirect inputs such as //evil.com. Call redirect_external(url) when an endpoint intentionally redirects to another origin.

Progressive rendering with htmx::is_htmx

A single slab can serve both full browser navigations and partial HTMX swaps by checking htmx::is_htmx(&headers):

  • On a normal browser request, return the full html::document(...) shell with sidebar, navigation bar, and article content.
  • On an HTMX click (HX-Request: true with hx-target="#doc-article" and hx-push-url="true"), return only the <article> fragment plus an htmx::oob_replace for the sidebar active link or document <title>.

Direct URLs, browser back/forward buttons, and search engine crawlers work cleanly because every link is a standard <a href="..."> upgraded with hx-get.

Serving AI agents alongside browsers

Because routes return typed responses from self-contained slabs, exposing plain Markdown (/raw/{section}/{slug}) or /llms.txt alongside HTML pages takes a small sibling slab reading the same SQLite tables with zero client-side JavaScript overhead.