Learn
Clients
Runtime

Runtime

A runtime is an essential concept in clean/hexagonal architecture, especially within the context of command and query execution in the client layer. It is essentially a composite of all necessary traits to execute the commands and queries in your application.

Understanding Runtime

The runtime serves as the execution context for your application's operations. It's where your application's logic comes to life, interacting with various services, repositories, and stores.

Core Characteristics:

  • Combination of Traits: It aggregates all the necessary traits to execute commands and queries.
  • Execution Context: Provides the necessary context and dependencies for executing operations.
  • Delegate Pattern: To enhance the development experience, runtimes utilize the delegate pattern, which the framework crate directly exposes.

Creating a Runtime

Creating a runtime involves defining a struct that includes all the necessary traits and services your application requires. Here's an example of how you might define a runtime in Rust using the delegate pattern:

clients/axum/src/runtime.rs
use framework::*;
 
#[derive(Default, Delegate)]
pub struct Runtime {
    #[to(TodoListStore, TodoListRepository)]
    store: services::memstore::MemStore,
}

This Runtime struct becomes the backbone of your application's client layer, orchestrating the interactions between different components.