Roc Solid
Markup in Roc · pages on a native server · components in WebAssembly

Tooling

A few commands, and the compiler you already have

rocx turns markup into Roc, builds and serves your app as you edit, and points the Roc compiler's reports at your .rocx lines. It is written in Roc, and lives in ~/.rocx/bin once installed, or at bin/rocx in a clone of the repository.

Commands#

dir is an app's folder (the one with routes/), the current one by default. rocx or rocx --help lists the commands; rocx help build or rocx build --help shows one command's options. At a terminal, each build step shows a ✓ and its time; in a pipe, in CI or with NO_COLOR set, the output is plain text.

rocx new [dir]--db sqlite|postgres|turso

Makes an app from rocx's template in dir, which must be empty or new (asked for at a terminal). People sign in with the auth package (an email link; Google and GitHub once their keys are set; any address under rocx dev; two-factor for those who turn it on), into the app's own users table. Other sites' posts are refused, guard's security headers are on, and sign-in mail is rate limited. The database is SQLite unless you pick another (it asks at a terminal). .rocx-version names the app's rocx version (commit it); .rocx is the link the app's header reaches the platform and packages through (gitignore it). From a clone of the repository, .rocx links to the clone and there is no .rocx-version. It also writes AGENTS.md and CLAUDE.md (rocx agents). The app's README.md says what to change first.

rocx dev [dir]--port 8080--opt dev|size|speed--android [--lan]-- <server options>

Serves the app at http://localhost:8080 in development mode. Each save rebuilds it, restarts the server and reloads open pages. A failing build's errors show at their .rocx lines while the last good build keeps running. The first run writes the smallest main.roc if there is none. Each start also checks the app's SQL (rocx check --sql). At a terminal it opens with the app's address and database, and the server lists the places to open under it (the stories, the mailbox, the sign-in page, the OpenAPI page).

The port is --port, else PORT, else 8080. Options after -- go to the server (--database-url postgres://…), which also reads its environment (DATABASE_URL). A .env in the folder you run it in (SMTP_URL=… lines) goes to the server and its SQL check as --env-file .env; the environment wins. Development mode adds the stories (/__rocx/stories), plugins' development pages (the email package's mailbox) and crash messages in 500 answers.

Builds use Roc's fast-compiling development backend (--opt dev: seconds). --opt size or --opt speed builds both programs as a release does, to try what ships.

--android also builds for Android: it installs a development client on an emulator or a USB-connected phone, and reloads it on each save. --lan also serves the app on your network and prints a QR code for a phone on the same Wi-Fi. This needs the Android SDK and NDK; the pomodoro example runs this way.

rocx build [dir]--out dist--target arm64musl--opt speed|size|dev

Builds the app to deploy: dist/server, optimized for speed, and dist/static, the app's static/ and the browser's files (wasm optimized for size). Run dist/server --static dist/static behind a TLS proxy (Caddy, say). --target is arm64mac, x64mac, or arm64musl or x64musl (static Linux executables for a container). --opt builds both programs at one level. The server has only the database engine the program names (SQLite if none); a Linux build has no debug info. The build replaces dist (or --out) only when complete; that folder must be empty or an earlier build (with a server).

rocx build [dir] --image--out <name>.tar--tag name:tag

The release as a container image, which rocx writes itself: no Dockerfile, no Docker. The server is a static Linux executable with its TLS roots inside, so the image has no base and one layer: /app/server, /app/static, a user to run as (65532), /tmp, and /app/data for a volume (a SQLite app's data/app.db). It runs in /app on PORT 8080. The output is an OCI image tar, <name>.tar after the app's folder (or --out), for docker load -i or podman. --tag defaults to the folder's name, :latest; --target is arm64musl or x64musl (default: this machine's processor). --opt works as above. Settings are environment variables (docker run -e PUBLIC_URL=…).

rocx build [dir] --static--out dist--base /path/--route <path>--built <build>-- <server options>

Writes the app as static files into dist/ (or --out) for a host with no server: GitHub Pages, a CDN, any web server. It builds for production, runs the server on a free port, and saves /, every page whose path has no params, and every page they link to, each as <path>/index.html. Beside them go 404.html (for paths nothing answers), the app's static/, and rocx/ (the runtime and the wasm). Each page carries the answers to its reads, so its data needs no server. This site is built this way.

--base puts every URL under a path (--base /docs/ for example.github.io/docs/). --route adds a path no page links to: a page with params (/blog/hello) or an endpoint's answer as a file (/feed.xml). --built uses a build you made (its server and client/static). The copy replaces its folder only when complete; the folder must be empty or an earlier copy.

The build lists what only a server can answer, which the copy leaves out: methods that write (post!), events and channels, pages behind a directory's middleware (it runs per request), pages with params no link or --route reached, and links to paths that answered an error.

rocx generate [dir]…--client <out>--dev

Only the code generation rocx build and rocx dev start with, for editors and scripts. Each .rocx file under the folders becomes a .roc file beside it, its markup as calls to the platform's Html. For an app it also writes Generated/: Routes.roc (the router), Paths.roc (typed links), Api.roc and Handlers.roc (the endpoints' contract and handlers), Styles.roc (the stylesheet), App.roc (which main.roc completes), Root.roc for an app with pages (the page at the browser's path, in its layouts), and route files' own Roc. Packages' components are copied into Generated/<package>/, and each folder under content/ becomes Generated/Content/<Name>.roc, listing its Markdown files.

--client also writes the browser's copy of the app into <out>: endpoints without their handlers (method, URL and types kept), <NoHydration>s without children, and only the imports still used. For an app with pages, it adds the browser's main.roc and static/rocx/: start.js, the runtime, and the stylesheet named by its content (styles-hash.css). The runtime is minified (about half the size with brotli), except in a --dev build. A build to deploy (rocx build, with or without --image or --static) ships only the runtime code the app's wasm and pages reach: in-place navigation only for an app of several pages (or one that navigates), and drags, pointer positions and glides only where its markup has them. An app of endpoints alone has no browser program, and the build says so. When the browser's copy reaches a module that imports something server-only (pf.Db, directly or not), the build warns at the page's or component's import, before the browser's build fails far from it.

--dev also builds the stories and their catalog.

rocx check [dir]

Builds the app from its sources (never an older build's files) as rocx dev does, then type-checks the server's program and, for an app with pages, the browser's. Each problem shows at its .rocx line. Exits 0 when clean, 1 on an error, 2 on warnings only, rocx's own included: a match arm's value or a list row's item given to a component that reads it once (if, match and .map). Needs a main.roc. Run it in CI.

rocx test [dir]

Builds the app as rocx check does, then runs its expects with rocx's compiler, each failure at its .rocx line. Exits 1 if one fails.

rocx check -- <command>

Runs a command (roc check, roc build, just check) and points the compiler reports it prints at the .rocx files (errors at your lines). Exits with the command's code.

rocx check --sql [dir]--engine sqlite|turso--verbose-- <server options>

Checks the app's SQL with its own database engine, and its row types with the compiler. Each string statement at a Db.all!, Db.one! or Db.run! is prepared on a scratch database built from the migrations: a temporary file for SQLite or Turso, or a database created, then dropped, on the Postgres server --database-url (or DATABASE_URL) names. It reports SQL the engine refuses, parameters that don't match their statement and row types that don't fit, at their lines, and exits 1 (how it works).

--engine checks a SQLite app on Turso, or a Turso app on SQLite. --verbose also lists the calls it couldn't check, such as SQL built at run time. It reads no .env by itself: -- --env-file .env gives it one.

rocx lint [--pairs warn|error|off] <dir>…

Refuses Html.source_text in hand-written .roc files under the folders: it puts any string in a page as markup (why). Mentions in comments or strings don't count. Exits 1 if a file calls it. It also warns of a folder under routes/ with both a page and an endpoint, saying where the endpoint goes under routes/api/ (a path is one or the other): --pairs error fails on it, --pairs off says nothing.

rocx routes [dir]--server--client

Lists an app's routes: each method and path, and the middleware around it, outermost first (what runs, in what order). --server lists only the endpoints; --client only the pages (the error page too).

rocx fmt <path>…--check

Formats the Roc in each .rocx file, and each .roc file rocx didn't write, under the paths, with roc fmt: rocx's compiler (an installed version's, a clone's .tools/roc-active, else the one ROC names), else the roc on your PATH. Markup and the Roc in its holes stay as written: markup moves only with the code around it, and <pre> or <textarea> text never moves. --check lists unformatted files, and exits 1 if there are any.

rocx render <url>-o out.mp4-o out.webm-o frames/--player n|label--scale 2--from n --to n--crf 18

Films the video on the page at url (the video package's <Player>) a frame at a time in Chromium's headless shell. Each frame is the same however long it took to draw, so two renders are the same. ffmpeg writes .mp4 (H.264) and .webm (VP9); a folder (ending in /) gets the frames as PNGs. Without -o, it writes video.mp4.

--player picks the page's player by its index from 0 or its aria-label (the first by default). --scale is device pixels to a CSS pixel (2: a 1280-wide video is 2560). --from and --to film a stretch, by frame. --crf is H.264's quality (lower is better and bigger). Chromium is $CHROME, else Playwright's headless shell; ffmpeg is $FFMPEG, the one on your PATH, or Nix's. The stories' catalog copies this command for a story.

rocx qr <text>--pbm

Prints the text as a QR code in the terminal (as rocx dev --android --lan does), or as a PBM image with --pbm. A code holds at most 2,331 bytes.

rocx upgrade [version]

Installs rocx (the latest, or the version you name) into ~/.rocx as the default. In an app, it also moves the app's .rocx-version and .rocx link to it. Every command on an app runs the version the app names, installing it if needed, so a team shares one version through the repository. A rocx from Nix leaves upgrading to Nix.

rocx agents [dir]--force

Writes rocx's rules for coding agents into the app's AGENTS.md, as a block between two markers, and a CLAUDE.md that imports it if there is none. The block points at .rocx/agents/guide.md, the guide for the app's rocx version. Run it again after an upgrade: it rewrites only the block, so the app's own notes stay. It refuses an edited block without --force. rocx check says when the block is from another version. rocx new writes both files.

rocx help [command]

The commands, or one command's usage and options (rocx <command> --help too).

rocx --version

Which rocx this is (an installed version's number, or a clone's commit), then the Roc compiler it runs and where it is.

Code generation (rocx generate, and the first step of rocx dev, rocx check and rocx build) writes a file only when its content changes, so watchers don't loop. It deletes the .roc files it wrote whose .rocx file is gone, and stops at the first markup problem, with its line and column. Generated files end with a # rocx: generated from … line. Keep them out of version control: ignore Generated/, build/ and the .roc files beside your .rocx files.

rocx routes on the hello example:

$ rocx routes examples/hello
METHOD  PATH    MIDDLEWARE (outermost first)
GET     /       -
GET     /hello  -

Errors at your lines#

Markup mistakes (an unclosed tag, an attribute rocx refuses) are rocx's: it reports each at its line and column, with a caret, and stops. The rest are the Roc compiler's. Line N of a generated file is line N of yours, so its reports already name your line. rocx check and rocx dev also rewrite the location, quote your line, and move the caret onto your code. A route file's Roc (+server.roc) is reported at its lines too.

A file with a type mistake:

Posts.rocx
import pf.Html

Posts := [].{
	view : List(Str) -> Html
	view = |posts|
		<p class="count" title={posts.len()}>
			You have {posts.len()} posts
		</p>
}

and what rocx check -- roc check Posts.roc printed for it when this page was built:

The compiler, through rocx check
── ✗ type mismatch ────────────────────────────────────────────── Posts.rocx:6:27

The second argument being passed to this function has the wrong type.

<p class="count" title={posts.len()}>
                        ^^^^^^^^^^^

This argument has the type:

    U64

But the function needs the second argument to be:

    Str

Hint: Convert it to a Str with .to_str().

── 1 error and 0 warnings ──────────────────────────────────────────── Posts.roc

In an editor#

The repository's editors/ folder has a grammar for .rocx files. It colours Roc (by the official Roc grammar), markup (tags, a component's tag as a type, attributes like class:active and on:click.prevent), the Roc in holes and markup inside it, and CSS in a <style>. Its one guess: a < before a letter starts markup, unless a value comes right before it. So a <b (a comparison with a space before < and none after) is coloured as markup.

VS Code: just vscode-extension installs the extension for every workspace (it needs code on your PATH, and Node). Besides highlighting, it adds a task type: Terminal → Run Task… → rocx lists dev (runs rocx dev in its own terminal) and check (runs rocx check once) for each app. Their reports show at the .rocx line and in the Problems panel until the next run. A task of your own in .vscode/tasks.json runs any command the same way ({ "type": "rocx", "command": "just check" }). There is no language server yet: the editor shows what the build reports.

Orca: just orca-plugin installs a plugin that highlights .rocx and .roc files. It runs nothing, so it needs no access. Orca plugins can't show errors: use rocx check.

Stories#

A component's stories are the ways it looks, written beside it, as in Storybook. Each <story name="…"> among the component's definitions holds one story's markup. rocx makes each a definition (story_tip! for <story name="Tip">), so every build checks it against the component. Only a development build has them: rocx dev serves a catalog at /__rocx/stories (rocx generate --dev writes them into the code).

site/Ui/Callout.rocx
import pf.Html

## A note beside the text: `tip`, `note` or `warning`.
Callout := [].{
	view : { kind : Str, title : Str, children : List(Html) } -> Html
	view = |{ kind, title, children }|
		<aside class={"callout callout-${kind}"}>
			<p class="callout-title">{title}</p>
			{...children}
		</aside>

	<story name="Tip">
		<Callout kind="tip" title="Name holes by what they hold">
			<p>A hole shows text, a number or markup, by its type, and <code>{"{...}"}</code> a list of markup.</p>
		</Callout>
	</story>

	<story name="Note">
		<Callout kind="note" title="Lines stay lines">
			<p>Line N of the Roc rocx writes is line N of the <code>.rocx</code> file.</p>
		</Callout>
	</story>

	<story name="Warning">
		<Callout kind="warning" title="Never build markup from strings">
			<p>Text is escaped wherever it goes; a string never becomes a tag.</p>
		</Callout>
	</story>

	<story name="Long">
		<Callout kind="note" title="A callout with more in it">
			<p>
				It takes any children: paragraphs, lists and code. Text wraps at the callout's width, and the
				title stays one line above it.
			</p>
			<ul>
				<li>a paragraph</li>
				<li>a list</li>
				<li>a line of <code>code</code></li>
			</ul>
		</Callout>
	</story>

	<style>
		.callout {
			max-width: var(--measure);
			margin: var(--space-6) 0;
			padding: var(--space-4) var(--space-5);
			border-radius: var(--radius);
			background: var(--accent-soft);
			box-shadow: inset 3px 0 0 var(--accent);
		}

		.callout-warning {
			background: var(--warn-soft);
			box-shadow: inset 3px 0 0 var(--warn);
		}

		.callout-tip {
			background: var(--good-soft);
			box-shadow: inset 3px 0 0 var(--good);
		}

		.callout-title {
			margin: 0 0 var(--space-1);
			font-weight: 700;
		}

		.callout-note .callout-title {
			color: var(--accent);
		}

		.callout-warning .callout-title {
			color: var(--warn);
		}

		.callout-tip .callout-title {
			color: var(--good);
		}

		/* What is inside is the page's: global, under the callout. */
		.callout > :global(p) {
			margin: var(--space-2) 0;
		}

		.callout > :global(ul) {
			margin: var(--space-2) 0;
			padding-left: var(--space-5);
		}

		.callout > :global(:last-child) {
			margin-bottom: 0;
		}
	</style>
}

The catalog lists every story in a sidebar:

Each story is the app's page at its own path (/__rocx/stories/…), rendered in the root layout and hydrated, so it works as in the app. A layout can tell a story by its path (this site shows one with nothing around it). An app with no pages can't show stories, so they are an error there.

An app's stories/ folder holds modules of stories only: drafts, each a component with its own <style>, side by side in the catalog. Only a development build compiles it, so none of it is published, styles included. This site's site/stories/Landing.rocx has the front page as it is, and drafts of it in six themes.

Building an app yourself#

An app is two programs (the platform): the server's, native code in a Rust host, and the browser's, the same pages in WebAssembly. rocx dev builds both (getting started); rocx build builds them to ship (below). The server's program, Generated/App.roc, is rocx's: every request goes through the app's middleware (routes/+middleware.roc) to the router, where every URL is a file. The app's main.roc says only what rocx can't know:

main.roc
app [program] { pf: platform "./.rocx/server/platform/main.roc" }

import Generated/App

program = App.program({
	init!: |_started| Ok({}),
})

rocx writes the browser's program too (rocx generate --client): its root is the page at the browser's path, which the browser hydrates. This site's:

site/build/client/main.roc
## The browser's app, written by rocx build --client from site: the app's page (`Generated/Root`),
## which the browser hydrates (web/start.js), on the web platform. Don't edit it.
app [main!] { admin: "../../../packages/admin/browser.roc", audio: "../../../packages/audio/browser.roc", charts: "../../../packages/charts/main.roc", forms: "../../../packages/forms/main.roc", guard: "../../../packages/guard/browser.roc", intl: "../../../packages/intl/main.roc", markdown: "../../../packages/markdown/main.roc", mcp: "../../../packages/mcp/browser.roc", presence: "../../../packages/presence/browser.roc", push: "../../../packages/push/browser.roc", qr: "../../../packages/qr/main.roc", testing: "../../../packages/testing/main.roc", tools: "../../../packages/tools/main.roc", video: "../../../packages/video/main.roc", virtual: "../../../packages/virtual/main.roc", pf: platform "../../../web/platform/main.roc" }

import pf.Html
import Generated/Root

main! : {} => Html
main! = |{}| Root.view!({})

# rocx: generated from the routes: rocx build --client writes it.

For a release, rocx build compiles the browser's wasm with --opt=size --specialize=yes (and again with --specialize=no if the compiler crashes on it), and the server's program and host into one executable with --opt=speed, with what it serves beside it. Its --target works from a Mac too (deploying). The executable takes its port, database and the rest as flags or environment variables (running it).

rocx build --target arm64musl
dist/server --port 8080 --static dist/static

The server is built with boxy lowering (--specialize=no) by default. With Roc's default, lambda-set specialization, the function that renders pages gets a stack frame that grows with the app, and a large app's could outgrow its stack. Boxy lowering renders about as fast and builds much faster; ROCX_SPECIALIZE=yes opts back in. Specializing the browser's wasm makes it smaller with brotli, and faster.

Both platforms have requests, routes, endpoints, events and middleware (pf.Server, pf.Endpoint, pf.Middleware, pf.Events, pf.OpenApi) and the modules components are written with, so a component compiles on both. The database, the key-value store, channels, live rooms and actors are the server platform's alone; jobs, cron and email are packages for it (the ecosystem).

This repository#

WhereWhat
rocx-cli/rocx, in Roc: the transpiler and every command (just dev's loop too), built into bin/rocx
cli/the command-line platform rocx is built on (a Rust host): files, commands, a watched directory tree, signals, a WebSocket, and one wait for whichever comes first
agents/rocx's rules for coding agents: the block rocx agents writes into an app's AGENTS.md, and the guide it points at
web/the browser's platform: its Roc modules (with those both platforms share: components', requests, endpoints, events, middleware), the Rust host (built for wasm32), and the JavaScript runtime
server/the server's platform: its Roc modules, the Rust host, and the build
packages/, examples/the ecosystem's packages, and complete example apps
site/this site, in rocx (pages in routes/): just dev serves it as you edit, site/build.mjs (just site) builds it static
templates/the app rocx new copies, and its tests
release/a release of rocx: what is built per target, the archives, the install script and its test
editors/the .rocx grammar, the VS Code extension and the Orca plugin
test/, web/test/, site/test/, server/test/the transpiler and CLI, the browser's platform, the site in a real browser, the server's platform

To work on Roc Solid itself, clone the repository and run just setup. It uses your system's Zig 0.17.1 and Rust 1.85 or newer (from Nix, say), else downloads them into .tools/, and adds Rust's wasm32-unknown-unknown target (for the browser's host) with rustup. Roc is a fork of Roc's main, at a pinned commit, with the compiler fixes Roc Solid needs: just setup builds it from a clone of the fork if there is one, else downloads it prebuilt from the repository's releases (macOS on Apple silicon, Linux on arm64 or x86_64). Scripts use that compiler, never the roc on your PATH. Only the repository's checks and tests, the site's build and the VS Code extension need Node; rocx and your apps don't. CI runs just check, just site, the three parts of just test and just examples on every push to master and every pull request, on GitHub's Linux runners on arm64.

just setup   # the Roc fork, the pinned nightly, Zig and Rust if need be, into .tools/; then bin/rocx
just db      # a Postgres in Docker, for the server platform (prints its DATABASE_URL)
just test    # everything: the transpiler, both platforms, the packages, rocx new's template, the site in Chromium
just check   # formatting, no package copied by hand, lint, and the site's and examples' type checks
just dev     # this site, rendered per request, rebuilt and reloaded on save
just site    # the static site, in site/dist

bin/rocx also has commands for the repository's scripts: rocx site dev and rocx site prepare (this site), rocx self-build (rebuilds bin/rocx when its Roc changed) and rocx internal (the tests' calls into rocx's functions).