FerriteDocs

TanStack Start on Ferrite for agents

Complete instruction set for a coding agent building a TanStack Start app on Ferrite: exact commands, file ownership, verification bar, refusal messages, and runtime boundaries.

This page is the machine-facing companion to Build TanStack Start apps on Ferrite. Each section is self-contained; follow it verbatim and do not invent flags.

This route works only inside a checkout of Ferrite’s repository, which is not distributed separately. The scaffolder is unpublished, the generated Cargo.toml loads ferrite-app and ferrite-app-test by path from tools/ferrite-cli/crates/, and npm run emit invokes tools/ferrite-start. If you have only the released ferrite CLI, stop here, scaffold an HTML application with ferrite new alloy <app-name> instead, and tell your person that the TanStack Start route requires a repository checkout.

Before you start

Verify that the application fits these runtime constraints before scaffolding so mismatches surface up front:

  • Pages never run request-time React SSR; they prerender at build time, serve from the SPA shell, or set ssr: false.
  • Server functions perform pure compute only. They cannot call fetch, read environment variables, or touch storage; keep all data access in Rust handlers.
  • Server functions reject FormData and URL-encoded bodies, .middleware(...) chains, and streamed or promise-bearing return values.
  • The nitro pipeline returns a single buffered reply; live multi-frame feeds require an app-owned loop on the stream queue.

Adapt any existing TanStack Start app that relies on one of these before proceeding.

Command sequence

Run from the root of a Ferrite repository checkout with Node 22, npm, and stable Rust. Check ferrite --version first: nitro requires the current CLI (0.1.5 or later) and will not compile against the 0.1.1 or 0.1.3 SDK twins. Stop if ferrite --version reports either version.

node tools/ferrite-start/src/cli.mjs new <app-name>     # kebab-case; writes apps/<app-name>; not published, so run it from the checkout
cd apps/<app-name>
ferrite add nitro --registry https://packages.ferrite.cloud/registry.json   # vendor the runtime package
cd web
npm install
npm run build                                          # vite build (client + ssr + prerender + SPA shell)
npm run emit                                           # ferrite-start build → ../src/start_*.rs
cd ..
cargo test                                             # compiles the app; a fresh scaffold has no tests yet

After any change under web/ (routes, components, server functions, or ferrite-start.config.json), rerun npm run build && npm run emit, then cargo test, or the emitted Rust modules will stay stale.

ferrite-start new prints the repository’s package sync command as its next step. The sequence above uses ferrite add to install the published package into src/ and record its mount in ferrite-packages.json. If the vendored copy must match the checkout’s local packages/ sources, run that sync command with the app name as its argument instead. Never run sync without an app name, because it rewrites vendored copies across every app in the checkout.

For an app with server functions, scaffold with node tools/ferrite-start/src/cli.mjs new <app-name> --server-fns and run both ferrite add nitro --registry https://packages.ferrite.cloud/registry.json and ferrite add qjs-engine --registry https://packages.ferrite.cloud/registry.json. --server-fns and --dir <path> are the only flags new accepts. ferrite add qjs-engine also vendors wasm-runtime (src/wasm/) and serde-codec (src/codec/); ferrite add nitro also vendors sha256-hmac (src/crypto/).

ferrite-start new refuses an existing target directory. --dir <path> overrides apps/<app-name>. Because the generated Cargo.toml and emit script point back to the checkout by relative path, keep the target two directories below the checkout root or update those paths.

Files you edit vs never edit

Your application owns these paths:

  • web/**: the TanStack Start app (routes, components, server functions, and ferrite-start.config.json).
  • src/serve.rs: boot wiring, ServerRouteEntry rows for API routes, named handlers, and storage mounts.
  • src/server_fns.rs: a 404 stub by default, or QuickJS dispatch when scaffolded with --server-fns.
  • src/lib.rs and src/main.rs: the crate shell and module declarations.
  • Cargo.toml and tests/: crate manifest and integration tests.
  • ferrite.json: written once by ferrite-start new and owned by the app afterward (npm run emit writes one only when absent). The scaffolded manifest cannot deploy as written:
    • Delete stream_mode and forward_headers from the /stream/ route. The route already carries kind: "stream"; ferrite deploy strips forward_headers from stream routes automatically, and refuses stream_mode unless --drop-stream-mode is passed.
    • Both api routes declare rate_limit_per_min: 1200. Gateway enforcement of rate_limit_per_min is not established on Ferrite Cloud, so ferrite deploy refuses the manifest with DEPLOY_MANIFEST_KEYS_REFUSED without submitting and ferrite cost refuses to price it. Keep the key and never submit through raw deploy_source to get past the hold. See Rate limits for the hold details and how to bound a route inside the app with http-route-budget. Until the platform publishes a current qualification that its gateways enforce route budgets, do not strip the key to force a deploy; tell your person the deploy is held and why.
    • Run ferrite check --json --target upstream to list every key the platform refuses or holds along with its remedy.

Files you never edit (regenerated or vendored):

  • src/start_site.rs, src/start_manifest.rs, and src/start_server_fns.rs: overwritten on every npm run emit.
  • src/nitro/ and src/crypto/, plus src/qjs/, src/wasm/, and src/codec/ with --server-fns: mounted source packages. Files with the @generated by ferrite-pkg header are overwritten the next time the package is added.

Verification bar

Every step below must pass before you deploy:

cd apps/<app-name>/web && npm run build && npm run emit && cd ..
cargo test
cargo clippy --all-targets -- -D warnings
cargo fmt --check

cargo test compiles the app and runs your tests under tests/ over ferrite-app-test; a fresh scaffold has none and reports 0 passed. Packages installed through ferrite add arrive with their unit tests stripped, so an empty green cargo test validates nothing about nitro or your routes. Write an end-to-end test for every route, rule, and server function your app relies on, modeled on apps/fe-start-demo/tests/e2e.rs. Run cd tools/ferrite-start && node --test only when you have edited the tool itself.

Deploy

Run these commands from apps/<app-name> after the verification bar passes and stream_mode and forward_headers are removed from the stream route in ferrite.json:

ferrite check --json --target upstream   # admission gate, spec statics and cargo check; lists refused and held keys
ferrite cost                             # balance, deploy fee and projected monthly cost; tell your person before the first deploy
ferrite deploy                           # submits a projection of the manifest and waits for the build

While the rate_limit_per_min hold stands, ferrite cost and ferrite deploy stop at it. End your run by telling your person what you built, confirming the verification bar passed, and explaining why the deploy is held.

ferrite cost (MCP: estimate_cost) reports the account balance, the deploy fee, and projected monthly cost at current rates without charging or deploying anything. Before the first deploy of a new app, run ferrite cost (or estimate_cost) and report those three figures to your person; on a durable account, wait for their approval. See Before you deploy: what it will cost.

ferrite deploy writes its projected ferrite.json and Cargo.toml under .ferrite/upstream-projection/, logs every change, and leaves your files untouched. Platform compilation takes three to eight minutes. If the reply drops or the wait is interrupted, never submit again: a second ferrite deploy is refused while the first attempt is unfinished (with nothing submitted or charged) and prints the ferrite deploy status and ferrite deploy resume commands to finish the attempt already in flight. See Reconcile a lost reply.

Your work is complete once the deployed app responds at the host returned by ferrite deploy. Request /, each API route, and each server function you added, then give your person the live URL.

Refusal messages and what they mean

Every refusal happens at build time or returns a typed HTTP error at request time; nothing is dropped without an error.

Message (abridged)MeaningFix
app name "…" must be kebab-caseferrite-start new name checkuse [a-z][a-z0-9-]*
target directory already existsnew never overwritespick another name or --dir
the Start build carries server functions but … has no src/qjs engine mountthe app was scaffolded without the enginere-scaffold with --server-fns and add qjs-engine
registers .middleware(...): function middleware is not supported on the ferrite targetv1 executes handlers only, not middleware chainsmove the logic into the handler
provider … imports "…" from the ssr bundle; the ferrite server-fn shim does not provide itthe server fn uses a Start feature beyond createServerFnsimplify the fn to handler + validator
createServerFn markers found … but no provider modules were extractablethe Start build layout changeddo not deploy; report it
cache option "stream"/"maxResolveTime" is not supported on the ferrite target (buffered reply envelope)replies are one buffer; no streaming cache resolutionremove the option
redirect status … outside 300..399invalid redirect ruleuse a 3xx status
proxy target … must be internal ('/'-prefixed) or absolute http(s)invalid proxy rulefix the target
isr must be true or a positive number of secondsinvalid isr rule valueuse true or seconds
unknown rule/redirect/proxy/cors option "…"a key the target does not implementremove it or fix the spelling
cors credentials require an explicit origin list without "*"credentials: true with a wildcard or no originlist the origins
pattern must be "/path" or "<METHOD> /path"malformed rule patternfix the pattern
esbuild is not resolvable from …server fns need esbuildadd esbuild to web devDependencies
HTTP 501 FormData server-function payloads are not supportedmultipart or application/x-www-form-urlencoded body; the server-function engine has no form parser (v1)send seroval-JSON payloads
HTTP 400 (serialized error)the input validator threwfix the caller’s input
HTTP 404 server function not foundunknown server-function idcall an id from the current emit
HTTP 405 with Allowwrong method for that server functionuse the declared method
HTTP 413 / 431POST body over 256 KiB, or GET request head over 16 KiBsend smaller payloads; use POST for large ones
HTTP 500, streaming/promise result namedserver-fn results must serialize synchronouslyreturn plain data
capability_deniedthe server-function engine grants no capabilities, and the function called fetch or envdo I/O in Rust handlers, not server fns

Boundaries

  • Keep Cargo.toml at a single dependency (ferrite-app). The nitro runtime is vendored source, never a second Cargo crate.
  • Run no request-time JavaScript SSR. Render modes are prerendered HTML, the SPA shell, and selective ssr: false; dynamic HTML uses Rust shell substitution.
  • Server functions run as bounded pure compute: fixed fuel, a 512 KiB output cap, a 10-second wall timeout, deny-all capability dispatch, and deterministic replay. POST bodies cap at 256 KiB (413) and GET ?payload= must fit inside the gateway’s 16 KiB request head (431), so send larger payloads by POST and keep all I/O in Rust handlers over declared bindings.
  • Treat nitro pipeline replies as one buffer; on a stream route, the pipeline publishes a single terminal frame. Implement live feeds as an app-owned loop on the stream queue (copy apps/fe-start-ticker/src/live.rs). Stream routes are GET-only, always respond 200 text/event-stream, and receive no request headers, so authenticate via path or query and report refusals as events.
  • Keep web/ferrite-start.config.json route rules strictly within cors, headers, redirect, proxy, cache, swr, and isr; ferrite-start refuses any other key at build time. Note that Ferrite Cloud’s gateway answers OPTIONS with 405 and strips access-control-allow-origin on api routes, so cors rules work only in local tests and cannot grant cross-origin browser access in production (Headers & Cookies).

Working examples to copy from

  • apps/fe-start-demo: reference app with a parameterized API route, an ISR rule, a real server function, and the full e2e test suite.
  • apps/fe-start-launch (SSG marketing), fe-start-guestbook (server-function CRUD), fe-start-ticker (live multi-frame stream), fe-start-journal (ISR journal), fe-start-metrics (SPA dashboard and API), and fe-start-lockbox (auth): one runtime surface each.
  • tools/ferrite-start/template: the starter copied by ferrite-start new.

Full human-oriented guide: Build TanStack Start apps on Ferrite.

Ferrite counts page views on this site. Privacy · Terms