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
beginnerBuild your first Axon workflow in under 30 minutes.
HTTP Services
intermediateBuild production HTTP APIs with routing, auth, and real-time features.
Advanced Patterns
advancedMaster resilience, persistence, and enterprise patterns.
Governance and Full Stack
advancedApply 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
Minimal Flat API example — chain transitions to build and transform a greeting.
Minimal Axon pipeline in 3 lines
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
Complete CRUD application with JWT authentication, Bus dependency injection, HTTP routing, and collection-based testing.
Complete CRUD with JWT and Bus DI
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
Domain-driven workflow: validation, payment, inventory reservation, and shipping.
Multi-step domain-driven workflow
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
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
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
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
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
Complete Saga pipeline with compensation, audit trail, multi-tenancy, and RFC 7807 errors.
Complete Saga with compensation and audit
cargo run -p reference-ecommerce-order
- saga compensation flow
- order reference app surface
// Saga: CreateOrder → ProcessPayment → ReserveInventory → ScheduleShipping
// ↓ (comp) ↓ (comp)
// RefundPayment ReleaseInventoryReference Chat Server
Canonical WebSocket reference: multi-room chat with JWT auth, REST + WS hybrid routing, health/readiness probes, and graceful shutdown.
Canonical WebSocket operability reference
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
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
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.
Hello World
Minimal Flat API example — chain transitions to build and transform a greeting.
Minimal Axon pipeline in 3 lines
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
Type-safe decision flows using Rust enums with Axon, Transition, and Outcome.
Type-safe decision flows with Rust enums
cargo run -p typed-state-tree
let flow = Axon::new("flow")
.then(validate)
.then(process);Basic Schematic
Axon flow visualization with schematic extraction for debugging and documentation.
Visualize any Axon pipeline as a schematic
cargo run -p basic-schematic
Order Processing Workflow
Domain-driven workflow: validation, payment, inventory reservation, and shipping.
Multi-step domain-driven workflow
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
Declarative allow/deny access control via @transition bus attributes.
Declarative Bus access control
cargo run -p bus-capability-demo
#[transition(bus_allow = "db,cache")]
async fn fetch(input: Req) -> Outcome<Resp, String> { .. }Outcome Variants
All 5 Outcome variants: Next (linear), Fault (error), Branch (conditional), Jump (loop), Emit (side-effect).
All 5 Outcome control flow variants
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 eventTyped JSON API
Type-safe JSON endpoints using get_json_out, post_typed_json_out, BusHttpExt, and CorsGuard::permissive().
Type-safe JSON auto-serialization
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
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
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
Workflow crash recovery, checkpointing, and compensation hooks.
Crash recovery with compensation hooks
cargo run -p persistence-production-demo
Axon::new("resilient")
.then(step_a)
.then(step_b)
.with_persistence(store)
.with_compensation(rollback);Traced Wrapper
Automatic span generation in transitions with Traced wrapper and ConnectionBus.
Automatic span generation with Traced wrapper
cargo run -p otel-concept
Testing Patterns
Unit and integration testing strategies for Transitions and Axon chains.
Unit and integration testing strategies
cargo run -p testing-patterns
Retry & Dead Letter Queue
DLQ retry with exponential backoff, timeout patterns, and circuit breaker.
DLQ retry with exponential backoff
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
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
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
Complete Saga pipeline with compensation, audit trail, multi-tenancy, and RFC 7807 errors.
Complete Saga with compensation and audit
cargo run -p reference-ecommerce-order
- saga compensation flow
- order reference app surface
// Saga: CreateOrder → ProcessPayment → ReserveInventory → ScheduleShipping
// ↓ (comp) ↓ (comp)
// RefundPayment ReleaseInventoryReference Chat Server
Canonical WebSocket reference: multi-room chat with JWT auth, REST + WS hybrid routing, health/readiness probes, and graceful shutdown.
Canonical WebSocket operability reference
cargo run -p reference-chat-server
- health/ready/live probes
- unauthenticated websocket auth_failed frame
- authenticated join/history/message websocket flow
Reference Fullstack Admin
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
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
Complete CRUD application with JWT authentication, Bus dependency injection, HTTP routing, and collection-based testing.
Complete CRUD with JWT and Bus DI
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 }cargo run -p <package>.