Examples

Learn by example.

Explore categorized examples covering core concepts, HTTP routing, auth, persistence, observability, and protocol adapters. Each card links to the full source in the GitHub repository.

Learning Paths

Follow a guided path from beginner to advanced.

Quick Start

beginner

Build your first Axon workflow in under 30 minutes.

HTTP Services

intermediate

Build production HTTP APIs with routing, auth, and real-time features.

Advanced Patterns

advanced

Master resilience, persistence, and enterprise patterns.

Governance and Full Stack

advanced

Apply explicit request governance and connect a maintained full-stack reference.

Official Example Track

This is the official learning order. Start with Hello World, then move through CRUD and workflow examples before the bridge/reference surfaces.

Hello World

canonical Beginner

Minimal Flat API example — chain transitions to build and transform a greeting.

Minimal Axon pipeline in 3 lines

~5 min basics general
cargo run -p hello-world
  • server startup log
  • simple greeting response
#[transition]
async fn greet(input: String) -> Outcome<String, String> {
    Outcome::Next(format!("Hello, {input}!"))
}

Reference Todo API

supported Intermediate

Complete CRUD application with JWT authentication, Bus dependency injection, HTTP routing, and collection-based testing.

Complete CRUD with JWT and Bus DI

~30 min crud general
Prereqs: flat-api, routing-params
cargo run -p reference-todo-api
  • POST /login
  • GET/POST/PUT/DELETE /todos
// Single-transition Axon circuits per endpoint
POST /login   -> [login]       -> JWT token
GET  /todos   -> [list_todos]  -> Vec<Todo>
POST /todos   -> [create_todo] -> Todo
PUT  /todos/:id  -> [update_todo] -> Todo
DELETE /todos/:id -> [delete_todo] -> { deleted }

Order Processing Workflow

supported Intermediate

Domain-driven workflow: validation, payment, inventory reservation, and shipping.

Multi-step domain-driven workflow

~20 min pipelinesaga commerce
Prereqs: routing-demo
cargo run -p order-processing-demo
  • validation -> inventory -> payment -> shipping flow
  • success and failure-path logs
Axon::new("order")
    .then(validate_order)
    .then(process_payment)
    .then(reserve_inventory)
    .then(arrange_shipping)

Bridge & Reference

Continue from the official track into the admin-style bridge backend and the public-only reference app.

Admin CRUD Demo

supported Intermediate

Bridge example: JWT login, SQLite-backed admin CRUD, pagination/search, and OpenAPI in one mid-sized backend.

Admin-style CRUD backend after the official track

~35 min crud general
Prereqs: reference-todo-api, openapi
cargo run -p admin-crud-demo
  • JWT login
  • users CRUD
  • OpenAPI JSON
  • Swagger UI parity
Ranvier::http()
    .post_typed_json_out("/login", login)
    .get_json_out("/users", list_users)
    .post_typed_json_out("/users", create_user)
    .put_typed_json_out("/users/:id", update_user)
    .delete_json_out("/users/:id", delete_user)

Reference Fullstack Admin

supported Advanced

Public-only fullstack reference app with a Ranvier backend, SvelteKit frontend, JWT login, dashboard, and user administration.

Public-only fullstack reference app after the bridge example

~40 min crud general
Prereqs: admin-crud, openapi
cargo run -p reference-fullstack-admin
cd examples/reference-fullstack-admin/frontend && npm install && npm run dev
  • backend login/dashboard/users surface
  • frontend login/dashboard/users surface
Ranvier::http()
    .guard(CorsGuard::<AppState>::permissive())
    .post_typed_json_out("/login", login)
    .get_json_out("/dashboard", dashboard)
    .get_json_out("/users", list_users)

Reference E-commerce Order

supported Advanced

Complete Saga pipeline with compensation, audit trail, multi-tenancy, and RFC 7807 errors.

Complete Saga with compensation and audit

~40 min saga commercefintech
Prereqs: order-processing, audit, multitenancy
cargo run -p reference-ecommerce-order
  • saga compensation flow
  • order reference app surface
// Saga: CreateOrder → ProcessPayment → ReserveInventory → ScheduleShipping
//          ↓ (comp)          ↓ (comp)
//      RefundPayment    ReleaseInventory

Reference Chat Server

supported Advanced

Canonical WebSocket reference: multi-room chat with JWT auth, REST + WS hybrid routing, health/readiness probes, and graceful shutdown.

Canonical WebSocket operability reference

~35 min streaming general
Prereqs: websocket, session-pattern
cargo run -p reference-chat-server
  • health/ready/live probes
  • unauthenticated websocket auth_failed frame
  • authenticated join/history/message websocket flow

Governance & Operability

Separate from the OpenAPI surface, inspect a service that combines structured errors, audit logging, and guard-backed observability in one operability example.

Request Governance Demo

supported Advanced

Cross-cutting backend example combining JWT auth, policy checks, audit logging, SQLite persistence, and RFC 7807-style errors.

Auth + policy + audit + DB + structured errors in one flow

~30 min guardobservability general
Prereqs: admin-crud
cargo run -p request-governance-demo
  • 403 application/problem+json on insufficient-role approval
  • 200 on approver approval
  • audit event writes
Ranvier::http()
    .post_typed_json_out("/login", login)
    .post_typed_json_out("/requests", create_request)
    .get_with_error("/requests/:id", get_request, governance_error_response)
    .post_with_error("/requests/:id/approve", approve_request, governance_error_response)

All Examples

17 examples match the current filters.

Default filter: Core examples
Tier
Category
Pattern
Domain

Hello World

canonical Beginner

Minimal Flat API example — chain transitions to build and transform a greeting.

Minimal Axon pipeline in 3 lines

~5 min basics general
cargo run -p hello-world
  • server startup log
  • simple greeting response
#[transition]
async fn greet(input: String) -> Outcome<String, String> {
    Outcome::Next(format!("Hello, {input}!"))
}

Typed State Tree

canonical Beginner

Type-safe decision flows using Rust enums with Axon, Transition, and Outcome.

Type-safe decision flows with Rust enums

~10 min basicsbranching general
Prereqs: hello-world
cargo run -p typed-state-tree
let flow = Axon::new("flow")
    .then(validate)
    .then(process);

Basic Schematic

canonical Beginner

Axon flow visualization with schematic extraction for debugging and documentation.

Visualize any Axon pipeline as a schematic

~10 min basicsobservability general
Prereqs: hello-world
cargo run -p basic-schematic

Order Processing Workflow

supported Intermediate

Domain-driven workflow: validation, payment, inventory reservation, and shipping.

Multi-step domain-driven workflow

~20 min pipelinesaga commerce
Prereqs: routing-demo
cargo run -p order-processing-demo
  • validation -> inventory -> payment -> shipping flow
  • success and failure-path logs
Axon::new("order")
    .then(validate_order)
    .then(process_payment)
    .then(reserve_inventory)
    .then(arrange_shipping)

Bus Capability System

supported Intermediate

Declarative allow/deny access control via @transition bus attributes.

Declarative Bus access control

~15 min basics general
Prereqs: typed-state-tree
cargo run -p bus-capability-demo
#[transition(bus_allow = "db,cache")]
async fn fetch(input: Req) -> Outcome<Resp, String> { .. }

Outcome Variants

canonical Beginner

All 5 Outcome variants: Next (linear), Fault (error), Branch (conditional), Jump (loop), Emit (side-effect).

All 5 Outcome control flow variants

~15 min basicsbranching general
Prereqs: hello-world, typed-state-tree
cargo run -p outcome-variants-demo
// Outcome<T, E> — control flow as data
Outcome::Next(value)       // linear progression
Outcome::Fault(err)        // error path
Outcome::Branch("name", v) // conditional routing
Outcome::Jump("node", v)   // goto / loop
Outcome::Emit(event)       // side-effect event

Typed JSON API

supported Intermediate

Type-safe JSON endpoints using get_json_out, post_typed_json_out, BusHttpExt, and CorsGuard::permissive().

Type-safe JSON auto-serialization

~20 min crud general
Prereqs: flat-api, routing-params
cargo run -p typed-json-api
Ranvier::http()
    .get_json_out("/items", list_items_axon)
    .post_typed_json_out::<CreateItem, _, _>("/items", create_item_axon)
    .delete_json_out("/items/:id", delete_item_axon)

Admin CRUD Demo

supported Intermediate

Bridge example: JWT login, SQLite-backed admin CRUD, pagination/search, and OpenAPI in one mid-sized backend.

Admin-style CRUD backend after the official track

~35 min crud general
Prereqs: reference-todo-api, openapi
cargo run -p admin-crud-demo
  • JWT login
  • users CRUD
  • OpenAPI JSON
  • Swagger UI parity
Ranvier::http()
    .post_typed_json_out("/login", login)
    .get_json_out("/users", list_users)
    .post_typed_json_out("/users", create_user)
    .put_typed_json_out("/users/:id", update_user)
    .delete_json_out("/users/:id", delete_user)

Crash Recovery & Persistence

supported Intermediate

Workflow crash recovery, checkpointing, and compensation hooks.

Crash recovery with compensation hooks

~20 min saga general
Prereqs: hello-world
cargo run -p persistence-production-demo
Axon::new("resilient")
    .then(step_a)
    .then(step_b)
    .with_persistence(store)
    .with_compensation(rollback);

Traced Wrapper

canonical Intermediate

Automatic span generation in transitions with Traced wrapper and ConnectionBus.

Automatic span generation with Traced wrapper

~20 min observability general
Prereqs: hello-world
cargo run -p otel-concept

Testing Patterns

supported Beginner

Unit and integration testing strategies for Transitions and Axon chains.

Unit and integration testing strategies

~15 min basics general
Prereqs: hello-world
cargo run -p testing-patterns

Retry & Dead Letter Queue

supported Intermediate

DLQ retry with exponential backoff, timeout patterns, and circuit breaker.

DLQ retry with exponential backoff

~25 min saga general
Prereqs: custom-error-types
cargo run -p retry-dlq-demo
let axon = Axon::new("payment")
    .then(gateway)
    .with_dlq_policy(DlqPolicy::RetryThenDlq {
        max_attempts: 5,
        backoff_ms: 100,
    })
    .with_dlq_sink(dlq);

Request Governance Demo

supported Advanced

Cross-cutting backend example combining JWT auth, policy checks, audit logging, SQLite persistence, and RFC 7807-style errors.

Auth + policy + audit + DB + structured errors in one flow

~30 min guardobservability general
Prereqs: admin-crud
cargo run -p request-governance-demo
  • 403 application/problem+json on insufficient-role approval
  • 200 on approver approval
  • audit event writes
Ranvier::http()
    .post_typed_json_out("/login", login)
    .post_typed_json_out("/requests", create_request)
    .get_with_error("/requests/:id", get_request, governance_error_response)
    .post_with_error("/requests/:id/approve", approve_request, governance_error_response)

Reference E-commerce Order

supported Advanced

Complete Saga pipeline with compensation, audit trail, multi-tenancy, and RFC 7807 errors.

Complete Saga with compensation and audit

~40 min saga commercefintech
Prereqs: order-processing, audit, multitenancy
cargo run -p reference-ecommerce-order
  • saga compensation flow
  • order reference app surface
// Saga: CreateOrder → ProcessPayment → ReserveInventory → ScheduleShipping
//          ↓ (comp)          ↓ (comp)
//      RefundPayment    ReleaseInventory

Reference Chat Server

supported Advanced

Canonical WebSocket reference: multi-room chat with JWT auth, REST + WS hybrid routing, health/readiness probes, and graceful shutdown.

Canonical WebSocket operability reference

~35 min streaming general
Prereqs: websocket, session-pattern
cargo run -p reference-chat-server
  • health/ready/live probes
  • unauthenticated websocket auth_failed frame
  • authenticated join/history/message websocket flow

Reference Fullstack Admin

supported Advanced

Public-only fullstack reference app with a Ranvier backend, SvelteKit frontend, JWT login, dashboard, and user administration.

Public-only fullstack reference app after the bridge example

~40 min crud general
Prereqs: admin-crud, openapi
cargo run -p reference-fullstack-admin
cd examples/reference-fullstack-admin/frontend && npm install && npm run dev
  • backend login/dashboard/users surface
  • frontend login/dashboard/users surface
Ranvier::http()
    .guard(CorsGuard::<AppState>::permissive())
    .post_typed_json_out("/login", login)
    .get_json_out("/dashboard", dashboard)
    .get_json_out("/users", list_users)

Reference Todo API

supported Intermediate

Complete CRUD application with JWT authentication, Bus dependency injection, HTTP routing, and collection-based testing.

Complete CRUD with JWT and Bus DI

~30 min crud general
Prereqs: flat-api, routing-params
cargo run -p reference-todo-api
  • POST /login
  • GET/POST/PUT/DELETE /todos
// Single-transition Axon circuits per endpoint
POST /login   -> [login]       -> JWT token
GET  /todos   -> [list_todos]  -> Vec<Todo>
POST /todos   -> [create_todo] -> Todo
PUT  /todos/:id  -> [update_todo] -> Todo
DELETE /todos/:id -> [delete_todo] -> { deleted }
All examples live under ranvier/examples in the GitHub repository. Clone and run with cargo run -p <package>.