Skip to main content

Crate reinhardt_dentdelion

Crate reinhardt_dentdelion 

Source
Expand description

Dentdelion - Plugin System for Reinhardt Framework

Dentdelion (dent de lion = lion’s tooth = dandelion) is a plugin system that makes it easy to create, distribute, and install plugins for the Reinhardt web framework.

§Features

  • Static Plugins: Rust crates compiled with your application
  • WASM Plugins: Dynamic plugins loaded at runtime (with wasm feature)
  • TypeScript Plugins: TypeScript/JavaScript plugins via boa_engine (pure-Rust ECMAScript engine) (with ts feature)
  • Capability System: Fine-grained control over what plugins can do
  • CLI Management: Install and manage plugins via reinhardt plugin commands
  • Multi-Runtime: Unified interface for Static, WASM, and TypeScript runtimes

§Naming Convention

Plugin names should follow the xxx-delion pattern:

  • auth-delion - Authentication plugin
  • rate-limit-delion - Rate limiting plugin
  • analytics-delion - Analytics plugin

§Quick Start

§Creating a Plugin

use reinhardt_dentdelion::prelude::*;
use std::sync::Arc;

struct MyPlugin {
    metadata: PluginMetadata,
}

impl MyPlugin {
    pub fn new() -> Self {
        Self {
            metadata: PluginMetadata::builder("my-delion", "1.0.0")
                .description("My awesome plugin")
                .provides(PluginCapability::Middleware)
                .build()
                .unwrap(),
        }
    }
}

impl Plugin for MyPlugin {
    fn metadata(&self) -> &PluginMetadata {
        &self.metadata
    }

    fn capabilities(&self) -> &[Capability] {
        &[Capability::Core(PluginCapability::Middleware)]
    }
}

// Register the plugin for automatic discovery
register_plugin!(|| Arc::new(MyPlugin::new()));

§Using the Registry

use reinhardt_dentdelion::prelude::*;
use std::sync::Arc;

let registry = PluginRegistry::new();

// Register plugins
registry.register(Arc::new(MyPlugin::new())).unwrap();

// Validate dependencies
registry.validate_dependencies().unwrap();

// Get enable order
let order = registry.get_enable_order().unwrap();

§Project Manifest (dentdelion.toml)

[dentdelion]
format_version = "1.0"
wasm_dir = ".dentdelion/plugins"

[[plugins]]
name = "auth-delion"
type = "static"
version = "1.0.0"
enabled = true

[plugin_config.auth-delion]
algorithm = "HS256"

§Feature Flags

  • default - Core plugin system only
  • wasm - WASM plugin support with Component Model (requires wasmtime 36.x)
  • ts - TypeScript/JavaScript SSR support via boa_engine (pure-Rust ECMAScript engine)
  • cli - CLI support for crates.io integration
  • full - All features enabled (wasm + cli); note: ts is NOT included in full

§WASM Plugin Support

When the wasm feature is enabled, plugins can be loaded dynamically at runtime from WebAssembly Component Model files (.wasm).

§Key Features

  • Component Model: Uses WebAssembly Interface Types (WIT) for type-safe interfaces
  • Sandboxed Execution: Memory limits, timeouts, and fuel-based CPU metering
  • Host API: Config, logging, services, HTTP client, and database access
  • Capability-Based Security: Fine-grained permission checks for sensitive operations

§Requirements

  • Plugins must implement the dentdelion-plugin WIT world (see wit/dentdelion.wit)
  • Use wit-bindgen or cargo-component for code generation
  • Data serialized with MessagePack for WASM boundary crossing

§Runtime Configuration

use reinhardt_dentdelion::wasm::{WasmRuntime, WasmRuntimeConfigBuilder};
use std::time::Duration;

let config = WasmRuntimeConfigBuilder::new()
    .memory_limit_mb(128)
    .timeout(Duration::from_secs(30))
    .fuel_metering(true)
    .initial_fuel(100_000_000)
    .build();

let runtime = WasmRuntime::new(config)?;

§Capabilities

Two special capabilities are available for WASM plugins:

  • NetworkAccess - Required for http_get/http_post host functions
  • DatabaseAccess - Required for db_query/db_execute host functions

§Architecture

┌──────────────────────────────────┐
│        PluginRegistry            │
│    - Plugin registration         │
│    - Dependency resolution       │
│    - Lifecycle management        │
└────────────────┬─────────────────┘
                 │
    ┌────────────┼────────────┐
    │            │            │
┌───▼──┐     ┌───▼──┐     ┌───▼────┐
│Static│     │ WASM │     │Manifest│
│Plugin│     │Plugin│     │ Parser │
└──────┘     └──────┘     └────────┘

Re-exports§

pub use inventory;

Modules§

capability
Plugin capability system.
context
Plugin context for lifecycle operations.
error
Plugin system error types.
installer
Plugin installer for managing Cargo.toml and dentdelion.toml.
manifest
Plugin manifest parser for dentdelion.toml.
metadata
Plugin metadata and dependency definitions.
plugin
Core plugin traits.
prelude
Re-export commonly used types.
registry
Plugin registry for managing installed plugins.
runtime
Multi-runtime plugin execution layer.

Macros§

register_plugin
Macro for registering a static plugin.