01 — Getting Started
Introduction
rulii is a lightweight, zero-dependency Java library for defining and executing business rules. It follows the Production Rule Model: IF some condition is true, THEN perform an action, OTHERWISE perform an alternative action.
Key Characteristics
Zero Dependencies
No external libraries. Just add rulii and go.
Java 17+
Uses modern Java features like records and sealed types.
Two Rule Styles
Functional (quick & functional) or Declarative (annotated structured classes).
Built-in Validation
39+ validation rules ready to use out of the box.
RuleFlow Orchestration
Compose rules into pipelines with conditionals, loops, async, and error handling (new in 2.0.0).
Spring Integration
Auto-configuration, DI in rules, and declarative XML rules & flows via rulii-spring.
When to Use rulii
- Business logic that changes frequently and should be separated from application code
- Input validation with rich error reporting (violations, severity levels)
- Decision engines where conditions determine which actions to take
- Anywhere you'd write chains of
if/elseblocks that need to be testable and composable
A Quick Taste
import static org.rulii.model.condition.Conditions.condition;
import static org.rulii.model.action.Actions.action;
// Define a rule: IF age >= 18 THEN print "Welcome!"
Rule rule = Rule.builder()
.name("AgeCheck")
.given(condition((Integer age) -> age >= 18))
.then(action(() -> System.out.println("Welcome!")))
.build();
// Run it through a RuleFlow — the recommended entry point
RuleFlow<RuleContext> flow = RuleFlow.builder()
.name("WelcomeFlow")
.run(rule)
.build();
flow.run(age -> 25);
// Output: Welcome!
That's it — a complete rule in just a few lines. The rest of this documentation will walk you through every feature, from bindings and conditions to rule sets, rule flows, and validation.