Skip to main content
Create custom modules to extend iii with new functionality. Modules can have multiple adapter implementations for different backends.

Module Architecture

A module consists of:
  1. Module Implementation - Implements the Module trait
  2. Adapter Trait - Defines the adapter interface
  3. Adapter Implementations - Concrete adapter implementations
  4. Configuration - Module and adapter configuration
  5. Functions - Functions exposed to the engine
  6. Triggers - Optional trigger types for events

Quick Start: Custom Queue Module

Let’s build a custom queue module with multiple adapters. This example is based on examples/custom_queue_adapter.rs.

1. Define the Adapter Trait

Define what all adapters must implement:

2. Create Adapter Implementations

Implement your adapters:

3. Register Adapters

Create adapter registration and factories:

4. Define Module Configuration

5. Implement the Module

6. Implement ConfigurableModule

7. Implement Function Handler

8. Register and Use the Module

Configuration in config.yaml

Add your module to the configuration:
config.yaml

Adding Multiple Adapters

Create different adapter implementations:

Adding Triggers (Optional)

Implement trigger support:

Best Practices

  1. Trait-based Design: Define clear adapter traits
  2. Error Handling: Use anyhow::Result for errors
  3. Async: All I/O operations should be async
  4. Configuration: Support flexible adapter configuration
  5. Testing: Write tests for each adapter
  6. Documentation: Document your module’s functions and configuration
  7. Logging: Use tracing for observability

Example: Database Module

Source Code Reference

  • Full example: examples/custom_queue_adapter.rs
  • Module trait: src/modules/module.rs:30
  • ConfigurableModule: src/modules/module.rs:76
  • Adapter registration: src/modules/registry.rs