# rulii > rulii is an open-source (Apache 2.0) business rule engine for Java 17 or later. A rule is a condition and its actions, written as an annotated class or as lambdas. Rules are grouped into rule sets and orchestrated by rule flows, and they run in the order given: there is no inference. The engine is one jar with no required dependencies. Notes for writing code with rulii: - Libraries: `org.rulii:rulii` (the engine), `org.rulii:rulii-spring` (Spring Boot), `org.rulii:rulii-bean-validation` (Jakarta Bean Validation constraints run as rules) and `org.rulii:rulii-explorer-spring-boot-starter` (a read-only viewer). `org.rulii:rulii-bom` pins matching versions. Current versions are on the Installation page. - Annotations (`@Rule`, `@Given`, `@Then`, `@Otherwise`, `@PreCondition`, `@Description`, `@Category`, `@Param`) are in `org.rulii.annotation`. For lambda rules, import `org.rulii.model.condition.Conditions.condition` and `org.rulii.model.action.Actions.action` statically. - Values are matched to method and lambda parameters by name, then by type. The names come from the class file, so compile with debug information (the Maven default), or put `@Param("name")` on the parameters of a rule class. - Run a rule, rule set or flow with `run(name -> value, ...)`, with a `Bindings` object, or with a `Map` or bean. A lambda parameter cannot have the name of a local variable in scope: write `run(customer -> buyer)`, not `run(customer -> customer)`. - `RuleResult` is a record: read `result.status()`. The statuses are `PASS`, `FAIL`, `SKIPPED` and `ERROR`. - A rule parameter with no matching binding receives a default (`null`, `0`, `false`, an empty `Optional`), not an exception. - Jakarta Expression Language can be written as `#{...}` or `${...}`; the docs use `#{...}`. From rulii 2.3.0 a `jakarta-el` script is not searched for Spring property placeholders (on 2.2.0 with rulii-spring, `${...}` was read as one and failed). - Bean Validation on rulii is opt-in in Spring Boot: add `org.rulii:rulii-bean-validation` beside rulii-spring (2.3.0 or later) and Spring Boot's validation starter, and the application's `Validator` runs on rulii in place of Hibernate Validator. `rulii.validation.enabled=false` turns it off while the dependency stays. JPA keeps validating entities with Hibernate Validator while it is on the classpath. rulii-bean-validation is not a certified implementation. - A flow-level `onException` handler recovers the failed step and the flow continues with the next top-level step (from 2.3.0; up to 2.2.0 it ended the flow). End the handler body with `exit()` to stop the flow. - rulii has no inference (it is not a Rete engine), no decision tables and no long-running workflows. The whole documentation as one Markdown file: https://rulii.org/llms-full.txt ## Getting Started - [Introduction](https://rulii.org/getting-started/introduction/): rulii is a lightweight, zero-dependency Java library for defining and executing business rules. - [Overview](https://rulii.org/getting-started/overview/): rulii is a Business Rule Engine written in Java. - [What's New in 2.3.0](https://rulii.org/getting-started/whats-new/): rulii 2.3.0, rulii-spring 2.3.0, rulii-bean-validation 1.1.0 and rulii-explorer 1.2.0: a faster engine, GraalJS context reuse, a flow-level exception handler that lets the flow continue, opt-in Bean Validation in Spring and all 48 validators in XML. - [Installation & Setup](https://rulii.org/getting-started/installation/): Add rulii to a Maven or Gradle build, check that it runs, and see which companion libraries exist. - [Core Concepts](https://rulii.org/getting-started/core-concepts/): rulii is built on three building blocks: Conditions, Actions, and Bindings. Every rule combines these pieces following the Production Rule Model. - [Release History](https://rulii.org/getting-started/release-history/): Every release of rulii and its companion libraries, back to ruling-class in 2019. - [Migrating from Easy Rules](https://rulii.org/getting-started/migrating-from-easy-rules/): This guide is for a project that runs its rules on Easy Rules 4 today and wants to run them on rulii. A rule keeps its shape: a name, a condition and actions. ## Core - [Bindings](https://rulii.org/core/bindings/): A Binding is a named, typed variable. - [Loading Bindings](https://rulii.org/core/loading-bindings/): A BindingLoader provides a convenient way to bulk-load bindings into a Bindings container from external sources such as Maps, POJOs, or other data structures. - [Binding Matching](https://rulii.org/core/binding-matching/): When a rule executes, its parameters (conditions, actions) need to be resolved from the available bindings. - [RuleContext](https://rulii.org/core/rule-context/): A RuleContext is the execution environment a rule runs in: the bindings, locale, converters, message formatters, tracer and clock. - [Building Rules (Functional)](https://rulii.org/core/lambda-rules/): Lambda rules are the quickest way to define rules in rulii. - [Building Rules (Declarative)](https://rulii.org/core/annotation-rules/): Annotation-based rules let you define rules as Java classes with annotated methods. - [Rule Execution & Results](https://rulii.org/core/rule-results/): When you run a rule, it returns a RuleResult — a Java record containing the rule that was executed and its execution status. - [RuleSets](https://rulii.org/core/rulesets/): A RuleSet groups multiple rules into an ordered collection and runs them in sequence against the same bindings. - [RuleFlows](https://rulii.org/core/ruleflow/): A RuleFlow is an executable pipeline of rules, rule sets, nested flows, functions and actions, with branching, loops, exception handling and async steps. - [Builder Pattern Reference](https://rulii.org/core/builder-reference/): Almost everything in rulii is built using the builder pattern. ## Validation - [Built-in Validation Rules](https://rulii.org/validation/validation-rules/): rulii ships with 48 ready-to-use validation rules (eleven of them new in 2.2.0). - [RuleViolations & Severity](https://rulii.org/validation/rule-violations/): When validation rules fail, they add RuleViolation objects to a RuleViolations container. This section explains how to work with violations and severity levels. - [Custom Validation Rules](https://rulii.org/validation/custom-validation/): Extend the ValidationRule base class to create your own domain-specific validators. ## Advanced - [Condition Composition](https://rulii.org/advanced/condition-composition/): Conditions in rulii support logical composition using and(), or(), not(), and xor(). - [Action Chaining](https://rulii.org/advanced/action-chaining/): Actions in rulii can be chained together using andBefore() and andThen() methods. - [Functions](https://rulii.org/advanced/functions/): Functions in rulii are like Actions but they return a value. - [Scoped Bindings](https://rulii.org/advanced/scoped-bindings/): ScopedBindings create a stack of named scopes, each with its own set of bindings. - [Type References](https://rulii.org/advanced/type-references/): Java erases generic type information at runtime. - [Type Conversion](https://rulii.org/advanced/type-conversion/): ConverterRegistry manages type converters for automatic value conversion in rulii. - [Rule Tracing & Debugging](https://rulii.org/advanced/rule-tracing/): The Tracer provides event-driven debugging for rule execution. - [Introspection & Metadata](https://rulii.org/advanced/introspection/): As of 2.1.0, everything a Rule, RuleSet, or RuleFlow is made of can be read off the built object without running it. - [Async Execution](https://rulii.org/advanced/async-execution/): RuleSets and RuleFlows can be executed asynchronously using CompletableFuture — both implement the AsyncRunnable interface (new in 2.0.0). - [Message Formatting](https://rulii.org/advanced/message-formatting/): rulii includes a message formatting system that supports both positional placeholders ({0}, {1}) and named placeholders (${name}). - [Message Resolution](https://rulii.org/advanced/message-resolution/): The MessageResolver loads messages from Java ResourceBundle files (.properties) and supports locale-aware message lookup. - [Clock & Time Support](https://rulii.org/advanced/clock-time/): The RuleContext includes a Clock for time-based operations. - [Scripting Support](https://rulii.org/advanced/scripting/): Dynamic expressions inside rules, written in JavaScript, Groovy, Java expressions, Jakarta EL or any JSR-223 language. ## Spring - [Introduction](https://rulii.org/spring/introduction/): rulii-spring is the official Spring Boot integration for the rulii rule engine. - [Installation & Setup](https://rulii.org/spring/installation/): Add rulii-spring to your pom.xml. It transitively brings in the core rulii library, so you don't need to declare it separately. - [Auto-Configuration](https://rulii.org/spring/auto-configuration/): rulii-spring ships with one central @AutoConfiguration class — RuleConfig — that sets up everything you need. - [Rule Scanning & Discovery](https://rulii.org/spring/rule-scanning/): rulii-spring automatically discovers your @Rule classes and registers them as Spring beans. - [Dependency Injection in Rules](https://rulii.org/spring/dependency-injection/): One of the biggest benefits of rulii-spring is that your @Rule classes participate in Spring's dependency injection. - [Rule Registry](https://rulii.org/spring/rule-registry/): The SpringRuleRegistry is a registry backed by the Spring application context. - [Type Conversion](https://rulii.org/spring/type-conversion/): rulii has its own type conversion system (ConverterRegistry), and Spring has its own (ConversionService). - [Message Resolution](https://rulii.org/spring/message-resolution/): Rule violations carry messages that describe what went wrong. - [Spring Context Bindings](https://rulii.org/spring/binding-loader/): SpringContextBindingLoader makes every Spring bean available as a read-only binding in rulii's binding system. - [SpEL Scripting](https://rulii.org/spring/scripting/): rulii-spring 1.2.0 adds first-class support for Spring Expression Language (SpEL) as a scripting language inside rules. - [XML Rule Definitions](https://rulii.org/spring/xml-rules/): rulii-spring 1.2.0 introduces an XML namespace that lets you declare rules, rulesets, and validation rules entirely in XML files. - [XML RuleFlows](https://rulii.org/spring/xml-ruleflows/): rulii-spring 2.0.0 adds a full XML namespace that mirrors the RuleFlow builder DSL — script expressions substitute the builder's lambdas. - [Configuration Reference](https://rulii.org/spring/configuration-reference/): This page collects every configuration property, bean name constant, and auto-configured bean in one place for quick reference. ## Bean Validation - [Introduction](https://rulii.org/bean-validation/introduction/): rulii-bean-validation reads the jakarta.validation constraints on your beans and runs each one as a rulii rule. - [Installation & Setup](https://rulii.org/bean-validation/installation/): Add rulii-bean-validation to your pom.xml. It brings in rulii core and jakarta.validation:jakarta.validation-api and nothing else. - [Validating Beans](https://rulii.org/bean-validation/validating-beans/): A bean annotated for Bean Validation needs no change. - [Constraints](https://rulii.org/bean-validation/constraints/): Every constraint the specification defines is in place, with its null semantics and applicable types, each mapped to a built-in rulii validation rule. - [Attaching rulii Rules with @Validate](https://rulii.org/bean-validation/validate-annotation/): @Validate names runnables in the validator's RuleRegistry: a Rule, a RuleSet or a RuleFlow. - [Inline Conditions with @Expr](https://rulii.org/bean-validation/expr/): For an invariant between fields that no annotation expresses, @Expr attaches a script condition, compiled once when the class is first read. - [Cross-Field Validation with Rules, RuleSets & RuleFlows](https://rulii.org/bean-validation/rules-and-flows/): Validation that looks at more than one value is where annotations run out. - [Constraints as rulii Rules](https://rulii.org/bean-validation/constraints-as-rules/): Every constraint, @Expr and @Validate declaration becomes a named, described, categorised and tagged rulii rule, visible in the trace and the registry. - [Configuration](https://rulii.org/bean-validation/configuration/): Everything is fixed when the validator is built. - [Spring Boot Integration](https://rulii.org/bean-validation/spring/): Add rulii-bean-validation beside rulii-spring and it becomes the application's Bean Validation provider, wired into the Spring rulii context. - [Migrating from Hibernate Validator](https://rulii.org/bean-validation/migration/): This guide is for a project that validates with Hibernate Validator today and wants to run on rulii-bean-validation. The beans do not change. - [Specification Coverage](https://rulii.org/bean-validation/spec-coverage/): What the Jakarta Validation 3.1 specification requires, chapter by chapter, and where this library stands. ## Explorer - [Introduction](https://rulii.org/explorer/introduction/): rulii-explorer shows the rules, rule sets and rule flows of a running Spring Boot application: what each one checks, what runs what, and what is likely to fail. - [Installation & Setup](https://rulii.org/explorer/installation/): Add the explorer starter to a Spring Boot application that uses rulii-spring, switch it on, and expose its Actuator endpoint. - [Configuration](https://rulii.org/explorer/configuration/): Every rulii.explorer property: the switch, the page, sources, placeholder values and the Beans section. - [Using the Explorer](https://rulii.org/explorer/guide/): A guide to the explorer's screens: the tour, flowcharts, the dependency graph, search, categories, beans, addresses, and a reference for every problem it reports. ## Guides - [Why rulii](https://rulii.org/why/): Why it exists, what it is not for, and how it compares with plain Java, Drools, Easy Rules and Hibernate Validator. - [Questions people ask](https://rulii.org/questions/): Why not if/else, parameter names, the single maintainer, and how much of it AI wrote. - [You keep the rules, the AI keeps the rest](https://rulii.org/blog/using-ai-to-build-the-rules/): Keeping the business rules apart from the rest of the code used to take discipline, planning and buy-in. Now it takes one instruction. The AI writes the code, and you keep the rules. - [Why I'd use rulii to validate incoming data](https://rulii.org/blog/validating-incoming-data/): Bean Validation annotations cover the easy checks. The cross-field ones and the business rules are where they run out, and where a rule engine earns its place. ## Code - [rulii](https://github.com/algox/rulii): The engine. - [rulii-spring](https://github.com/algox/rulii-spring): Spring Boot integration. - [rulii-bean-validation](https://github.com/algox/rulii-bean-validation): Jakarta Bean Validation on the engine. - [rulii-explorer](https://github.com/algox/rulii-explorer): The viewer for the rules of a running application. - [rulii-samples](https://github.com/algox/rulii-samples): Runnable examples, including a starter project set up for an AI assistant. - [Claude Code skills for rulii](https://github.com/algox/rulii/tree/develop/.claude/skills): Markdown guides for writing rules, rule sets, rule flows, validation rules and tests. - [Claude Code skills for rulii-spring](https://github.com/algox/rulii-spring/tree/develop/.claude/skills): The same, with Spring wiring and XML. - [Javadoc](https://javadoc.io/doc/org.rulii/rulii/latest): API reference for the engine. ## Optional - [Optimizing rulii](https://rulii.org/blog/optimizing-rulii/): rulii 2.2.0 ran 1.4 million rules a second on one thread. 2.3.0 runs 8.1 million, and the rules do exactly what they did. Where the time was going, what changed, and what we measured and threw away. - [rulii 2.3.0 and rulii-spring 2.3.0](https://rulii.org/blog/rulii-2-3-0/): A faster engine with nothing to change in your rules, GraalJS context reuse, a flow-level exception handler that lets the flow continue, and a Spring integration where Bean Validation on rulii is opt-in and all 48 validators are XML elements. - [rulii-bean-validation 1.1.0](https://rulii.org/blog/rulii-bean-validation-1-1-0/): A validation call costs a fraction of what it did: predefined constraints are checked directly, and a class with nothing else needs no engine around it. The annotations, the API and the violations are unchanged. - [rulii-bom 2.3.0](https://rulii.org/blog/rulii-bom-2-3-0/): The bill of materials for the 2.3.0 line: rulii 2.3.0, rulii-spring 2.3.0, rulii-bean-validation 1.1.0 and rulii-explorer 1.2.0. - [rulii-explorer 1.2.0](https://rulii.org/blog/rulii-explorer-1-2-0/): The explorer starts in an application on WebFlux without Spring MVC, a start-up warning is gone, and it is built against rulii 2.3.0 and rulii-spring 2.3.0. - [rulii-bom 2.2.0](https://rulii.org/blog/rulii-bom-2-2-0/): A bill of materials that pins the matching versions of rulii, rulii-spring, rulii-bean-validation and rulii-explorer. Import it once and leave the versions off. - [rulii 2.2.0 and rulii-spring 2.2.0](https://rulii.org/blog/rulii-2-2-0/): Forked contexts for async work, local bindings, formal result types, Jakarta EL as a scripting language, eleven more validators, and a Spring integration that makes rulii the application's Bean Validation provider. - [rulii-bean-validation 1.0.0](https://rulii.org/blog/rulii-bean-validation-1-0-0/): The first release: a Jakarta Bean Validation 3.1 provider that runs every constraint as a rulii rule, with @Validate, @Expr and @Bind for what annotations cannot say. - [rulii-explorer 1.1.0](https://rulii.org/blog/rulii-explorer-1-1-0/): A Beans section for the classes validated with rulii-bean-validation, result types on rule sets and flows, and a resizable sidebar. - [Explorer demo](https://rulii.org/demo/index.html): The explorer running on a sample application.