rust-logic-graph 0.3.0

A modular reasoning graph framework for distributed logic orchestration
Documentation
# ๐Ÿง  Rust Logic Graph

[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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

| Document | Description |
|----------|-------------|
| **[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

| 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 (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>