High-Performance Domain-Agnostic Rule Engine with AI-Powered Configuration
Configure complex business rules with visual DAG editing, AI assistance, and sub-millisecond execution
https://ayushmaanbhav.github.io/Product-FARM/
Product-FARM (Functionality, Attribute, and Rule Management) is a domain-agnostic rule engine that lets you configure complex business logic without writing code. Whether you're calculating insurance premiums, generating trading signals, or evaluating loan eligibility, Product-FARM provides:
- Visual Rule Builder - Drag-and-drop JSON Logic blocks, no coding required
- AI Assistant - Create rules from natural language descriptions
- Sub-millisecond Execution - 3.5x faster with tiered bytecode compilation
- DAG Visualization - See rule dependencies and execution flow
- Real-time Simulation - Test rules instantly with live feedback
- Features
- Screenshots
- Architecture
- Quick Start
- Use Cases
- Performance
- API Reference
- Testing
- Project Structure
- Contributing
- License
|
|
|
|
┌─────────────────────────────────────────────────────────────────────────────┐
│ PRESENTATION LAYER │
├─────────────────────────────────────────────────────────────────────────────┤
│ React 19 + TypeScript + Vite + TailwindCSS + shadcn/ui │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Dashboard │ │ Rule Canvas │ │ Simulation │ │ AI Assistant │ │
│ │ │ │ (@xyflow) │ │ Panel │ │ (Chat) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │
└────────────────────────────────┬────────────────────────────────────────────┘
│ HTTP/REST (Port 8081)
┌────────────────────────────────▼────────────────────────────────────────────┐
│ API LAYER (Rust) │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌──────────────────────────┐ ┌──────────────────────────┐ │
│ │ REST API (Axum) │ │ gRPC API (Tonic) │ │
│ │ Port: 8081 │ │ Port: 50051 │ │
│ └────────────┬─────────────┘ └────────────┬─────────────┘ │
│ │ │ │
│ ┌────────────▼──────────────────────────────▼─────────────┐ │
│ │ Service Layer │ │
│ │ ProductService │ RuleService │ AttributeService │ ... │ │
│ └────────────────────────────┬────────────────────────────┘ │
└───────────────────────────────┼─────────────────────────────────────────────┘
│
┌───────────────────────────────▼─────────────────────────────────────────────┐
│ CORE ENGINE (Rust) │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
│ │ JSON Logic │ │ Rule Engine │ │ AI Agent │ │
│ │ ┌──────────┐ │ │ ┌──────────┐ │ │ ┌──────────┐ │ │
│ │ │ Parser │ │ │ │DAG Builder│ │ │ │Translator│ │ │
│ │ │ Compiler │ │ │ │Topo Sort │ │ │ │Explainer │ │ │
│ │ │ VM │ │ │ │Executor │ │ │ │Validator │ │ │
│ │ └──────────┘ │ │ └──────────┘ │ │ └──────────┘ │ │
│ └──────────────────┘ └──────────────────┘ └──────────────────┘ │
│ │
│ Performance: Tier 0 (AST) ~1.15µs → Tier 1 (Bytecode) ~330ns (3.5x faster) │
└───────────────────────────────┬─────────────────────────────────────────────┘
│
┌───────────────────────────────▼─────────────────────────────────────────────┐
│ PERSISTENCE LAYER │
├─────────────────────────────────────────────────────────────────────────────┤
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
│ │ DGraph │ │ LRU Cache │ │ File Storage │ │
│ │ (Graph DB) │ │ (Hot Data) │ │ (Development) │ │
│ │ Port: 9080 │ │ │ │ │ │
│ └──────────────────┘ └──────────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Product-FARM uses a tiered compilation strategy for optimal performance:
JSON Logic Expression
│
▼
┌───────────────┐
│ Parser │
│ (JSON → AST) │
└───────┬───────┘
│
┌─────────────┼─────────────┐
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ Tier 0 │ │ Tier 1 │ │ Tier 2 │
│ (AST) │ │(Bytecode│ │ (JIT) │
│ ~1.15µs │ │ ~330ns │ │ Future │
└─────────┘ └─────────┘ └─────────┘
│ │
│ Auto-promote after
│ 100 evaluations
└─────────────┘
Rules are organized into execution levels based on dependencies:
Input Variables
│
▼
┌─────────────────────────────────────┐
│ Level 0 (Parallel) │
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │Rule1│ │Rule2│ │Rule3│ │
│ └──┬──┘ └──┬──┘ └──┬──┘ │
└─────┼────────┼───────┼──────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────┐
│ Level 1 (Parallel) │
│ ┌─────┐ ┌─────┐ │
│ │Rule4│ │Rule5│ │
│ └──┬──┘ └──┬──┘ │
└──────────┼──────────┼───────────────┘
│ │
▼ ▼
┌─────────────────────────────────────┐
│ Level 2 │
│ ┌─────┐ │
│ │Rule6│ │
│ └──┬──┘ │
└───────────────┼─────────────────────┘
│
▼
Final Output
┌─────────────────────────────────────────────────────────────────────────────┐
│ PRODUCT │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ id: "insurance-premium-calculator" │ │
│ │ name: "Life Insurance Premium Calculator" │ │
│ │ status: ACTIVE │ │
│ │ template_type: INSURANCE │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │ │ │
│ │ has_many │ has_many │ uses │
│ ▼ ▼ ▼ │
│ ┌────────────┐ ┌────────────┐ ┌──────────────────────────────┐ │
│ │ RULES │ │ ATTRIBUTES │ │ ABSTRACT ATTRIBUTES │ │
│ │────────────│ │────────────│ │ (Templates) │ │
│ │ base_prem │ │ age │ │──────────────────────────────│ │
│ │ age_factor │ │ coverage │ │ customer_age → Integer │ │
│ │ smoker_adj │ │ smoker │ │ coverage_amount → Currency │ │
│ │ final_prem │ │ premium │ │ is_smoker → Boolean │ │
│ └────────────┘ └────────────┘ └──────────────────────────────┘ │
│ │ │ │
│ │ typed_by │ has_type │
│ ▼ ▼ │
│ ┌────────────┐ ┌──────────────┐ │
│ │ DATATYPES │ │ ENUMERATIONS │ │
│ │────────────│ │──────────────│ │
│ │ Integer │ │ RiskLevel │ │
│ │ Decimal │ │ LOW │ │
│ │ Currency │ │ MEDIUM │ │
│ │ Boolean │ │ HIGH │ │
│ │ String │ │ Status │ │
│ └────────────┘ │ APPROVED │ │
│ │ REJECTED │ │
│ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ PRODUCT LIFECYCLE │
├──────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌──────────────┐ ┌─────────┐ ┌───────────┐ │
│ │ DRAFT │──────►│ PENDING │──────►│ ACTIVE │──────►│DISCONTINUED│ │
│ │ │ │ APPROVAL │ │ │ │ │ │
│ └─────────┘ └──────────────┘ └─────────┘ └───────────┘ │
│ │ │ │ │ │
│ │ │ │ │ │
│ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐ │
│ │• Create │ │• Submit │ │• Approve│ │• Archive│ │
│ │• Edit │ │• Review │ │• Deploy │ │• Retire │ │
│ │• Test │ │• Comment│ │• Monitor│ │ │ │
│ │• Simulate │• Reject │ │• Update │ │ │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
│ │ │
│ │ (rejected) │
│ ▼ │
│ Back to DRAFT │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ SUPPORTED JSON LOGIC OPERATIONS │
├──────────────────────────────────────────────────────────────────────────────┤
│ │
│ ARITHMETIC COMPARISON LOGIC DATA ACCESS │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ + add │ │ == equals │ │ and │ │ var │ │
│ │ - subtract│ │ != not eq │ │ or │ │ missing │ │
│ │ * multiply│ │ < less │ │ ! not │ │ missing_ │ │
│ │ / divide │ │ <= less eq │ │ !! truthy │ │ some │ │
│ │ % modulo │ │ > greater │ │ if/else │ │ │ │
│ │ min │ │ >= greater │ │ │ │ │ │
│ │ max │ │ eq │ │ │ │ │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
│ │
│ ARRAY STRING TYPE SPECIAL │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ map │ │ cat concat │ │ typeof │ │ log debug │ │
│ │ filter │ │ substr │ │ coerce │ │ throw err │ │
│ │ reduce │ │ in contains│ │ │ │ │ │
│ │ all │ │ │ │ │ │ │ │
│ │ some │ │ │ │ │ │ │ │
│ │ none │ │ │ │ │ │ │ │
│ │ merge │ │ │ │ │ │ │ │
│ │ in member │ │ │ │ │ │ │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
- Rust 1.75+ (rustup.rs)
- Node.js 20+ (nodejs.org)
- DGraph v25 (included in
infrastructure/)
# Clone the repository
git clone https://github.com/ayushmaanbhav/product-farm.git
cd product-farm
# Start all services (DGraph, Backend, Frontend)
./start-all.shServices will be available at:
- Frontend: http://localhost:5173
- Backend REST: http://localhost:8081
- Backend gRPC: localhost:50051
- DGraph: http://localhost:8080
# Terminal 1: Start DGraph
cd infrastructure
./dgraph zero --my=localhost:5080 &
./dgraph alpha --my=localhost:7080 --zero=localhost:5080 &
# Terminal 2: Start Backend
cd backend
cargo run -p product-farm-api -- 8081
# Terminal 3: Start Frontend
cd frontend
npm install
npm run dev- Open http://localhost:5173
- Click "New Product" → "From Scratch"
- Name it
my-first-product - Go to Rules tab
- Click "New Rule"
- Use the block editor to create:
{"*": [{"var": "price"}, {"var": "quantity"}]} - Click "Simulate" and enter:
{"price": 10, "quantity": 5} - See the result:
50
Configure insurance products with complex pricing rules:
┌─────────────────────────────────────────────────────────────┐
│ INSURANCE PRODUCT │
├─────────────────────────────────────────────────────────────┤
│ │
│ Inputs: Rules: │
│ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ customer_age: 65│ │ base_premium = │ │
│ │ coverage: 250000│ ──► │ coverage × 0.02 │ │
│ │ smoker: false │ │ │ │
│ └─────────────────┘ │ age_factor = │ │
│ │ if(age > 60) 1.2 else 1 │ │
│ │ │ │
│ │ smoker_factor = │ │
│ Output: │ if(smoker) 1.5 else 1 │ │
│ ┌─────────────────┐ │ │ │
│ │ premium: $6,000 │ ◄── │ premium = base × age × │ │
│ └─────────────────┘ │ smoker │ │
│ └──────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
JSON Logic Rules:
// Rule 1: Base Premium
{"*": [{"var": "coverage"}, 0.02]}
// Rule 2: Age Factor
{"if": [{">": [{"var": "age"}, 60]}, 1.2, 1.0]}
// Rule 3: Smoker Factor
{"if": [{"var": "smoker"}, 1.5, 1.0]}
// Rule 4: Final Premium
{"*": [{"var": "base_premium"}, {"var": "age_factor"}, {"var": "smoker_factor"}]}Build algorithmic trading strategies:
┌─────────────────────────────────────────────────────────────┐
│ TRADING STRATEGY │
├─────────────────────────────────────────────────────────────┤
│ │
│ Market Data: Signal Rules: │
│ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ rsi_14: 28 │ │ oversold = rsi < 30 │ │
│ │ price: 150 │ ──► │ above_trend = price > sma │ │
│ │ sma_50: 145 │ │ │ │
│ └─────────────────┘ │ entry_signal = │ │
│ │ if(oversold AND │ │
│ │ above_trend) │ │
│ Signal Output: │ "BUY" │ │
│ ┌─────────────────┐ │ else │ │
│ │ signal: "BUY" │ ◄── │ "HOLD" │ │
│ └─────────────────┘ └──────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Evaluate loan applications with multiple criteria:
┌─────────────────────────────────────────────────────────────┐
│ LOAN ELIGIBILITY │
├─────────────────────────────────────────────────────────────┤
│ │
│ Application: Eligibility Rules: │
│ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ credit: 720 │ │ score_ok = credit >= 680 │ │
│ │ income: 75000 │ ──► │ income_ok = income >= 50k │ │
│ │ debt_ratio: 0.3 │ │ debt_ok = ratio <= 0.4 │ │
│ └─────────────────┘ │ │ │
│ │ eligible = score_ok AND │ │
│ Decision: │ income_ok AND │ │
│ ┌─────────────────┐ │ debt_ok │ │
│ │ eligible: true │ ◄── │ │ │
│ └─────────────────┘ └──────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
| Operation | Time | Notes |
|---|---|---|
| Simple arithmetic (cached) | ~300ns | Bytecode compiled |
| Complex condition (5 branches) | ~18µs | Full evaluation |
| Insurance premium (5 rules) | ~7.8µs | DAG execution |
| Trading strategy (10 rules) | ~19µs | With dependencies |
| 50-rule chain | ~347µs | Sequential chain |
| Tier | Evaluation Time | Speedup |
|---|---|---|
| Tier 0 (AST Interpretation) | ~1.15µs | Baseline |
| Tier 1 (Bytecode VM) | ~330ns | 3.5x faster |
| RuleCache (auto-promoted) | ~366ns | ~3.1x faster |
# JSON Logic benchmarks
cd backend
cargo bench -p product-farm-json-logic
# Rule engine benchmarks
cargo bench -p product-farm-rule-engine| Endpoint | Method | Description |
|---|---|---|
/api/products |
GET, POST | List/create products |
/api/products/{id} |
GET, PUT, DELETE | Product CRUD |
/api/products/{id}/rules |
GET, POST | List/create rules |
/api/products/{id}/evaluate |
POST | Evaluate rules |
/api/products/{id}/batch-evaluate |
POST | Batch evaluation |
/api/abstract-attributes |
GET, POST | Attribute templates |
/api/datatypes |
GET, POST | Custom datatypes |
/api/enumerations |
GET, POST | Enum definitions |
service ProductFarmService {
rpc Evaluate(EvaluateRequest) returns (EvaluateResponse);
rpc BatchEvaluate(BatchEvaluateRequest) returns (BatchEvaluateResponse);
rpc ValidateRules(ValidateRulesRequest) returns (ValidateRulesResponse);
rpc GetExecutionPlan(GetExecutionPlanRequest) returns (ExecutionPlanResponse);
}
service ProductService {
rpc CreateProduct(CreateProductRequest) returns (Product);
rpc GetProduct(GetProductRequest) returns (Product);
rpc ListProducts(ListProductsRequest) returns (ListProductsResponse);
}curl -X POST http://localhost:8081/api/products/my-product/evaluate \
-H "Content-Type: application/json" \
-d '{
"inputs": {
"price": 100,
"quantity": 5
}
}'Response:
{
"outputs": {
"total": 500
},
"execution_time_ns": 1250,
"rules_evaluated": 1
}cd backend
# Run all tests
cargo test --workspace
# Run specific crate tests
cargo test -p product-farm-json-logic
cargo test -p product-farm-rule-engine
cargo test -p product-farm-api
# Run with output
cargo test --workspace -- --nocapturecd frontend
# Install Playwright
npm install
npx playwright install
# Run E2E tests
npm run test:e2e
# Run with UI
npm run test:e2e:ui
# Run headed (see browser)
npm run test:e2e:headed| Module | Tests | Coverage |
|---|---|---|
| product-farm-core | 68 | ~90% |
| product-farm-json-logic | 93 | ~85% |
| product-farm-rule-engine | 15 | ~80% |
| product-farm-api | 21 | ~75% |
| product-farm-persistence | 18 | ~80% |
| product-farm-ai-agent | 19 | ~70% |
product-farm/
├── backend/ # Rust backend
│ ├── crates/
│ │ ├── core/ # Domain types (Product, Rule, Attribute)
│ │ ├── json-logic/ # JSON Logic parser, compiler, VM
│ │ ├── rule-engine/ # DAG builder, executor
│ │ ├── persistence/ # Storage backends (DGraph, file, memory)
│ │ ├── api/ # REST + gRPC services
│ │ └── ai-agent/ # AI tools for rule management
│ └── Cargo.toml
│
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Route pages
│ │ ├── services/ # API client
│ │ ├── store/ # Zustand state
│ │ └── types/ # TypeScript types
│ ├── e2e/ # Playwright E2E tests
│ └── package.json
│
├── infrastructure/ # DGraph database
│ ├── dgraph # DGraph binary
│ └── dgraph-data/ # Data directory
│
├── docs/ # Documentation
│ ├── screenshots/ # UI screenshots
│ ├── ARCHITECTURE.md
│ ├── QUICK_START.md
│ └── USE_CASES.md
│
├── start-all.sh # Start all services
├── stop-all.sh # Stop all services
└── README.md
We welcome contributions! Please see our Contributing Guide for details.
# Clone and setup
git clone https://github.com/ayushmaanbhav/product-farm.git
cd product-farm
# Backend development
cd backend
cargo build
cargo test
# Frontend development
cd frontend
npm install
npm run dev- Rust: Follow
rustfmtandclippyrecommendations - TypeScript: ESLint + Prettier configuration included
- Commits: Use conventional commits format
- Docker Compose deployment
- Kubernetes Helm chart
- OAuth2/OIDC authentication
- Audit logging
- Rate limiting
- Prometheus metrics
- Rule versioning and rollback
- Import/export functionality
- Multi-tenant support
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Made with Rust + React
GitHub ·
Documentation ·
Examples






