Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Crate Reference

AstraWeave is organized as a workspace of interconnected crates, each providing focused functionality. This reference documents the crate hierarchy, dependencies, and public APIs.

Workspace Overview

graph TB
    subgraph Core["Core Layer"]
        ECS[astraweave-ecs]
        MATH[astraweave-math]
        SDK[astraweave-sdk]
    end
    
    subgraph AI["AI Layer"]
        AI_CORE[astraweave-ai]
        LLM[astraweave-llm]
        MEMORY[astraweave-memory]
        PERSONA[astraweave-persona]
        BEHAVIOR[astraweave-behavior]
    end
    
    subgraph Rendering["Rendering Layer"]
        RENDER[astraweave-render]
        MATERIALS[astraweave-materials]
        ASSET[astraweave-asset]
        UI[astraweave-ui]
    end
    
    subgraph Simulation["Simulation Layer"]
        PHYSICS[astraweave-physics]
        NAV[astraweave-nav]
        AUDIO[astraweave-audio]
    end
    
    subgraph Gameplay["Gameplay Layer"]
        GAMEPLAY[astraweave-gameplay]
        DIALOGUE[astraweave-dialogue]
        QUESTS[astraweave-quests]
        PCG[astraweave-pcg]
    end
    
    SDK --> ECS
    SDK --> AI_CORE
    SDK --> RENDER
    SDK --> PHYSICS
    
    AI_CORE --> ECS
    AI_CORE --> LLM
    AI_CORE --> MEMORY
    
    RENDER --> ECS
    RENDER --> ASSET
    RENDER --> MATERIALS
    
    GAMEPLAY --> ECS
    GAMEPLAY --> AI_CORE
    GAMEPLAY --> PHYSICS

Core Crates

astraweave-ecs

The foundation Entity Component System providing deterministic, high-performance entity management.

[dependencies]
astraweave-ecs = "0.1"

Key Types:

TypeDescription
WorldContainer for all entities, components, and resources
EntityLightweight identifier for game objects
ComponentData attached to entities (derive macro available)
ResourceSingleton data shared across systems
QueryEfficient iteration over component combinations
CommandsDeferred entity/component modifications

Example:

#![allow(unused)]
fn main() {
use astraweave_ecs::prelude::*;

#[derive(Component)]
struct Position(Vec3);

#[derive(Component)]
struct Velocity(Vec3);

fn movement_system(mut query: Query<(&mut Position, &Velocity)>) {
    for (mut pos, vel) in query.iter_mut() {
        pos.0 += vel.0;
    }
}
}

Features:

  • parallel - Enable parallel system execution (default)
  • tracing - Add performance tracing instrumentation
  • serde - Serialization support for components

astraweave-math

Mathematics library optimized for game development with SIMD acceleration.

[dependencies]
astraweave-math = "0.1"

Key Types:

TypeDescription
Vec2, Vec3, Vec4Vector types with operator overloading
Mat3, Mat4Matrix types for transforms
QuatQuaternion for rotations
TransformPosition + rotation + scale
AabbAxis-aligned bounding box
RayRay for intersection tests

Example:

#![allow(unused)]
fn main() {
use astraweave_math::prelude::*;

let pos = Vec3::new(1.0, 2.0, 3.0);
let rotation = Quat::from_axis_angle(Vec3::Y, 45.0_f32.to_radians());
let transform = Transform::from_translation(pos).with_rotation(rotation);

let world_pos = transform.transform_point(Vec3::ZERO);
}

astraweave-sdk

High-level SDK that re-exports commonly used types and provides convenience APIs.

[dependencies]
astraweave-sdk = "0.1"

Re-exports:

#![allow(unused)]
fn main() {
pub use astraweave_ecs::prelude::*;
pub use astraweave_ai::prelude::*;
pub use astraweave_render::prelude::*;
pub use astraweave_physics::prelude::*;
pub use astraweave_audio::prelude::*;
pub use astraweave_input::prelude::*;
}

App Builder:

use astraweave_sdk::prelude::*;

fn main() {
    App::new()
        .add_plugin(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(game_logic)
        .run();
}

AI Crates

astraweave-ai

Core AI framework with perception, planning, and behavior systems.

[dependencies]
astraweave-ai = "0.1"

Key Types:

TypeDescription
AiAgentAI-controlled entity component
PerceptionBusSensory input aggregation
PlannerGoal-oriented action planning
BehaviorTreeBehavior tree execution
BlackboardShared AI state storage
AiToolTool definition for LLM agents

Example:

#![allow(unused)]
fn main() {
use astraweave_ai::prelude::*;

let mut agent = AiAgent::new()
    .with_perception_radius(50.0)
    .with_tick_budget_ms(8);

agent.add_goal(AiGoal::Patrol { 
    waypoints: vec![point_a, point_b, point_c] 
});
}

Features:

  • llm - Enable LLM integration (requires astraweave-llm)
  • goap - Goal-Oriented Action Planning
  • utility - Utility AI scoring system

astraweave-llm

LLM integration for AI agents with tool calling and validation.

[dependencies]
astraweave-llm = "0.1"

Key Types:

TypeDescription
LlmClientHTTP client for LLM endpoints
LlmConfigConfiguration for model and endpoint
ToolCallStructured tool invocation from LLM
ToolResultValidated tool execution result
PromptBuilderFluent prompt construction

Example:

#![allow(unused)]
fn main() {
use astraweave_llm::prelude::*;

let config = LlmConfig {
    endpoint: "http://localhost:11434".into(),
    model: "hermes2-pro-mistral".into(),
    temperature: 0.7,
    max_tokens: 256,
};

let client = LlmClient::new(config);
let response = client.complete("What should I do next?").await?;
}

Supported Backends:

  • Ollama (local)
  • OpenAI-compatible APIs
  • Custom endpoints

astraweave-memory

Memory systems for AI agents including short-term, long-term, and episodic memory.

[dependencies]
astraweave-memory = "0.1"

Key Types:

TypeDescription
MemoryStoreCentral memory management
ShortTermMemoryRecent observations with decay
LongTermMemoryPersistent important memories
EpisodicMemoryEvent sequences and narratives
MemoryQuerySemantic memory retrieval

astraweave-behavior

Behavior tree implementation with visual editor support.

[dependencies]
astraweave-behavior = "0.1"

Node Types:

CategoryNodes
CompositeSequence, Selector, Parallel, RandomSelector
DecoratorInverter, Repeater, Succeeder, UntilFail
LeafAction, Condition, Wait, SubTree

Example:

#![allow(unused)]
fn main() {
use astraweave_behavior::prelude::*;

let tree = BehaviorTree::new(
    Selector::new(vec![
        Sequence::new(vec![
            Condition::new("has_target"),
            Action::new("attack_target"),
        ]).into(),
        Action::new("patrol").into(),
    ])
);
}

Rendering Crates

astraweave-render

GPU rendering with Vulkan/DX12/Metal backends via wgpu.

[dependencies]
astraweave-render = "0.1"

Key Types:

TypeDescription
RendererMain rendering context
RenderPassConfigurable render pass
MeshVertex/index buffer pair
MaterialSurface properties and shaders
CameraView and projection configuration
LightPoint, directional, spot lights

Features:

  • pbr - Physically-based rendering (default)
  • shadows - Shadow mapping with CSM
  • post-process - Bloom, SSAO, tone mapping
  • skeletal - Skeletal animation

astraweave-materials

PBR material system with shader graph support.

[dependencies]
astraweave-materials = "0.1"

Material Properties:

PropertyTypeDescription
albedoColor or TextureBase color
metallicf32 or TextureMetallic factor (0-1)
roughnessf32 or TextureSurface roughness (0-1)
normalTextureNormal map
emissionColorEmissive color
aoTextureAmbient occlusion

astraweave-asset

Asset loading, caching, and hot-reloading.

[dependencies]
astraweave-asset = "0.1"

Key Types:

TypeDescription
AssetServerAsync asset loading
Handle<T>Reference-counted asset handle
AssetLoaderCustom loader trait
AssetEventLoad/unload notifications

Supported Formats:

  • Meshes: glTF 2.0, OBJ, FBX
  • Textures: PNG, JPEG, KTX2, DDS
  • Audio: WAV, OGG, MP3
  • Fonts: TTF, OTF

astraweave-ui

Immediate-mode UI with retained state for game interfaces.

[dependencies]
astraweave-ui = "0.1"

Key Types:

TypeDescription
UiContextUI state and input handling
WidgetBase widget trait
LayoutFlexbox-style layout
StyleVisual styling properties

Built-in Widgets:

  • Button, Label, TextInput
  • Slider, Checkbox, RadioGroup
  • Panel, ScrollView, Modal
  • ProgressBar, Tooltip

Simulation Crates

astraweave-physics

3D physics with Rapier backend.

[dependencies]
astraweave-physics = "0.1"

Key Types:

TypeDescription
RigidBodyDynamic, kinematic, or static body
ColliderCollision shape
PhysicsWorldPhysics simulation context
RayCastRay intersection queries
JointConstraints between bodies

Collider Shapes:

  • Ball, Cuboid, Capsule, Cylinder
  • ConvexHull, TriMesh, HeightField
  • Compound (multiple shapes)

astraweave-nav

Navigation mesh and pathfinding.

[dependencies]
astraweave-nav = "0.1"

Key Types:

TypeDescription
NavMeshNavigation mesh geometry
NavAgentPathfinding agent component
PathQueryPath computation request
NavObstacleDynamic obstacle

Features:

  • A* pathfinding with string pulling
  • Dynamic obstacle avoidance
  • Off-mesh links for jumps/ladders
  • Hierarchical pathfinding for large worlds

astraweave-audio

Spatial audio with multiple backends.

[dependencies]
astraweave-audio = "0.1"

Key Types:

TypeDescription
AudioSourcePositional audio emitter
AudioListenerSpatial audio receiver
AudioClipLoaded audio data
MixerAudio mixing and effects

Features:

  • 3D spatial audio with HRTF
  • Reverb zones
  • Audio occlusion
  • Streaming for music

Gameplay Crates

astraweave-gameplay

High-level gameplay systems and components.

[dependencies]
astraweave-gameplay = "0.1"

Systems:

  • Combat and damage
  • Inventory management
  • Status effects
  • Interactable objects
  • Save/load integration

astraweave-dialogue

Dialogue tree and conversation systems.

[dependencies]
astraweave-dialogue = "0.1"

Key Types:

TypeDescription
DialogueTreeBranching conversation graph
DialogueNodeSingle dialogue entry
DialogueControllerRuntime dialogue state
DynamicDialogueLLM-powered conversations

astraweave-quests

Quest tracking and objective systems.

[dependencies]
astraweave-quests = "0.1"

Key Types:

TypeDescription
QuestQuest definition
QuestLogPlayer’s active quests
ObjectiveQuest goal/task
QuestEventQuest state changes

astraweave-pcg

Procedural content generation framework.

[dependencies]
astraweave-pcg = "0.1"

Generators:

  • Terrain heightmaps with erosion
  • Dungeon layouts
  • Item properties
  • NPC backstories (AI-enhanced)
  • Quest generation (AI-enhanced)

Tool Crates

aw_editor

Visual editor for scenes, behavior trees, and materials.

cargo run -p aw_editor

Features:

  • Scene hierarchy view
  • Component inspector
  • Behavior tree editor
  • Material graph editor
  • Asset browser

aw_asset_cli

Command-line asset processing.

cargo run -p aw_asset_cli -- --help

Commands:

  • import - Convert assets to engine format
  • pack - Create asset bundles
  • validate - Check asset integrity
  • optimize - Compress and optimize assets

aw_debug

Runtime debugging tools.

[dependencies]
aw_debug = "0.1"

Features:

  • Entity inspector overlay
  • Performance graphs
  • Physics debug visualization
  • AI state visualization
  • Console commands

Feature Flags Summary

CrateFeatureDescription
astraweave-ecsparallelParallel system execution
astraweave-ecstracingPerformance instrumentation
astraweave-aillmLLM integration
astraweave-aigoapGoal-oriented planning
astraweave-renderpbrPBR materials
astraweave-rendershadowsShadow mapping
astraweave-physicsdebug-renderPhysics visualization
astraweave-audiospatial3D audio

Dependency Graph

graph LR
    subgraph External["External Dependencies"]
        wgpu[wgpu]
        rapier[rapier3d]
        tokio[tokio]
        serde[serde]
    end
    
    ECS[astraweave-ecs] --> serde
    RENDER[astraweave-render] --> wgpu
    RENDER --> ECS
    PHYSICS[astraweave-physics] --> rapier
    PHYSICS --> ECS
    LLM[astraweave-llm] --> tokio
    AI[astraweave-ai] --> ECS
    AI --> LLM