๐ง 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.17
- ๐ 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)
- ๐ฏ Advanced Control Flow - Subgraphs, conditionals, loops, error handling (v0.9.0) ๐
- ๐ Multiple Node Types - RuleNode, DBNode, AINode, ConditionalNode, LoopNode, TryCatchNode, RetryNode, CircuitBreakerNode
- ๐ 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.9.0"
# With specific integrations
= { = "0.9.0", = ["postgres", "openai"] }
# With all integrations
= { = "0.9.0", = ["all-integrations"] }
๐ข 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
The purchasing flow system demonstrates the same business logic implemented in two different architectures - showcasing rust-logic-graph's flexibility for different deployment scenarios.
Architecture Comparison: Pros, Cons & Use Cases
| Aspect | ๐ข Monolithic | ๐ Microservices |
|---|---|---|
| โ Advantages | โข Fast development - Single codebase, quick iterationsโข Low latency - In-process calls (~10ms)โข Simple deployment - Single binaryโข Easy debugging - Single process, simple logsโข Low cost - ~50MB RAM, 1 CPUโข YAML flexibility - Change workflows without rebuild | โข Horizontal scaling - Scale services independentlyโข Team autonomy - Separate service ownershipโข Fault isolation - Service failure โ system failureโข Tech flexibility - Different languages per serviceโข Independent deploys - Update without full restartโข Production proven - Battle-tested at scale |
| โ Disadvantages | โข Vertical scaling only - Limited by single machineโข Single point of failure - Process crash = full outageโข Tight coupling - All code in one repoโข Resource competition - Services share CPU/RAMโข Deployment risk - One deploy affects everything | โข Network overhead - gRPC calls (~56ms, 5.6x slower)โข Complex setup - Docker, K8s, service meshโข High resource usage - ~500MB RAM, 7 containersโข Debugging complexity - Distributed tracing neededโข Development friction - Slower build/test cyclesโข Infrastructure cost - More servers required |
| ๐ฏ Best Use Cases | โ Startups - MVP, validate quicklyโ Small teams (1-5 devs)โ Low-medium traffic (<1K req/min)โ Cost-sensitive projectsโ Frequent changes - Business logic evolvesโ Simple ops - Limited DevOps resources | โ High scale (>10K req/min)โ Large teams (15+ devs, multiple teams)โ Critical uptime - 99.99% SLAโ Independent services - Different release cyclesโ Polyglot needs - Mix languages/frameworksโ Regulatory - Service isolation required |
| โ ๏ธ Anti-patterns | โ Don't use if:โข Need >10K requests/minโข Team >15 developersโข Services need independent scalingโข Require 99.99% uptime | โ Don't use if:โข Team <5 developersโข Traffic <1K requests/minโข Premature optimizationโข No DevOps expertise |
| ๐๏ธ Architecture | Single HTTP service (Port 8080)4 PostgreSQL DBs (multi-database)YAML-driven graph execution | 7 services (gRPC + HTTP)4 PostgreSQL DBs (service-owned)Hardcoded gRPC graph topology |
| ๐ Performance | ~10ms latency (in-process)~50MB RAM, 1 CPU core | ~56ms latency (network calls)~500MB RAM, 7 containers |
When to Use Each Architecture
โ Use Monolithic When:
- ๐ Early stage startup - Fast iteration, quick deployments
- ๐ฐ Limited resources - Small team, limited infrastructure budget
- ๐ Low-medium traffic - <1000 requests/minute
- ๐ฏ MVP/Prototype - Need to validate business logic quickly
- ๐ ๏ธ Simple operations - Single deployment, easy monitoring
- ๐ฅ Small team - 1-5 developers, full-stack ownership
- ๐ง Frequent changes - Business logic changes often, need flexibility
- ๐ต Cost-sensitive - Minimize cloud costs, fewer resources
Monolithic Example (Port 8080):
โ Use Microservices When:
- ๐ High scale - >10,000 requests/minute, need horizontal scaling
- ๐ฅ Large team - Multiple teams, service ownership per team
- ๐ง Independent deployments - Deploy services independently
- ๐ก๏ธ Fault isolation - Service failure shouldn't crash entire system
- ๐ Polyglot needs - Different services in different languages
- ๐ Different SLAs - Critical services need higher availability
- ๐ Complex monitoring - Distributed tracing, service mesh
- ๐ฐ Budget for infrastructure - Can afford Kubernetes, service mesh
Microservices Example (7 Services):
Migration Path: Start Monolithic โ Scale to Microservices
-
Phase 1: Start Monolithic
- Build and validate business logic
- Use YAML config for flexibility
- Deploy single binary
-
Phase 2: Extract Critical Services
- Identify bottlenecks (e.g., Rule Engine)
- Extract to separate service
- Keep rest monolithic
-
Phase 3: Full Microservices
- Split all services when scale demands
- Add service mesh, observability
- Use Kubernetes for orchestration
Both implementations use:
- โ
Same GRL business rules (15 rules in
purchasing_rules.grl) - โ Same graph topology (OMS โ Inventory โ Supplier โ UOM โ RuleEngine โ PO)
- โ rust-logic-graph's Graph/Executor pattern
- โ Clean architecture principles
๐ฅ 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 support YAML-based graph configuration, but with different approaches:
Monolithic YAML Example (purchasing_flow_graph.yaml):
nodes:
oms_history:
type: DBNode
database: "oms_db" # Multi-database routing
query: "SELECT product_id, avg_daily_demand::float8, trend FROM oms_history WHERE product_id = $1"
inventory_levels:
type: DBNode
database: "inventory_db"
query: "SELECT product_id, available_qty::float8, reserved_qty::float8 FROM inventory WHERE product_id = $1"
rule_engine:
type: RuleNode
description: "Evaluate business rules with dynamic field mapping"
dependencies:
- oms_history
- inventory_levels
- supplier_info
- uom_conversion
field_mappings: # Dynamic field extraction (NEW)
avg_daily_demand: "oms_history.avg_daily_demand"
available_qty: "inventory_levels.available_qty"
lead_time: "supplier_info.lead_time"
moq: "supplier_info.moq"
create_po:
type: RuleNode
dependencies:
- rule_engine
field_mappings:
should_order: "rule_engine.should_order"
recommended_qty: "rule_engine.recommended_qty"
product_id: "supplier_info.product_id"
edges:
- from: oms_history
to: rule_engine
- from: inventory_levels
to: rule_engine
- from: rule_engine
to: create_po
Microservices YAML Example (purchasing_flow_graph.yaml):
nodes:
oms_grpc:
type: GrpcNode
query: "http://localhost:50051#GetOrderHistory"
description: "Fetch order management data via gRPC"
inventory_grpc:
type: GrpcNode
query: "http://localhost:50052#GetInventoryLevels"
description: "Fetch inventory levels via gRPC"
supplier_grpc:
type: GrpcNode
query: "http://localhost:50053#GetSupplierInfo"
description: "Fetch supplier information via gRPC"
uom_grpc:
type: GrpcNode
query: "http://localhost:50054#ConvertUnits"
description: "Fetch UOM conversions via gRPC"
rule_engine_grpc:
type: RuleNode
description: "Evaluate business rules"
dependencies:
- oms_grpc
- inventory_grpc
- supplier_grpc
- uom_grpc
po_grpc:
type: RuleNode
description: "Create purchase order"
dependencies:
- rule_engine_grpc
edges:
- from: oms_grpc
to: rule_engine_grpc
- from: inventory_grpc
to: rule_engine_grpc
- from: supplier_grpc
to: rule_engine_grpc
- from: uom_grpc
to: rule_engine_grpc
- from: rule_engine_grpc
to: po_grpc
Key Differences:
| Feature | Monolithic YAML | Microservices YAML |
|---|---|---|
| Node Type | DBNode (direct SQL) |
GrpcNode (service calls) |
| Query | SQL queries | gRPC endpoint URLs |
| Database Routing | database: "oms_db" |
No database (delegates to services) |
| Field Mappings | โ Dynamic via YAML | โ Hardcoded in Node implementations |
| Flexibility | 100% config-driven | Hybrid (topology in YAML, logic in code) |
Benefits:
- โ 70% less code - Graph definition moves from Rust to YAML
- โ No recompile - Change workflows without rebuilding
- โ Dynamic field mapping (Monolithic only) - Zero hardcoded field names
- โ Multi-database routing (Monolithic only) - Each node specifies its database
- โ Service URLs (Microservices only) - Configure gRPC endpoints
- โ Better readability - Clear, declarative graph structure
- โ Easy testing - Test with different configurations
Key Architecture Differences:
| Aspect | Monolithic | Microservices |
|---|---|---|
| Service Count | 1 service | 7 services (Orchestrator, OMS, Inventory, Supplier, UOM, RuleEngine, PO) |
| Ports | Single port 8080 | Orchestrator: 8080, Services: 50051-50056 (gRPC) |
| Database Access | Direct SQL queries to 4 DBs | gRPC calls to service APIs |
| Field Mapping | YAML field_mappings config |
Hardcoded in gRPC node implementations |
| Rule Engine | In-process RuleEngine call | gRPC to rule-engine-service :50055 |
| Communication | Function calls (0 network) | gRPC (network overhead) |
| Graph Executor | PurchasingGraphExecutor |
OrchestratorExecutor with gRPC nodes |
| Node Types | DynamicDBNode, DynamicRuleNode |
OmsGrpcNode, InventoryGrpcNode, etc. |
| Configuration | 100% YAML-driven | Partially hardcoded gRPC contracts |
| Flexibility | Change workflow via YAML only | Need code changes for new services |
| Dependencies | rust-logic-graph + sqlx | rust-logic-graph + tonic + prost |
| Deployment | cargo run or single binary |
docker compose up (11 containers) |
| Development | Hot reload, fast compile | Rebuild multiple containers |
| Production Ready | โ Yes (single binary) | โ Yes (Docker/K8s) |
Example Response Time Comparison:
Monolithic (in-process):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP Request โ Graph Executor โ ~2ms
โ โโ DB Query (oms_db) โ ~1ms
โ โโ DB Query (inventory_db) โ ~1ms
โ โโ DB Query (supplier_db) โ ~1ms
โ โโ DB Query (uom_db) โ ~1ms
โ โโ Rule Engine (in-process) โ ~2ms
โ โโ Create PO (in-process) โ ~2ms
โ Total: ~10ms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Microservices (network calls):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP Request โ Orchestrator โ ~2ms
โ โโ gRPC OMS Service (50051) โ ~8ms (network + DB)
โ โโ gRPC Inventory (50052) โ ~8ms (network + DB)
โ โโ gRPC Supplier (50053) โ ~8ms (network + DB)
โ โโ gRPC UOM (50054) โ ~8ms (network + DB)
โ โโ gRPC Rule Engine (50055) โ ~12ms (network + rules)
โ โโ gRPC PO Service (50056) โ ~10ms (network + create)
โ Total: ~56ms (5.6x slower) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Trade-offs Summary:
| Consideration | Monolithic Wins | Microservices Wins |
|---|---|---|
| Performance | โ 5-10x faster | โ Network overhead |
| Simplicity | โ Single process | โ Complex setup |
| Resource Usage | โ ~50MB RAM | โ ~500MB RAM |
| Development Speed | โ Faster iteration | โ Slower builds |
| Scalability | โ Vertical only | โ Horizontal scale |
| Team Autonomy | โ Shared codebase | โ Independent teams |
| Fault Isolation | โ Single point of failure | โ Service isolation |
| Deployment | โ Single binary | โ Multi-container |
| Monitoring | โ Simple logs | โ Distributed tracing |
| Cost | โ Lower infra cost | โ Higher infra cost |
Real-World Recommendation:
Traffic Level | Recommended Architecture
-----------------------|-------------------------
< 100 req/min | Monolithic (overkill to use microservices)
100-1,000 req/min | Monolithic (scales easily vertically)
1,000-10,000 req/min | Monolithic or Hybrid (extract bottlenecks)
> 10,000 req/min | Microservices (horizontal scaling needed)
Team Size | Recommended Architecture
-----------------------|-------------------------
1-5 developers | Monolithic (single codebase)
5-15 developers | Monolithic or Hybrid
15-50 developers | Microservices (team per service)
> 50 developers | Microservices (clear boundaries)
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 /api/purchasing/flow
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Orchestrator Service (Port 8080) - main.rs โ
โ โ
โ HTTP Endpoint โ OrchestratorGraphExecutor โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ rust-logic-graph Graph Executor โ โ
โ โ (graph_executor.rs) โ โ
โ โ โ โ
โ โ Creates Graph with 6 Custom gRPC Nodes: โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ OmsGrpcNode โ โ โ
โ โ โ โข impl Node trait from rust-logic-graph โ โ โ
โ โ โ โข async fn run() โ gRPC call to :50051 โ โ โ
โ โ โ โข Returns JSON to Context โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ InventoryGrpcNode โ gRPC :50052 โ โ โ
โ โ โ SupplierGrpcNode โ gRPC :50053 โ โ โ
โ โ โ UomGrpcNode โ gRPC :50054 โ โ โ
โ โ โ RuleEngineGrpcNode โ gRPC :50056 โ โ โ
โ โ โ PoGrpcNode โ gRPC :50055 โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โ Graph Topology (hardcoded in graph_executor.rs): โ โ
โ โ OMS โโโโโโโโ โ โ
โ โ Inventory โโผโโ RuleEngine โโโ PO โ โ
โ โ Supplier โโโค โ โ
โ โ UOM โโโโโโโโ โ โ
โ โ โ โ
โ โ Executor runs in topological order โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ (Parallel) โ (Parallel) โ (Parallel) โ (Parallel) โ
โผ โผ โผ โผ โ
โโโโโโโโโโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โOMS :50051โ โInventory โ โSupplier โ โUOM :50054 โ โ
โ (gRPC) โ โ:50052 โ โ:50053 โ โ (gRPC) โ โ
โ โ โ (gRPC) โ โ (gRPC) โ โ โ โ
โโข History โ โโข Levels โ โโข Pricing โ โโข Convert โ โ
โโข Demand โ โโข Available โ โโข Lead Time โ โโข Factors โ โ
โ โ โ โ โโข MOQ โ โ โ โ
โโโโโโฌโโโโโโ โโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโฌโโโโโโ โ
โ โ โ โ โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ โ
โ โ
โ Data stored in Graph Context โ
โผ โ
โโโโโโโโโโโโโโโโโโโ โ
โ Rule Engine โ (Port 50056 - gRPC) โ
โ :50056 โ โ
โ (gRPC) โ โ
โ โ โ
โ โข Loads GRL โ โข Evaluates 15 rules โ
โ rules from โ โข Returns decision flags โ
โ .grl file โ โข NO side effects โ
โ โข Pure function โ โข Calculations + flags โ
โโโโโโโโโโฌโโโโโโโโโ โ
โ โ
โ Flags stored in Graph Context โ
โผ โ
โโโโโโโโโโโโโโโโโโโ โ
โ PO Service โ (Port 50055 - gRPC) โ
โ :50055 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (gRPC) โ
โ โ
โ โข Create PO โ โข Reads flags from context
โ โข Send to โ โข Executes based on rules
โ Supplier โ โข Email/API delivery
โโโโโโโโโโโโโโโโโโโ
Note: The Orchestrator uses rust-logic-graph's Graph/Executor pattern - each gRPC service call is wrapped in a custom Node implementation. The Rule Engine returns decision flags to the Graph Context, and the PoGrpcNode reads these flags to determine whether to create/send the PO.
Where rust-logic-graph is Used
Monolithic App (case_study/monolithic/):
- Uses
Graph,Executor, and customNodeimplementations - Multi-database architecture: 4 separate PostgreSQL databases (oms_db, inventory_db, supplier_db, uom_db)
- Dynamic field mapping: YAML-configured field extraction with zero hardcoded field names
- Config-driven nodes:
DynamicDBNodeandDynamicRuleNoderead behavior from YAML - Database routing via
databasefield in YAML (e.g.,database: "oms_db") - Field mappings via
field_mappingsin YAML (e.g.,avg_daily_demand: "oms_history.avg_daily_demand") RuleEngineServiceacceptsHashMap<String, Value>for complete flexibility- Graph structure defined in
purchasing_flow_graph.yaml - 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
Architecture Highlights:
Monolithic Clean Architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP REST API (Port 8080) โ
โ POST /purchasing/flow {product_id} โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PurchasingGraphExecutor (executors/graph_executor.rs) โ
โ (Clean Architecture) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ rust-logic-graph Graph/Executor Engine โ โ
โ โ โ โ
โ โ execute_with_config(product_id, "purchasing_flow.yaml") โ โ
โ โ โ โ
โ โ 1. GraphConfig::from_yaml_file("purchasing_flow.yaml") โ โ
โ โ 2. Parse nodes + edges + field_mappings โ โ
โ โ 3. For each node in YAML: โ โ
โ โ โข Create DynamicDBNode (with database routing) โ โ
โ โ โข Create DynamicRuleNode (with field_mappings) โ โ
โ โ 4. Register all nodes to Executor โ โ
โ โ 5. Execute graph in topological order โ โ
โ โ โ โ
โ โ Graph Topology (from YAML): โ โ
โ โ oms_history โโโโโโโโโ โ โ
โ โ inventory_levels โโโโผโโโ rule_engine โโโ create_po โ โ
โ โ supplier_info โโโโโโโค โ โ
โ โ uom_conversion โโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ (Parallel DBs) โ (Parallel DBs) โ (Parallel DBs) โ (Parallel)โ
โผ โผ โผ โผ โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ oms_db โ โ inventory_db โ โ supplier_db โ โ uom_db โ โ
โ PostgreSQL โ โ PostgreSQL โ โ PostgreSQL โ โ PostgreSQL โ โ
โ :5433 โ โ :5434 โ โ :5435 โ โ :5436 โ โ
โ โ โ โ โ โ โ โ โ
โ โข history โ โ โข levels โ โ โข info โ โ โข conversion โ โ
โ โข demand โ โ โข available โ โ โข pricing โ โ โข factors โ โ
โ โข trends โ โ โข reserved โ โ โข lead_time โ โ โ โ
โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ
โ โ โ โ โ
โ DynamicDBNode โ DynamicDBNode โ DynamicDBNode โ Dynamic โ
โ database:"oms" โ database:"inv" โ database:"sup" โ DB Node โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
โ
Data stored in Graph Context
with path notation (e.g., "oms_history.avg_daily_demand")
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DynamicRuleNode (rule_engine) โ
โ โ
โ YAML field_mappings config: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ avg_daily_demand: โ โ
โ โ "oms_history.avg_daily_demand" โ โ
โ โ available_qty: โ โ
โ โ "inventory_levels.available_qty" โ โ
โ โ lead_time: โ โ
โ โ "supplier_info.lead_time" โ โ
โ โ ... (9 total mappings) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ extract_rule_inputs() loop: โ
โ โข Reads field_mappings from YAML โ
โ โข Uses get_value_by_path() for parsing โ
โ โข Returns HashMap<String, Value> โ
โ โข ZERO hardcoded field names! โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ RuleEngineService (In-Process) โ
โ โ
โ evaluate(HashMap<String, Value>) โ
โ โ
โ โข Loads purchasing_rules.grl โ
โ โข 15 business rules (GRL) โ
โ โข Accepts dynamic HashMap input โ
โ โข No struct, no hardcoded fields โ
โ โข Pure functional evaluation โ
โ โ
โ Rules calculate: โ
โ โ shortage = required_qty - available โ
โ โ order_qty (respects MOQ) โ
โ โ total_amount with discounts โ
โ โ requires_approval flag โ
โ โ should_create_po flag โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Decision flags returned to Context
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DynamicRuleNode (create_po) โ
โ โ
โ YAML field_mappings config: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ should_order: โ โ
โ โ "rule_engine.should_order" โ โ
โ โ recommended_qty: โ โ
โ โ "rule_engine.recommended_qty" โ โ
โ โ product_id: โ โ
โ โ "supplier_info.product_id" โ โ
โ โ ... (6 total mappings) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โข Reads rule_engine output from context โ
โ โข Dynamic field extraction via YAML โ
โ โข Creates PO if should_order == true โ
โ โข Returns PO JSON or null โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Design Principles:
-
Multi-Database Routing - Each node specifies its database in YAML:
oms_history: database: "oms_db" # Routes to oms_db pool -
Dynamic Field Mapping - Zero hardcoded fields in Rust code:
field_mappings: avg_daily_demand: "oms_history.avg_daily_demand"// Code is 100% generic for in &self.field_mappings -
Config-Driven Execution - Graph structure in YAML, not Rust:
executor.execute_with_config?; -
HashMap-Based RuleEngine - Accepts any fields:
Microservices Communication Flow
- Multi-Database Routing (
graph_executor.rs):
// YAML config specifies database per node
oms_history:
database: "oms_db"
query: "SELECT ..."
// Executor routes to correct pool
let pool = self.get_pool;
- Dynamic Field Mapping (
graph_executor.rs):
// YAML config defines field mappings
field_mappings:
avg_daily_demand: "oms_history.avg_daily_demand"
available_qty: "inventory_levels.available_qty"
// Code extracts dynamically (zero hardcoding)
- Config-Driven RuleEngine (
rule_service.rs):
// Accepts HashMap instead of struct - 100% flexible
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
Advanced Control Flow Usage (v0.9.0) ๐
Conditional Branching
Route execution based on conditions:
use ;
let mut graph = new;
// Add nodes
graph.add_node;
graph.add_node;
graph.add_node;
// Add conditional routing
graph.add_node;
graph.add_edge;
graph.add_edge;
graph.add_edge;
// Execute
let result = graph.execute.await?;
Loops
Iterate over collections or use while loops:
// Foreach loop over products
graph.add_node;
// While loop with condition
graph.add_node;
Error Handling
Try/catch patterns for resilient workflows:
graph.add_node;
Retry Logic
Exponential backoff for transient failures:
graph.add_node;
Circuit Breaker
Fault tolerance for unstable services:
graph.add_node;
Subgraphs
Nested graph execution with input/output mapping:
graph.add_node;
See examples/ for complete working examples.
๐ 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.8 (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
Core 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 |
Advanced Control Flow Examples (v0.9.0) ๐
| Example | Description | Features Demonstrated |
|---|---|---|
conditional_flow.rs |
If/else routing based on conditions | ConditionalNode, branch selection |
loop_flow.rs |
Foreach and while loop patterns | LoopNode, iteration over arrays |
retry_flow.rs |
Exponential backoff retry logic | RetryNode, configurable attempts |
error_handling_flow.rs |
Try/catch/finally patterns | TryCatchNode, error recovery |
circuit_breaker_flow.rs |
Circuit breaker fault tolerance | CircuitBreakerNode, failure thresholds |
subgraph_flow.rs |
Nested graph execution | SubgraphNode, input/output mapping |
Run examples:
# Conditional routing
# Loop over products
# Retry with backoff
# Error handling
# Circuit breaker
# Nested subgraphs
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.9 (2025-11-22) - DBNode Parameters Feature
New Features:
- ๐ง DBNode Context Parameters - Dynamic query parameter extraction
- Extract SQL parameters from execution context
NodeConfig::db_node_with_params()for parameterized queries- Support for
$1,$2(PostgreSQL) and?(MySQL) placeholders - Automatic type conversion (String, Number, Boolean, Null)
- Graceful handling of missing parameters
- See DB Parameters Guide
API Additions:
// Create DBNode with context parameter extraction
db_node_with_params
// Set parameters in context
graph.context.set;
Configuration Support:
nodes:
fetch_user:
node_type: DBNode
query: "SELECT * FROM users WHERE user_id = $1"
params:
- user_id # Extract from context
Testing:
- 7 new integration tests in
tests/db_params_tests.rs - Single/multiple parameter extraction
- Missing parameter handling
- Type conversion tests
- JSON/YAML serialization tests
Documentation:
- Complete guide in
docs/DB_PARAMS.md - Example:
examples/db_params_flow.rs - JSON example:
examples/db_params_graph.json
Compatibility:
- Fully backward compatible
- Existing DBNodes work without changes
- Optional feature (params default to None)
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
- ๐๏ธ Monolithic Clean Architecture (NEW)
- Multi-database architecture with 4 PostgreSQL databases
- Dynamic field mapping via YAML configuration
- Zero hardcoded field names in code
- Database routing per node via config
field_mappingsfor flexible data extractionRuleEngineServiceacceptsHashMap<String, Value>- Config-driven
DynamicDBNodeandDynamicRuleNode
- ๐ Comprehensive Documentation
- YAML configuration guide with examples
- Before/After comparison showing improvements
- Multiple workflow examples
- Integration guides for both architectures
- Clean architecture patterns documentation
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
- Complete flexibility in field naming and mapping
Examples:
# Monolithic with multi-database
nodes:
oms_history:
database: "oms_db"
query: "SELECT ..."
rule_engine:
field_mappings:
avg_daily_demand: "oms_history.avg_daily_demand"
// Dynamic field extraction (no hardcoding)
let inputs = self.extract_rule_inputs;
rule_service.evaluate?; // HashMap<String, Value>
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