rust-logic-graph 0.6.0

A modular reasoning graph framework for distributed logic orchestration
Documentation

🧠 Rust Logic Graph

Rust License: MIT

A high-performance reasoning graph framework for Rust with GRL (Grule Rule Language) support. Build complex workflows with conditional execution, topological ordering, and async processing.

use rust_logic_graph::{Graph, Orchestrator, GraphIO};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let def = GraphIO::load_from_file("workflow.json")?;
    let mut graph = Graph::new(def);
    Orchestrator::execute_graph(&mut graph).await?;
    Ok(())
}

✨ Key Features

  • πŸ”₯ GRL Support - rust-rule-engine v0.14.0 with RETE-UL algorithm (2-24x faster)
  • πŸ”„ Topological Execution - Automatic DAG-based node ordering
  • ⚑ Async Runtime - Built on Tokio for high concurrency
  • ⚑ Parallel Execution - Automatic parallel execution of independent nodes (v0.5.0)
  • πŸ’Ύ Caching Layer - High-performance result caching with TTL, eviction policies, and memory limits (v0.5.0)
  • πŸ› οΈ CLI Developer Tools - Graph validation, dry-run, profiling, and visualization (v0.5.0)
  • πŸ“Š Multiple Node Types - RuleNode, DBNode, AINode
  • πŸ“ JSON Configuration - Simple workflow definitions
  • 🎯 98% Drools Compatible - Easy migration from Java
  • 🌊 Streaming Processing - Stream-based execution with backpressure (v0.3.0)
  • πŸ—„οΈ Database Integrations - PostgreSQL, MySQL, Redis, MongoDB (v0.2.0)
  • πŸ€– AI/LLM Integrations - OpenAI, Claude, Ollama (v0.2.0)

πŸš€ Quick Start

Installation

[dependencies]
rust-logic-graph = "0.6.0"

# With specific integrations
rust-logic-graph = { version = "0.6.0", features = ["postgres", "openai"] }

# With all integrations
rust-logic-graph = { version = "0.6.0", features = ["all-integrations"] }

Simple Example

use rust_logic_graph::{RuleEngine, GrlRule};

let grl = r#"
rule "Discount" {
    when
        cart_total > 100 && is_member == true
    then
        discount = 0.15;
}
"#;

let mut engine = RuleEngine::new();
engine.add_grl_rule(grl)?;

CLI Tools (NEW in v0.5.0)

# Build the CLI tool
cargo build --release --bin rlg

# Validate a graph
./target/release/rlg validate --file examples/sample_graph.json

# Visualize graph structure
./target/release/rlg visualize --file examples/sample_graph.json --details

# Profile performance
./target/release/rlg profile --file examples/sample_graph.json --iterations 100

# Dry-run without execution
./target/release/rlg dry-run --file examples/sample_graph.json --verbose

Full CLI Documentation β†’

Run Examples

# Basic workflow
cargo run --example simple_flow

# GRL rules
cargo run --example grl_rules

# Advanced integration
cargo run --example grl_graph_flow

πŸ“š Documentation

Document Description
CLI Tool Guide Developer tools for validation, profiling, and visualization (NEW in v0.5.0)
Cache Guide Caching layer with TTL and eviction policies (v0.5.0)
Migration Guide Upgrade guide to v0.14.0 with RETE-UL (v0.5.0)
Integrations Guide Database & AI integrations (v0.2.0)
GRL Guide Complete GRL syntax and examples
Use Cases 33+ real-world applications
Extending Create custom nodes and integrations
Implementation Technical details

🎯 Use Cases

Rust Logic Graph powers applications in:

  • πŸ’° Finance - Loan approval, fraud detection, risk assessment
  • πŸ›’ E-commerce - Dynamic pricing, recommendations, fulfillment
  • πŸ₯ Healthcare - Patient triage, clinical decisions, monitoring
  • 🏭 Manufacturing - Predictive maintenance, QC automation
  • πŸ›‘οΈ Insurance - Claims processing, underwriting
  • πŸ“Š Marketing - Lead scoring, campaign optimization
  • βš–οΈ Compliance - AML monitoring, GDPR automation

View all 33+ use cases β†’


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     rust-rule-engine v0.14.0 (GRL)      β”‚
β”‚    RETE-UL Algorithm β€’ 2-24x Faster     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Rust Logic Graph Core            β”‚
β”‚  β€’ Graph Definition                     β”‚
β”‚  β€’ Parallel Executor                    β”‚
β”‚  β€’ Cache Manager (NEW)                  β”‚
β”‚  β€’ Context Management                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚            β”‚            β”‚
β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”
β”‚ Rule  β”‚   β”‚  DB   β”‚   β”‚  AI   β”‚
β”‚ Node  β”‚   β”‚ Node  β”‚   β”‚ Node  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚            β”‚            β”‚
β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
β”‚         CLI Developer Tools        β”‚
β”‚  β€’ Validate  β€’ Profile  β€’ Visualizeβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”₯ GRL Example

rule "HighValueLoan" salience 100 {
    when
        loan_amount > 100000 &&
        credit_score < 750
    then
        requires_manual_review = true;
        approval_tier = "senior";
}

rule "AutoApproval" salience 50 {
    when
        credit_score >= 700 &&
        income >= loan_amount * 3 &&
        debt_ratio < 0.4
    then
        auto_approve = true;
        interest_rate = 3.5;
}

Learn more about GRL β†’


πŸ“Š Performance

  • RETE-UL Algorithm: Advanced pattern matching with unlinking (v0.14.0)
  • 2-24x Faster: Than v0.10 at 50+ rules
  • 98% Drools Compatible: Easy migration path
  • Async by Default: High concurrency support
  • Parallel Execution: Automatic layer-based parallelism
  • Smart Caching: Result caching with TTL and eviction policies

πŸ§ͺ Testing & CLI Tools

# Run all tests
cargo test

# Build CLI tool
cargo build --release --bin rlg

# Validate graph
./target/release/rlg validate --file examples/sample_graph.json

# Visualize graph structure
./target/release/rlg visualize --file examples/sample_graph.json

# Profile performance
./target/release/rlg profile --file examples/sample_graph.json --iterations 100

# Dry-run execution
./target/release/rlg dry-run --file examples/sample_graph.json --verbose

Test Results: βœ… 32/32 tests passing

Learn more about CLI tools β†’


πŸ“¦ Project Status

Version: 0.6.0 (Latest) Status: Production-ready with parallel execution, caching, and CLI tools

What's Working

  • βœ… Core graph execution engine
  • βœ… RETE-UL algorithm (v0.14.0) - 2-24x faster
  • βœ… Three node types (Rule, DB, AI)
  • βœ… Topological sorting
  • βœ… Async execution
  • βœ… JSON I/O
  • βœ… Database integrations (PostgreSQL, MySQL, Redis, MongoDB)
  • βœ… AI integrations (OpenAI, Claude, Ollama)
  • βœ… Streaming processing with backpressure and chunking
  • βœ… Parallel execution with automatic layer detection
  • βœ… Caching layer with TTL, eviction policies, memory limits (v0.5.0)
  • βœ… CLI Developer Tools - validate, profile, visualize, dry-run (v0.5.0)
  • βœ… Stream operators (map, filter, fold)
  • βœ… Comprehensive documentation

Roadmap

  • Streaming processing (v0.3.0) - COMPLETED βœ…
  • Parallel node execution (v0.4.0) - COMPLETED βœ…
  • Caching layer (v0.5.0) - COMPLETED βœ…
  • CLI Developer Tools (v0.5.0) - COMPLETED βœ…
  • RETE-UL upgrade (v0.5.0) - COMPLETED βœ…
  • GraphQL API (v0.6.0)
  • Web UI for visualization (v0.7.0)
  • Production release (v1.0.0)

See ROADMAP.md for details


🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create your feature branch
  3. Write tests for new features
  4. Submit a pull request

πŸ“– Examples

Example Description Lines
simple_flow.rs Basic 3-node pipeline 36
advanced_flow.rs Complex 6-node workflow 120
grl_rules.rs GRL rule examples 110
grl_graph_flow.rs GRL + Graph integration 140
postgres_flow.rs PostgreSQL integration 100
openai_flow.rs OpenAI GPT integration 150
streaming_flow.rs Streaming with backpressure 200
parallel_execution.rs Parallel node execution 250

CLI Tool Examples (v0.5.0)

File Description
examples/sample_graph.json Linear workflow with 5 nodes
examples/cyclic_graph.json Graph with cycle for testing
examples/sample_context.json Sample input data

See CLI_TOOL.md for usage examples


🌟 Why Rust Logic Graph?

vs. Traditional Rule Engines

  • βœ… Async by default - No blocking I/O
  • βœ… Type safety - Rust's type system
  • βœ… Modern syntax - GRL support
  • βœ… Graph-based - Complex workflows

vs. Workflow Engines

  • βœ… Embedded - No external services
  • βœ… Fast - Compiled Rust code
  • βœ… Flexible - Custom nodes
  • βœ… Rule-based - Business logic in rules

πŸ“ Changelog

v0.5.0 (2025-11-06) - Performance & Developer Tools Release

Breaking Changes:

  • ⚑ Upgraded rust-rule-engine from v0.10 β†’ v0.14.0
    • Now uses RETE-UL algorithm (2-24x faster)
    • Better memory efficiency
    • Improved conflict resolution
    • See Migration Guide

New Features:

  • πŸ› οΈ CLI Developer Tools (rlg binary)
    • Graph validation with comprehensive checks
    • Dry-run execution mode
    • Performance profiling with statistics
    • ASCII graph visualization
    • See CLI Tool Guide
  • πŸ’Ύ Caching Layer - High-performance result caching
    • TTL-based expiration
    • Multiple eviction policies (LRU, LFU, FIFO)
    • Memory limits and statistics
    • See Cache Guide
  • ⚑ Parallel Node Execution - Automatic detection and parallel execution
    • Layer detection algorithm using topological sort
    • Concurrent execution within layers
    • Parallelism analysis and statistics
  • πŸ“Š ParallelExecutor - New executor with parallel capabilities
  • πŸ“ New Examples - CLI examples and test graphs
  • βœ… 32 Tests - Comprehensive test coverage

Improvements:

  • Updated documentation with CLI tools, caching, and migration guides
  • Performance benchmarking utilities
  • Example graph files for testing

Compatibility:

  • All 32 tests passing
  • API is backward compatible (100%)
  • Performance: 2-24x faster rule matching

v0.3.0 (2025-11-03) - Streaming & Performance Release

New Features:

  • 🌊 Streaming Processing - Stream-based node execution
    • Backpressure handling with bounded channels
    • Large dataset support with chunking
    • Stream operators (map, filter, fold, async map)
  • πŸ“ New Example - streaming_flow.rs with 6 demonstrations
  • βœ… 8 New Tests - Streaming module testing

Performance:

  • Processed 10,000 items in chunks
  • ~432 items/sec throughput with backpressure

v0.2.0 (2025-11-02) - Integrations Release

New Features:

  • πŸ—„οΈ Database Integrations - PostgreSQL, MySQL, Redis, MongoDB
  • πŸ€– AI/LLM Integrations - OpenAI GPT-4, Claude 3.5, Ollama
  • πŸ“ Integration Examples - postgres_flow.rs, openai_flow.rs
  • πŸ“š INTEGRATIONS.md - Comprehensive integration guide
  • πŸŽ›οΈ Feature Flags - Optional dependencies for integrations

v0.1.0 (2025-11-01) - Initial Release

Core Features:

  • 🧠 Core graph execution engine
  • πŸ”₯ GRL (Grule Rule Language) integration
  • πŸ”„ Topological sorting
  • ⚑ Async execution with Tokio
  • πŸ“Š Three node types (Rule, DB, AI)
  • πŸ“ JSON I/O for graphs
  • πŸ“š 4 working examples
  • βœ… 6/6 tests passing

πŸ“„ License

MIT License - see LICENSE for details.


πŸ”— Links


πŸ‘₯ Authors

James Vu - Initial work


πŸ™ Acknowledgments

Built with:


⭐ Star us on GitHub if you find this useful! ⭐

Documentation β€’ Examples β€’ Use Cases