Guide · Pure Julia + WasmGC

Getting Started

Build standalone interactive web apps or full-stack servers in Julia. Render pages on the server with plain functions, add @island wherever you need client interactivity, and ship compact WasmGC modules compiled by WasmTarget.jl.

Installation

Therapy.jl compiles interactive islands with WasmTarget.jl (WasmGC). Install it from the Julia General registry:

using Pkg
Pkg.add("Therapy")

Project Structure

A Therapy.jl app uses file-based routing. Each file in src/routes/ defines a page URL, while files in src/components/ are loaded into the shared app scope so every route can call them directly.

my-app/
app.jl                 # App configuration and entry point
therapy.toml           # Declarative metadata hot-reloaded in dev (optional)
input.css              # Tailwind CSS v4 entry point (optional)
src/
  routes/
    index.jl           # /
    getting-started.jl # /getting-started/
    examples/
      index.jl         # /examples/
  components/
    Layout.jl          # Shared SSR page shell
    Counter.jl         # @island component compiled to WasmGC
LocationRuns whereRole
app.jlJulia hostConfigures routes, layout, static mounts, middleware, and runs dev, run, or build
therapy.tomlDev and buildDeclarative title, favicon, Prism languages, and UI flags reloaded live without restarting Julia
src/routes/*.jlBuild or server (SSR)File-based pages returning VNodes with full access to Julia packages
src/components/*.jlSSR or WasmGCPlain functions stay SSR and @island functions compile to WebAssembly

SSR Components

Components are plain Julia functions that return HTML VNodes. They execute at build time (or on the server) with full access to DataFrames, HTTP, Makie, or any other Julia package. No macro is required and zero JavaScript is shipped.

# src/routes/index.jl
() -> begin
    Div(
        :class => "space-y-4",
        H1("Hello from Julia"),
        P("Pre-rendered on the server with zero client runtime."),
        P("Use any Julia package directly inside SSR components."),
    )
end

Interactive Islands

Mark interactive components with @island. Therapy compiles the island's signals, memos, effects, and event handlers to a compact WasmGC module via WasmTarget.jl. Everything outside an island ships as zero-overhead HTML.

0
doubled 0
# src/components/Counter.jl
@island function Counter(; initial::Int = 0)
    count, set_count = create_signal(initial)
    doubled = create_memo(() -> count() * 2)

    return Div(
        Button(:on_click => () -> set_count(count() - 1), "-"),
        Span(count),
        Button(:on_click => () -> set_count(count() + 1), "+"),
        P("doubled: ", doubled),
    )
end
How @island compiles to WasmGC

With WasmTarget.jl, primitive signals (Int64, Bool, Float64) lower directly to WebAssembly globals, while heap values (String, Vector) compile to native WasmGC struct and array references.

Handlers, memos, and effects compile into typed functions inside a per-island .wasm module. Keep island props concrete (for example initial::Int = 0) and write type-stable Julia so every island remains trim-verifiable.

Reactivity & Control Flow

Therapy pairs SolidJS-style fine-grained reactivity with DOM-level control flow. Show inserts and removes real DOM branches (disposing nested effects automatically), while event handlers are auto-batched so multi-signal writes trigger dependent effects once.

Show + fallback@island

Mounted in the DOM right now

Inspect this element: clicking Toggle removes these nodes and swaps in the fallback branch.

Content is hidden. Click Toggle to restore it.

Rendered via the fallback prop while the condition is false.

Auto-batched updates@island

a=0 b=0

Open the browser console: each click logs one effect, not two.

PrimitivePurpose
create_signal(v)Reactive state stored in WasmGC globals
create_memo(fn)Cached derived computation recomputed only on dependency change
create_effect(fn)Owner-scoped side effect re-run when tracked signals update
on_mount(fn)Runs once after the island finishes wiring up in the browser (hydration), without tracking signal dependencies
create_selector(sig)O(1) selection helper paired with BindClass so clicking a row updates only the old and new selected rows
Show(cond; fallback)Inserts or removes DOM branches with automatic cleanup
For(items; key = fn)Keyed list diffing that keeps existing DOM rows in place with minimal moves and delegates item clicks automatically

View Transitions & Persistence

Internal links are enhanced automatically with Astro-style soft navigation. Clicking a link fetches the next pre-rendered page, swaps #page-content inside document.startViewTransition(), updates NavLink active classes, and hydrates islands on the incoming route.

Because the layout shell outside #page-content stays mounted (and elements like the sticky header and DarkModeToggle carry data-transition-persist), navigation never flashes or resets your theme toggle. Same-page hash anchors (like #running) bypass the router and scroll natively.

# Layout.jl: header persists while #page-content swaps on soft navigation
Header(
    Symbol("data-transition-persist") => "docs-header",
    NavLink(
        "/getting-started/",
        "Getting Started";
        class = "tv-pill",
        active_class = "tv-pill-on",
    ),
    DarkModeToggle(),
)
MainEl(:id => "page-content", content)

Browser APIs

Use js() to bridge from WebAssembly into browser APIs. Signal and memo values interpolate via $1, $2, and so on.

# Console logging (re-runs on every signal change)
create_effect(() -> js("console.log('count:', \$1)", count()))

# DOM class toggling
js("document.documentElement.classList.toggle('dark')")

# localStorage persistence
js("localStorage.setItem('count', \$1)", count())
Module-level signals share state across islands
Declare const dark_mode = create_signal(0) at file scope and capture it inside @island. Every instance of that island stays synchronized automatically, even across separate .wasm modules. See the live Dark Mode Toggle example.

Running Your App

Choose between live HMR development, a full-stack Julia server, or a standalone interactive web app bundle:

CommandModeWhat it runs or outputs
devDevelopment serverBoots immediately and compiles each @island lazily through a persistent .therapy/cache/islands/ cache. Watches routes, components, static mounts, therapy.toml, and Tailwind CSS with surgical HMR and live error overlays.
runFull-stack Julia serverPre-compiles routes and islands at startup, then serves live SSR pages, /styles.css, static mounts, JSON API routes, and WebSockets directly from Julia.
buildStandalone interactive web appOutputs HTML, CSS, and external streaming .wasm modules for full client-side interactivity with zero Julia server, ready for GitHub Pages, Netlify, or any CDN.
previewStatic build preview serverServes the built dist/ directory locally in pure Julia with proper application/wasm MIME types and base_path support.
# Development server with instant boot, CSS HMR, and surgical island reloads
julia --project=. app.jl dev --port 8080

# Full-stack Julia server (SSR + API routes + WebSockets)
julia --project=. app.jl run --port 8080

# Build standalone interactive web app (optimized WasmGC bundles via wasm-opt by default)
julia --project=. app.jl build

# Preview the built dist/ output locally with full .wasm streaming
julia --project=. app.jl preview --port 4175

# Skip wasm-opt for faster local builds
julia --project=. app.jl build --no-optim
Zero-restart dev diagnostics and automation endpoints
During dev, query /_therapy/status for JSON health, revision, and active build errors, or long-poll /_therapy/wait?since=<rev>&timeout=5000 after saving a file. Send POST /_therapy/rebuild to force a clean recompile without restarting Julia.