π§ Rust Logic Graph
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.
β¨ 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)
- π§ Memory Optimization - Context pooling and allocation tracking (v0.7.0)
- π οΈ CLI Developer Tools - Graph validation, dry-run, profiling, and visualization (v0.5.0)
- π¨ Web Graph Editor - Next.js visual editor with drag-and-drop interface (v0.8.0)
- οΏ½ YAML Configuration - Declarative graph definitions with external config files (v0.8.5)
- οΏ½π Multiple Node Types - RuleNode, DBNode, AINode
- π JSON/YAML 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
[]
= "0.8.5"
# With specific integrations
= { = "0.8.5", = ["postgres", "openai"] }
# With all integrations
= { = "0.8.5", = ["all-integrations"] }
Simple Example
use ;
let grl = r#"
rule "Discount" {
when
cart_total > 100 && is_member == true
then
discount = 0.15;
}
"#;
let mut engine = new;
engine.add_grl_rule?;
π’ Real-World Case Study: Purchasing Flow System
See a complete production implementation in case_study/ - A full-featured purchasing automation system built with Rust Logic Graph.
π System Overview
Problem: Automate purchasing decisions for inventory replenishment across multiple products, warehouses, and suppliers.
Solution: Business rules in GRL decide when/how much to order. Orchestrator executes the workflows.
π― Two Architecture Implementations
1. Microservices (v4.0) - 7 services with gRPC
- Orchestrator (port 8080) - Workflow coordination
- OMS Service (port 50051) - Order management data
- Inventory Service (port 50052) - Stock levels
- Supplier Service (port 50053) - Supplier information
- UOM Service (port 50054) - Unit conversions
- Rule Engine (port 50055) - GRL business rules
- PO Service (port 50056) - Purchase order management
2. Monolithic - Single HTTP service
- Same business logic as microservices
- Single process on port 8080
- Shared GRL rules file
- Direct function calls instead of gRPC
π₯ GRL Business Rules (15 Rules)
rule "CalculateShortage" salience 120 no-loop {
when
required_qty > 0
then
Log("Calculating shortage...");
shortage = required_qty - available_qty;
Log("Shortage calculated");
}
rule "OrderMOQWhenShortageIsLess" salience 110 no-loop {
when
shortage > 0 && shortage < moq && is_active == true
then
Log("Shortage less than MOQ, ordering MOQ");
order_qty = moq;
}
See full rules: purchasing_rules.grl
YAML Configuration (NEW in v0.8.5)
Both Monolithic and Microservices implementations now support YAML-based graph configuration:
# purchasing_flow_graph.yaml
nodes:
oms_grpc:
type: DBNode
description: "Fetch order management data"
inventory_grpc:
type: DBNode
description: "Fetch inventory levels"
rule_engine_grpc:
type: RuleNode
description: "Evaluate business rules"
dependencies:
- oms_grpc
- inventory_grpc
edges:
- from: oms_grpc
to: rule_engine_grpc
- from: inventory_grpc
to: rule_engine_grpc
Benefits:
- β 70% less code - Graph definition moves from code to YAML
- β No recompile - Change workflows without rebuilding
- β Multiple workflows - Easy to create variants (urgent, standard, approval)
- β Better readability - Clear, declarative graph structure
- β Easy testing - Test with different configurations
Usage:
// Default config
executor.execute.await?;
// Custom workflow
executor.execute_with_config.await?;
Documentation: See YAML_CONFIGURATION_SUMMARY.md
Microservices Communication Flow
After v0.8.0 refactor, the Orchestrator now uses rust-logic-graph's Graph/Executor pattern to coordinate microservices:
- The Orchestrator receives a purchasing request (HTTP) and creates a Graph with 6 custom gRPC Nodes.
- Each Node wraps a gRPC call to a service:
OmsGrpcNode,InventoryGrpcNode,SupplierGrpcNode,UomGrpcNode,RuleEngineGrpcNode,PoGrpcNode. - The Executor runs the graph in topological order:
- Data Collection Phase (parallel): OMS, Inventory, Supplier, UOM nodes execute simultaneously via gRPC
- Rule Evaluation Phase: RuleEngineGrpcNode waits for all data, then evaluates GRL rules
- Execution Phase: PoGrpcNode creates/sends PO based on rule decisions
- All business logic (decision flags, calculations) comes from GRL rules. The Orchestrator is a pure executor.
Graph Topology:
OMS Node βββββ
β
Inventory ββββΌβββ RuleEngine Node βββ PO Node
β
Supplier βββββ€
β
UOM Node βββββ
Benefits of Graph/Executor Pattern:
- β Declarative: Define workflow as nodes + edges instead of imperative code
- β Parallel Execution: Data nodes run concurrently automatically
- β Type Safety: Custom Node implementations with Rust's type system
- β Testable: Each node can be tested in isolation
- β Consistent: Same pattern used in monolithic and microservices
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (HTTP REST) β
ββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β POST /purchasing/flow
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Orchestrator Service (Port 8080) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β rust-logic-graph Graph Executor β β
β β β β
β β Creates Graph with 6 gRPC Nodes: β β
β β β’ OmsGrpcNode β gRPC to OMS :50051 β β
β β β’ InventoryGrpcNode β gRPC to Inventory :50052 β β
β β β’ SupplierGrpcNode β gRPC to Supplier :50053 β β
β β β’ UomGrpcNode β gRPC to UOM :50054 β β
β β β’ RuleEngineGrpcNode β gRPC to Rules :50055 β β
β β β’ PoGrpcNode β gRPC to PO :50056 β β
β β β β
β β Graph Topology: β β
β β OMS ββββββββ β β
β β Inventory ββΌββ RuleEngine βββ PO β β
β β Supplier βββ€ β β
β β UOM ββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββΌβββββββββββββββββββ¬βββββββββββββββββ¬βββββββββββββββ
β (Parallel) β (Parallel) β (Parallel) β (Parallel) β
βΌ βΌ βΌ βΌ β
ββββββββββββ ββββββββββββββ βββββββββββββββ βββββββββββββ β
βOMS :50051β βInventory β βSupplier β βUOM :50054 β β
β β β:50052 β β:50053 β β β β
ββ’ History β ββ’ Levels β ββ’ Pricing β ββ’ Convert β β
ββ’ Demand β ββ’ Available β ββ’ Lead Time β ββ’ Factors β β
ββββββ¬ββββββ βββββββ¬βββββββ ββββββββ¬βββββββ βββββββ¬ββββββ β
β β β β β
ββββββββββββββββ΄βββββββββββββββββ΄ββββββββββββββββ β
β β
β Data stored in Graph Context β
βΌ β
βββββββββββββββββββ β
β Rule Engine β (Port 50055 - gRPC) β
β :50055 β β
β β β
β β’ GRL Rules β β’ Evaluates 15 rules β
β β’ Calculations β β’ Returns decision flags β
β β’ Decision Flagsβ β’ NO side effects β
ββββββββββ¬βββββββββ β
β β
β Flags stored in Graph Context β
βΌ β
βββββββββββββββββββ β
β PO Service β (Port 50056 - gRPC) β
β :50056 ββββββββββββββββββββββββββββββββ
β β
β β’ Create PO β β’ Reads flags from context
β β’ Send to β β’ Executes based on rules
β Supplier β β’ Email/API delivery
βββββββββββββββββββ
Note: The Rule Engine service returns decision flags and calculations to the Graph Context. The PoGrpcNode then reads these flags from the context to determine whether to create/send the PO.
Where rust-logic-graph is Used
Monolithic App (case_study/monolithic/):
- Uses
Graph,Executor, and customNodeimplementations - 6 DB nodes query local MySQL databases directly
RuleEngineNodecalls in-processRuleEngine- Single process, no network calls
Orchestrator Microservice (case_study/microservices/services/orchestrator-service/):
- Uses
Graph,Executor, and custom gRPCNodeimplementations - 6 gRPC nodes make network calls to remote services
- Same graph topology as monolithic
- Distributed across multiple processes
Rule Engine Service (case_study/microservices/services/rule-engine-service/):
- Uses
RuleEnginefor GRL evaluation - Exposed via gRPC endpoint
- Stateless service (no graph execution)
Other Microservices (OMS, Inventory, Supplier, UOM, PO):
- Standard gRPC services with database access
- Do NOT use rust-logic-graph directly
- Called by Orchestrator's Graph Executor
Web Graph Editor (NEW in v0.8.0)
π Online Editor: https://logic-graph-editor.amalthea.cloud/
Try the visual graph editor online - no installation required! Create workflows, define rules, and visualize your logic graphs with drag-and-drop.
CLI Tools (v0.5.0)
# Build the CLI tool
# Validate a graph
# Visualize graph structure
# Profile performance
# Dry-run without execution
Run Examples
# Basic workflow
# GRL rules
# Advanced integration
π Documentation
| Document | Description |
|---|---|
| π’ Case Study: Purchasing Flow | Real production system with microservices & monolithic implementations |
| π YAML Configuration Guide | Declarative graph configuration with YAML (NEW in v0.8.5) |
| Graph Editor Guide | Visual web-based graph editor with Next.js (NEW in v0.8.0) |
| Memory Optimization Guide | Context pooling and allocation tracking (v0.7.0) |
| CLI Tool Guide | Developer tools for validation, profiling, and visualization (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
ποΈ Architecture

π₯ 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;
}
π 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
# Build CLI tool
# Validate graph
# Visualize graph structure
# Profile performance
# Dry-run execution
Test Results: β 32/32 tests passing
Learn more about CLI tools β
π¦ Project Status
Version: 0.8.5 (Latest) Status: Production-ready with YAML configuration, web graph editor, and real-world case study
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)
- β Memory optimization with context pooling (v0.7.0)
- β CLI Developer Tools - validate, profile, visualize, dry-run (v0.5.0)
- β Web Graph Editor - Next.js visual editor with drag-and-drop (v0.8.0)
- β Production Case Study - Purchasing flow with microservices & monolithic (v0.8.0)
- β YAML Configuration - Declarative graph definitions (v0.8.5)
- β 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 β
- Memory Optimization (v0.7.0) - COMPLETED β
- Web Graph Editor (v0.8.0) - COMPLETED β
- Production Case Study (v0.8.0) - COMPLETED β
- YAML Configuration (v0.8.5) - COMPLETED β
- GraphQL API (v0.9.0)
- Production release (v1.0.0)
See ROADMAP.md for details
π€ Contributing
Contributions welcome! Please:
- Fork the repository
- Create your feature branch
- Write tests for new features
- 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.8.5 (2025-11-20) - YAML Configuration Release
New Features:
- π YAML Configuration Support - Declarative graph definitions
- Load graph structure from YAML files instead of hardcoded
GraphConfigmodule for parsing YAML configurations- Support for both JSON and YAML formats
- 70% code reduction in graph executors
- See YAML Configuration Guide
- π§ Enhanced Graph Executor API
execute()- Use default configurationexecute_with_config(config_path)- Load custom YAML config- Dynamic node registration from config
- π Multiple Workflow Support
- Standard flow (full process)
- Simplified flow (skip optional steps)
- Urgent flow (fast-track)
- Easy to create custom workflows
- π Comprehensive Documentation
- YAML configuration guide with examples
- Before/After comparison showing improvements
- Multiple workflow examples
- Integration guides for both architectures
Improvements:
- Monolithic and Microservices both support YAML configs
- Reduced boilerplate code by 70% in executors
- Better separation of concerns (config vs. code)
- Easier testing with multiple configurations
- No recompilation needed for workflow changes
Examples:
# purchasing_flow_graph.yaml
nodes:
oms_grpc:
type: DBNode
description: "Fetch OMS data"
rule_engine_grpc:
type: RuleNode
dependencies:
edges:
- from: oms_grpc
to: rule_engine_grpc
// Use default config
executor.execute.await?;
// Use custom config
executor.execute_with_config.await?;
Compatibility:
- All tests passing
- API backward compatible
- Existing hardcoded graphs still work
v0.8.0 (2025-11-20) - Web Editor & Production Case Study Release
New Features:
- π¨ Web Graph Editor - Next.js visual editor with drag-and-drop
- Online version: https://logic-graph-editor.amalthea.cloud/
- React Flow-based graph visualization
- Real-time node editing and validation
- Export/import JSON workflows
- See Graph Editor Guide
- π’ Production Case Study - Complete purchasing flow system
- Microservices architecture (7 services with gRPC)
- Monolithic architecture (single HTTP service)
- 15 GRL business rules for purchasing decisions
- Kubernetes deployment manifests
- Docker Compose for local development
- Shared GRL rules proving portability
- See Case Study Documentation
Improvements:
- Updated README with case study section
- Added online graph editor link
- Comprehensive production examples
Compatibility:
- All tests passing
- API backward compatible
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 (
rlgbinary)- 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.rswith 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
- Repository: https://github.com/KSD-CO/rust-logic-graph
- rust-rule-engine: https://crates.io/crates/rust-rule-engine
- Documentation: docs/
- Issues: GitHub Issues
π₯ Authors
James Vu - Initial work
π Acknowledgments
Built with:
- rust-rule-engine v0.14.0 - GRL support with RETE-UL
- Tokio - Async runtime
- Petgraph - Graph algorithms
- Serde - Serialization
- Clap - CLI framework
β Star us on GitHub if you find this useful! β
Documentation β’ Examples β’ Use Cases β’ YAML Config Guide