Phlow - A Dynamic Rule-Based Workflow Engine
Phlow is a flexible and extensible rule-based workflow engine written in Rust.
It allows users to define and execute dynamic decision trees and conditional workflows
using JSON-based configurations and embedded scripting via Rhai.
Features
- Dynamic workflows with JSON-defined rules
- Embedded scripting with Rhai for advanced expressions
- Conditional branching with custom operators (
starts_with,ends_with,search) - Step-based execution with context-aware evaluation
- Extensible engine with pluggable functions
Example: Decision Tree for Club Membership Approval
This example demonstrates a decision tree to determine if a person can become a club member.
use phlow;
use Engine;
use json;
use Context;
Modules
phlow- Main structure containing pipelines and execution logic.context- Manages execution state and variable storage.pipeline- Defines sequential execution of processing steps.step_worker- Handles conditional logic and step execution.script- Integrates Rhai scripting for dynamic evaluation.engine- Configures and extends the scripting engine.condition- Defines logical operators and conditions.collector- Logs execution steps and tracks workflow state.
Architecture Overview
The phlow engine processes a workflow pipeline composed of steps. Each step can:
- Evaluate conditions (e.g., comparisons, regex matching)
- Execute scripts for computations
- Branch execution based on conditions
- Store and reference previous step outputs
Execution Flow
- The engine receives an input JSON workflow definition.
- The
phlowinstance parses and validates the workflow. - The workflow executes step-by-step, evaluating conditions and executing actions.
- The final result is returned to the caller.
Advanced Usage
Adding Custom Plugins
Users can extend phlow by adding custom functions to the execution engine:
use ;
use Value;
use HashMap;
use Arc;
Handling Execution Errors
Errors during workflow execution are returned as Result<T, PhlowError>:
match phlow.execute_context
License
This project is licensed under the MIT License.