Runtime Configuration and Backends
7. Getting Started & Execution Guide
Follow these steps to build, configure, and execute the application with various database engines across different WASI-compliant WebAssembly runtimes.⚙️ Prerequisites
Ensure you have the following installed on your developer machine:- Rust Toolchain: Stable release (Rust 1.93.0+ or similar)
- WASM Target:
rustup target add wasm32-wasip2 - Fermyon Spin CLI (for Spin runtime):
brew install fermyon/tap/spin - Wasmtime CLI (for bare WASM runtime):
brew install wasmtime - cargo-leptos:
cargo install --locked cargo-leptos
🔑 Environment Setup (.env)
Before running the application, configure your databases. We provide a complete template. Copy the example file to initialize your config:
examples/counter-app/.env and inspect the configuration variables. The .env.example template is tracked by version control as a reference, enabling seamless collaboration and automated testing across local and cloud environments:
🔀 Advanced Enterprise Multi-Backend Architecture
Our Leptos application implements a state-of-the-art Multi-Backend Persistence Engine insidesrc/store.rs.
Because our CQRS and Event Sourcing infrastructure depends strictly on framework traits (EventStore, CheckpointStore, Projection), we designed dynamic, runtime-routed wrappers—MultiBackendEventStore<A>, MultiBackendCheckpointStore, and MultiBackendCounterProjection—which inspect the environment at boot-time and execute the correct database operations without modifying a single line of business or component-rendering code.
Supported Database Backends Matrix
⚡ Overcoming WASM Sandbox Limits: Stateless Outbound HTTP
When compiling applications to WebAssembly targets, traditional blocking socket connection pools (such as those used bytokio-postgres or standard native SQLite engines written in C) are strictly incompatible with the isolated, single-threaded sandboxed environment of a WASM component.
To solve this compilation and runtime block, our Multi-Backend Engine employs a stateless, highly optimized Outbound HTTP Bridge powered by the WASIp3 HTTP Component Model standards.
When a database request is sent to Neon, Supabase, or Turso, the store adapter converts the SQL query and its parameterized arguments into a payload format (e.g., the JSON-based Hrana pipeline protocol for Turso/LibSQL or the HTTP SQL Endpoint format for Neon), dispatches it via a single non-blocking HTTP POST, collects the response, and translates the rows back into DDD event envelopes.
Sequence Flow: Outbound HTTP Database Query
Here is a simplified look at how theMultiBackendEventStore leverages WASIp3 Outbound HTTP helpers to communicate with external SQL APIs: