All docs

Forte Framework Overview

Forte is a full-stack web framework built on top of fn0. It compiles a Rust backend to WebAssembly (WASI Component Model) and pairs it with a React/TypeScript frontend built by Vite.

Architecture

┌────────────────────────────────────────────┐
│  Request                                   │
└────────────┬───────────────────────────────┘
             │
             ▼
┌────────────────────────────────────────────┐
│  fn0 runtime (Wasmtime)                    │
│  Executes backend.wasm                     │
└────────────┬───────────────────────────────┘
             │
             ▼
┌────────────────────────────────────────────┐
│  route_generated.rs  (auto-generated)      │
│  Routes request to page / action handler   │
└────────────┬───────────────────────────────┘
             │ page request
             ▼
┌────────────────────────────────────────────┐
│  Rust page handler                         │
│  Returns Props (serialized to JSON)        │
│  Sets x-fn0-next: js header                │
└────────────┬───────────────────────────────┘
             │
             ▼
┌────────────────────────────────────────────┐
│  JS runtime (server.js SSR bundle)         │
│  React SSR renders Props → HTML            │
└────────────────────────────────────────────┘

For API endpoints (src/apis/), the Rust handler returns JSON directly — no SSR step.

Key Packages

PackageVersionCratePurpose
forte-sdk0.3.6forte/sdkRuntime library for wasm components (HTTP types, ForteRequest, cookie utilities, metrics, etc.)
forte-cli0.4.2forte/cliDeveloper CLI (forte dev, forte build, forte deploy, etc.)
forte-macros0.5.2forte/macrosProcedural macros: #[forte_sdk::test], #[forte_doc]
forte-json0.1.1forte/jsonStreaming JSON serializer used for Props serialization
forte-codegen0.1.6forte/codegenBuild-script library that generates route_generated.rs
forte-rs-to-ts0.1.9forte/rs-to-tsStandalone binary: Rust → TypeScript type generator (uses private rustc APIs; downloaded automatically)

Project Structure

See project-structure.md for the full layout.

Runtime Constraints

Forte backends run inside a single WASM instance that is reused across many concurrent requests (Cloudflare Workers model):

  • No multi-threading. Use async/await for concurrency. std::thread::spawn and tokio are not available in wasm32-wasip2.
  • Stateless handlers. Module-level mutable state must not carry information between requests — another request may be interleaved at any await point. Module-level initialization runs once; per-request state belongs inside the handler.
  • No std::thread::sleep. Use forte_sdk::time_wasi::sleep instead.

fn0 does not enforce statefulness — violating the stateless constraint causes request-level data leakage.

Handler Types Quick Reference

TypeLocationRouteWhen to use
Pagers/src/pages/GET /<path>Server-renders a React component; returns Props to the SSR step
APIrs/src/apis//api/<path>Returns JSON directly; no React rendering; any HTTP method
Actionrs/src/actions/POST /__forte_action/<name>Mutation or query called from the browser via the generated typed client
Hookrs/src/hooks/POST /__self_invoke/<name>Data fetch called during SSR; result is embedded in the HTML and rehydrated on the client
Queue taskrs/src/queue_task/internalBackground job enqueued with enqueue::<name>(input)
Admin taskrs/src/admin/internalOne-off operation run via forte admin run <name>

See the full handler docs: Pages, API Endpoints, Actions & Tasks.

Workflow Overview

  1. forte init <name> — scaffold a new project
  2. forte dev — run dev server with hot reload
  3. forte add page <path> / forte add action <path> — add handlers
  4. forte build — compile backend (WASM) + frontend (Vite)
  5. forte login — authenticate with fn0 Cloud (required before first deploy)
  6. forte deploy — upload to fn0 Cloud

See cli.md for all commands.