# ๐ง Rust Logic Graph
[](https://www.rust-lang.org/)
[](https://opensource.org/licenses/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.
```rust
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](https://crates.io/crates/rust-rule-engine) integration with RETE algorithm
- ๐ **Topological Execution** - Automatic DAG-based node ordering
- โก **Async Runtime** - Built on Tokio for high concurrency
- ๐ **Multiple Node Types** - RuleNode, DBNode, AINode
- ๐ **JSON Configuration** - Simple workflow definitions
- ๐ฏ **97% Drools Compatible** - Easy migration from Java
- ๐ **Streaming Processing** - Stream-based execution with backpressure (NEW in v0.3.0)
- ๐๏ธ **Database Integrations** - PostgreSQL, MySQL, Redis, MongoDB (v0.2.0)
- ๐ค **AI/LLM Integrations** - OpenAI, Claude, Ollama (v0.2.0)
---
## ๐ Quick Start
### Installation
```toml
[dependencies]
rust-logic-graph = "0.2.0"
# With specific integrations
rust-logic-graph = { version = "0.2.0", features = ["postgres", "openai"] }
# With all integrations
rust-logic-graph = { version = "0.2.0", features = ["all-integrations"] }
```
### Simple Example
```rust
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)?;
```
### Run Examples
```bash
# Basic workflow
cargo run --example simple_flow
# GRL rules
cargo run --example grl_rules
# Advanced integration
cargo run --example grl_graph_flow
```
---
## ๐ Documentation
| **[Integrations Guide](docs/INTEGRATIONS.md)** | Database & AI integrations (NEW in v0.2.0) |
| **[GRL Guide](docs/GRL.md)** | Complete GRL syntax and examples |
| **[Use Cases](docs/USE_CASES.md)** | 33+ real-world applications |
| **[Extending](docs/EXTENDING.md)** | Create custom nodes and integrations |
| **[Implementation](docs/IMPLEMENTATION_SUMMARY.md)** | Technical details |
| **[GRL Integration](docs/GRL_INTEGRATION_SUMMARY.md)** | Integration guide |
---
## ๐ฏ 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 โ](docs/USE_CASES.md)**
---
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ rust-rule-engine (GRL) โ
โ RETE Algorithm โข 2-24x Faster โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Rust Logic Graph Core โ
โ โข Graph Definition โ
โ โข Topological Executor โ
โ โข Context Management โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ โ โ
โโโโโผโโโโ โโโโโผโโโโ โโโโโผโโโโ
โ Rule โ โ DB โ โ AI โ
โ Node โ โ Node โ โ Node โ
โโโโโโโโโ โโโโโโโโโ โโโโโโโโโ
```
---
## ๐ฅ GRL Example
```grl
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 โ](docs/GRL.md)**
---
## ๐ Performance
- **RETE Algorithm**: Optimized pattern matching
- **2-24x Faster**: Than alternatives at 50+ rules
- **97% Drools Compatible**: Easy migration path
- **Async by Default**: High concurrency support
---
## ๐งช Testing
```bash
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific example
cargo run --example grl_rules
```
**Result**: โ
14/14 tests passing
---
## ๐ฆ Project Status
**Version**: 0.3.0-dev (In Development)
**Status**: Production-ready with streaming support
### What's Working
- โ
Core graph execution engine
- โ
GRL rule engine integration
- โ
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 (NEW!)
- โ
Stream operators (map, filter, fold)
- โ
Comprehensive documentation
### Roadmap
- [x] Streaming processing (v0.3.0) - COMPLETED
- [ ] Parallel node execution (v0.3.0)
- [ ] Caching layer (v0.3.0)
- [ ] GraphQL API (v0.6.0)
- [ ] Web UI for visualization (v0.7.0)
- [ ] Production release (v1.0.0)
**See [ROADMAP.md](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
| `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 (NEW!)** | 200 |
---
## ๐ 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
---
## ๐ License
MIT License - see [LICENSE](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/](docs/)
- **Issues**: [GitHub Issues](https://github.com/KSD-CO/rust-logic-graph/issues)
---
## ๐ฅ Authors
**James Vu** - Initial work
---
## ๐ Acknowledgments
Built with:
- [rust-rule-engine](https://crates.io/crates/rust-rule-engine) - GRL support
- [Tokio](https://tokio.rs/) - Async runtime
- [Petgraph](https://github.com/petgraph/petgraph) - Graph algorithms
- [Serde](https://serde.rs/) - Serialization
---
<div align="center">
**โญ Star us on GitHub if you find this useful! โญ**
[Documentation](docs/) โข [Examples](examples/) โข [Use Cases](docs/USE_CASES.md)
</div>