Skip to main content

Getting Started

This guide will walk you through the initial setup and basic usage of Thalo, ensuring you have everything needed to start building with this powerful event sourcing runtime.

Prerequisites

Before you begin, make sure you have the following prerequisites installed:

  1. Rust: Thalo requires the latest stable version of Rust. If you haven't installed Rust yet, you can do so by following the instructions on the official Rust website.

Installation

Thalo CLI

The Thalo CLI is a vital tool for building and managing your wasm aggregates. Install it using Cargo:

cargo install thalo_cli

Thalo Runtime

Thalo Runtime is necessary for running the Thalo environment. Install it with the following command:

cargo install thalo_runtime

Starting Thalo

Once you have installed the necessary components, you can start the Thalo runtime with the following command:

thalo-runtime

Creating Your First Aggregate

An aggregate in Thalo is a Rust crate that implements the thalo::Aggregate trait, and is exported with the thalo::export_aggregate! macro. Here's a basic example:

use thalo::{Aggregate, Command, Event};

thalo::export_aggregate!(MyAggregate);

struct MyAggregate { /* fields */ }
impl Aggregate for MyAggregate {
type Command = MyAggregateCommand;
type Event = MyAggregateEvent;

// ...
}

#[derive(Command, Deserialize)]
enum MyAggregateCommand { /* commands */ }

#[derive(Event, Serialize, Deserialize)]
enum MyAggregateEvent { /* events */ }

Compile your aggregate with the Thalo CLI:

thalo build my_aggregate -o ./modules

This assumes your aggregate crate name is my_aggregate, and will generate a my_aggregate.wasm file in a ./modules directory. Thalo automatically loads all wasm aggregate in the ./modules directory by default.

Testing Your Aggregate

After compiling and loading your aggregate, test it with the thalo execute command:

thalo execute my_aggregate <aggregate_id> <command> <command_data>

Replace <aggregate_id>, <command>, and <command_data> with appropriate values for your aggregate.