Expert knowledge for building event-driven systems with Composable Rust framework. Use when implementing reducers, designing state machines, working with effects, creating environment traits for dependency injection, building stores, or answering questions about core architectural patterns and the unidirectional data flow model.
Instalación
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Expert knowledge for building event-driven systems with Composable Rust framework. Use when implementing reducers, designing state machines, working with effects, creating environment traits for dependency injection, building stores, or answering questions about core architectural patterns and the unidirectional data flow model.
Composable Rust Architecture Expert
Expert knowledge for building event-driven systems using the Composable Rust framework - core architectural patterns, reducer design, effect composition, and the unidirectional data flow model.
When to Use This Skill
Automatically apply when:
Implementing reducers or state machines
Designing action types or state transitions
Working with effects or the effect system
Creating environment traits for dependency injection
Building stores or runtime components
Questions about architecture or design patterns
Core Architecture Fundamentals
The Five Types
Every Composable Rust application is built on these five fundamental types:
State: Domain state for a feature (Clone-able, owned data)
Action: Unified type for all inputs (commands, events, cross-aggregate events)
Reducer: Pure function (State, Action, Environment) → (State, Effects)
Effect: Side effect descriptions (values, not execution)
Environment: Injected dependencies via traits
These compose together to create a complete system.
The Feedback Loop (Critical Concept)
Actions flow through the system in a self-sustaining cycle:
External Input → Action
↓
Reducer: (State, Action, Env) → (New State, Effects)
↓
Store executes Effects
↓
Effects produce new Actions:
- Effect::Future returns 0 or 1 action
- Effect::Stream yields 0..N actions over time
↓
Loop back to Reducer
Key Insight: Everything is an Action. Commands are Actions. Events are Actions. External events are Actions. This creates a unified data flow where the reducer is the single source of state transitions.
Auto-generates version tracking methods for event-sourced state:
use composable_rust_macros::State;
use composable_rust_core::stream::Version;
#[derive(State, Clone, Debug)]pubstructOrderState {
pub order_id: Option<String>,
pub items: Vec<Item>,
#[version]// Mark version fieldpub version: Option<Version>,
}
// Auto-generated methods:
state.version(); // Get version
state.set_version(v); // Set version
Use when: Implementing event-sourced aggregates with optimistic concurrency.
#[derive(Action)] - Command/Event Helpers
Auto-generates type-safe helpers for distinguishing commands vs events:
❌ Anti-Pattern 2: Complex Logic in Effect Execution
// Effect execution should be simple dispatch
Effect::Database(op) => {
// ❌ Don't put business logic hereif should_retry && attempt < 3 {
// Complex retry logic in executor
}
}
Solution: Encode retry logic as actions/effects in the reducer.
❌ Anti-Pattern 3: Nested State Machines Without Composition
// ❌ Giant monolithic reducerfnreduce(...) {
match (state.order_status, state.payment_status, state.shipping_status) {
// 100s of match arms
}
}
Solution: Use reducer composition (see saga patterns skill).
❌ Anti-Pattern 4: Ignoring the Feedback Loop
use composable_rust_core::async_effect;
// ❌ Not returning actions from effects
async_effect! {
database.save(&data).await?;
None// ❌ Missing feedback!
}
Solution: Return actions from futures to feed back into the system.
Composition Patterns
Combining Reducers
// Combine two reducers that operate on the same stateletcombined = combine_reducers(reducer1, reducer2);
// Scope a reducer to a sub-stateletscoped = scope_reducer(
child_reducer,
|parent_state| &mut parent_state.child,
|child_action| ParentAction::Child(child_action),
);
Effect Composition
// Parallel executionletparallel = Effect::Parallel(vec![
effect1,
effect2,
effect3,
]);
// Sequential executionletsequential = Effect::Sequential(vec![
effect1, // Executes first
effect2, // Then this
effect3, // Finally this
]);
// Nested compositionletcomplex = Effect::Parallel(vec![
Effect::Sequential(vec![step1, step2]),
Effect::Sequential(vec![step3, step4]),
]);
Remember: The architecture is simple but powerful. State + Action + Reducer → (New State, Effects). The Store coordinates the feedback loop. Everything else builds on this foundation.