How j-easy/easy-rules works
1. What this repository is
- Easy Rules is a multi-module Maven library for Java that implements a lightweight rules engine.
- The repo is organized as a core engine plus optional integration modules, support utilities, tutorial applications, and a Maven archetype for bootstrapping new projects.
2. Top-level architecture
- The root pom.xml aggregates the modules.
- .github/workflows/build.yml provides CI validation.
- The code is primarily a library ecosystem, not a single runtime application.
3. Core execution model
- The central runtime flow is: Facts → Rules → RulesEngine → Actions.
- Facts is the mutable input context.
- Rule defines a condition and one or more actions.
- RulesEngine evaluates conditions against the facts and triggers actions when conditions match.
4. easy-rules-core: public API boundary
- This module defines the main abstractions under org.jeasy.rules.api: Rule, Action, Condition, Facts, Rules, RulesEngine, listeners, and engine parameters.
- It is the main dependency surface for users embedding Easy Rules into their own applications.
5. easy-rules-core: engine and rule implementations
- The org.jeasy.rules.core package contains the default engine behavior and rule implementations such as DefaultRule, BasicRule, DefaultRulesEngine, and InferenceRulesEngine.
- It also contains rule construction and validation utilities like RuleBuilder, RuleDefinitionValidator, RuleProxy, and helper classes for rule ordering and fact handling.
- This is where rule lifecycle, priority ordering, skipping behavior, and listener callbacks are coordinated.
6. Annotation-based rule model
- The org.jeasy.rules.annotation package defines the annotation programming model: @Rule, @Condition, @Action, @Fact, and @Priority.
- These annotations allow users to write plain Java classes as rules instead of implementing engine interfaces directly.
- The test suite shows substantial validation around invalid annotation combinations, which indicates annotation parsing and method signature constraints are an important internal boundary.
7. easy-rules-support: reusable rule infrastructure
- This module adds higher-level support on top of core:
- composite rule types: ActivationRuleGroup, ConditionalRuleGroup, UnitRuleGroup
- rule definition readers for JSON and YAML
- abstract factory/reader support for turning descriptors into executable rules
- It acts as the bridge between external rule descriptors and the core rule engine.
8. Rule definition file flow
- Descriptor files in JSON/YAML are read by RuleDefinitionReader implementations.
- Those definitions are converted by AbstractRuleFactory into Rule instances.
- This is a distinct input path from annotation-based or fluent API rule creation, but it converges on the same core Rule abstraction.
9. Expression-language integrations
- easy-rules-mvel, easy-rules-spel, and easy-rules-jexl provide alternate rule implementations backed by expression engines.
- Each module supplies its own Rule, Action, Condition, and RuleFactory classes for its expression language.
- This is the main extension boundary for users who prefer declarative expressions over Java methods or lambdas.
10. How the expression modules fit the system
- These modules still produce standard Easy Rules Rule objects, so they plug into the same Rules collection and RulesEngine execution path.
- The main architectural difference is in how the condition/action logic is represented and evaluated:
- MVEL for expression-driven rules
- SpEL with Spring-oriented bean resolution support
- JEXL for Apache JEXL expressions
11. Composite and inferred behaviors
- The support package’s composite rule groups indicate that a “rule” can encapsulate multiple rules and coordinate their activation.
- InferenceRulesEngine in core suggests an alternate engine mode that can keep firing newly triggered rules until no more applicable rules remain.
- These features are important for diagrams because they introduce rule-to-rule orchestration, not just rule-to-action execution.
12. Tutorial applications as consumers
- easy-rules-tutorials is a set of sample applications showing how the library is used in different contexts:
- console examples like Hello World and FizzBuzz
- domain examples like shop and weather
- web-related examples with servlet/filter classes
- These are not core runtime dependencies, but they demonstrate the library’s integration points with application code and servlet-based environments.
13. Archetype module
- easy-rules-archetype is a Maven archetype that generates a starter project with example rule and launcher classes.
- Architecturally, it is a project scaffolding tool rather than part of the rules runtime.
14. Testing and quality boundaries
- Each module has focused unit tests, with especially deep coverage in easy-rules-core.
- The tests document expected behavior for rule validation, fact injection, rule ordering, listeners, composite rules, and expression-language integrations.
- For an architecture diagram, this reinforces that most complexity is concentrated in validation, rule construction, and engine execution rather than external infrastructure.
15. Operational context
- The project is a library distribution published to Maven Central, with CI through GitHub Actions.
- There are no major runtime backend dependencies in the repo itself beyond the optional expression libraries and Spring-related components used by specific modules.
- The primary “deployment” is as reusable Java artifacts consumed by other systems.
Main entry points: api Rules API · pom.xml Root POM · core Core Engine · AbstractRuleFactory.java Rule Factory
Components 16
Root
Repository-level Maven aggregation and CI
- Root POM · Aggregates all modules
pom.xml - CI Workflow · Build and validation pipeline
.github/workflows/build.yml
Core
Public API and default rules engine
- Rules API · Facts, rules, engine, listeners, and parameters
easy-rules-core/src/main/java/org/jeasy/rules/api - Core Engine · Default and inference engines plus rule lifecycle
easy-rules-core/src/main/java/org/jeasy/rules/core - Annotations · Rule, condition, action, fact, and priority annotations
easy-rules-core/src/main/java/org/jeasy/rules/annotation
Support
Composite rules and descriptor readers
- Def Readers · Loads rule descriptors from JSON and YAML
easy-rules-support/src/main/java/org/jeasy/rules/support/reader - Rule Factory · Converts rule definitions into executable rules
easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java - Composite Rules · Activation, conditional, and unit rule groups
easy-rules-support/src/main/java/org/jeasy/rules/support/composite
Integrations
Expression-language rule modules
- MVEL · MVEL-backed rules, conditions, actions, and factory
easy-rules-mvel/src/main/java/org/jeasy/rules/mvel - SpEL · Spring Expression Language-backed rules and factory
easy-rules-spel/src/main/java/org/jeasy/rules/spel - JEXL · Apache JEXL-backed rules and factory
easy-rules-jexl/src/main/java/org/jeasy/rules/jexl
Tutorials
Sample applications and usage examples
- Hello World · Basic starter example
easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/helloworld - FizzBuzz · Console rules example
easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz - Shop · Domain example using YAML rule input
easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop - Web Demo · Servlet and filter integration example
easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web
Scaffold
Project archetype resources
- Archetype · Maven archetype for bootstrapping new projects
easy-rules-archetype/src/main/resources/archetype-resources
Connections 26
- Root POM → Rules API: builds · Root aggregator includes core API module
- Root POM → Rule Factory: builds · Root aggregator includes support module
- Root POM → MVEL: builds · Root aggregator includes MVEL module
- Root POM → SpEL: builds · Root aggregator includes SpEL module
- Root POM → JEXL: builds · Root aggregator includes JEXL module
- Root POM → Hello World: builds · Root aggregator includes tutorials module
- Root POM → Archetype: builds · Root aggregator includes archetype module
- CI Workflow → Root POM: validates · Workflow runs repository build
- Rules API → Core Engine: implemented by · Default engine executes the public API contract
- Annotations → Rules API: maps to · Annotation model adapts into core abstractions
- Core Engine → Rules API: uses · Engine evaluates facts and rules through API types
- Core Engine → Annotations: reflects · Default engine supports annotated rule classes
- Def Readers → Rule Factory: feeds · Readers produce definitions consumed by the factory
- Rule Factory → Rules API: creates · Factory turns descriptors into Rule instances
- Composite Rules → Rules API: extends · Composite rule groups still behave as rules
- MVEL → Rule Factory: specializes · MVEL module provides expression-based rule creation
- MVEL → Rules API: implements · Produces standard Easy Rules abstractions
- SpEL → Rule Factory: specializes · SpEL module provides expression-based rule creation
- SpEL → Rules API: implements · Produces standard Easy Rules abstractions
- JEXL → Rule Factory: specializes · JEXL module provides expression-based rule creation
- JEXL → Rules API: implements · Produces standard Easy Rules abstractions
- Hello World → Core Engine: demonstrates · Starter example exercises the core engine
- FizzBuzz → Core Engine: demonstrates · Console example exercises rule evaluation
- Shop → Def Readers: demonstrates · Uses descriptor-based rule loading
- Web Demo → Core Engine: demonstrates · Servlet demo integrates rules into web code
- Archetype → Rules API: scaffolds · Generated projects start from core rule abstractions