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.

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/else blocks 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
rule.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 and validation.