# j-easy/easy-rules architecture

> Architecture diagram of the GitHub repository j-easy/easy-rules, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/j-easy/easy-rules
- Repository: https://github.com/j-easy/easy-rules

## Overview

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: [`easy-rules-core/src/main/java/org/jeasy/rules/api`](https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/api) (Rules API), [`pom.xml`](https://github.com/j-easy/easy-rules/blob/master/pom.xml) (Root POM), [`easy-rules-core/src/main/java/org/jeasy/rules/core`](https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/core) (Core Engine), [`easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java`](https://github.com/j-easy/easy-rules/blob/master/easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java) (Rule Factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Root"]
  node_pom["Root POM<br/>maven aggregator<br/>[pom.xml]"]
  node_ci["CI Workflow<br/>github actions<br/>[build.yml]"]
end

subgraph group_core["Core"]
  node_api["Rules API<br/>public api"]
  node_engine["Core Engine<br/>runtime engine"]
  node_annotations["Annotations<br/>annotation model"]
end

subgraph group_support["Support"]
  node_reader["Def Readers<br/>json/yaml input"]
  node_factory["Rule Factory<br/>descriptor bridge"]
  node_composite["Composite Rules<br/>rule grouping"]
end

subgraph group_integrations["Integrations"]
  node_mvel["MVEL<br/>expression integration"]
  node_spel["SpEL<br/>expression integration"]
  node_jexl["JEXL<br/>expression integration"]
end

subgraph group_tutorials["Tutorials"]
  node_hello["Hello World<br/>tutorial app"]
  node_fizzbuzz["FizzBuzz<br/>tutorial app"]
  node_shop["Shop<br/>tutorial app"]
  node_web["Web Demo<br/>servlet demo"]
end

subgraph group_scaffold["Scaffold"]
  node_archetype["Archetype<br/>project scaffold"]
end

node_pom -->|"builds"| node_api
node_pom -->|"builds"| node_factory
node_pom -->|"builds"| node_mvel
node_pom -->|"builds"| node_spel
node_pom -->|"builds"| node_jexl
node_pom -->|"builds"| node_hello
node_pom -->|"builds"| node_archetype
node_ci -->|"validates"| node_pom
node_api -->|"implemented by"| node_engine
node_annotations -->|"maps to"| node_api
node_engine -->|"uses"| node_api
node_engine -->|"reflects"| node_annotations
node_reader -->|"feeds"| node_factory
node_factory -->|"creates"| node_api
node_composite -->|"extends"| node_api
node_mvel -->|"specializes"| node_factory
node_mvel -->|"implements"| node_api
node_spel -->|"specializes"| node_factory
node_spel -->|"implements"| node_api
node_jexl -->|"specializes"| node_factory
node_jexl -->|"implements"| node_api
node_hello -->|"demonstrates"| node_engine
node_fizzbuzz -->|"demonstrates"| node_engine
node_shop -->|"demonstrates"| node_reader
node_web -->|"demonstrates"| node_engine
node_archetype -->|"scaffolds"| node_api

click node_pom "https://github.com/j-easy/easy-rules/blob/master/pom.xml"
click node_ci "https://github.com/j-easy/easy-rules/blob/master/.github/workflows/build.yml"
click node_api "https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/api"
click node_engine "https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/core"
click node_annotations "https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/annotation"
click node_reader "https://github.com/j-easy/easy-rules/tree/master/easy-rules-support/src/main/java/org/jeasy/rules/support/reader"
click node_factory "https://github.com/j-easy/easy-rules/blob/master/easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java"
click node_composite "https://github.com/j-easy/easy-rules/tree/master/easy-rules-support/src/main/java/org/jeasy/rules/support/composite"
click node_mvel "https://github.com/j-easy/easy-rules/tree/master/easy-rules-mvel/src/main/java/org/jeasy/rules/mvel"
click node_spel "https://github.com/j-easy/easy-rules/tree/master/easy-rules-spel/src/main/java/org/jeasy/rules/spel"
click node_jexl "https://github.com/j-easy/easy-rules/tree/master/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl"
click node_hello "https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/helloworld"
click node_fizzbuzz "https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz"
click node_shop "https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop"
click node_web "https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web"
click node_archetype "https://github.com/j-easy/easy-rules/tree/master/easy-rules-archetype/src/main/resources/archetype-resources"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pom,node_ci toneBlue
class node_api,node_engine,node_annotations toneAmber
class node_reader,node_factory,node_composite toneMint
class node_mvel,node_spel,node_jexl toneRose
class node_hello,node_fizzbuzz,node_shop,node_web toneIndigo
class node_archetype toneTeal
```

## Components

### Root

Repository-level Maven aggregation and CI

- [Root POM](https://github.com/j-easy/easy-rules/blob/master/pom.xml): maven aggregator · Aggregates all modules · `pom.xml`
- [CI Workflow](https://github.com/j-easy/easy-rules/blob/master/.github/workflows/build.yml): github actions · Build and validation pipeline · `.github/workflows/build.yml`

### Core

Public API and default rules engine

- [Rules API](https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/api): public api · Facts, rules, engine, listeners, and parameters · `easy-rules-core/src/main/java/org/jeasy/rules/api`
- [Core Engine](https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/core): runtime engine · Default and inference engines plus rule lifecycle · `easy-rules-core/src/main/java/org/jeasy/rules/core`
- [Annotations](https://github.com/j-easy/easy-rules/tree/master/easy-rules-core/src/main/java/org/jeasy/rules/annotation): annotation model · 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](https://github.com/j-easy/easy-rules/tree/master/easy-rules-support/src/main/java/org/jeasy/rules/support/reader): json/yaml input · Loads rule descriptors from JSON and YAML · `easy-rules-support/src/main/java/org/jeasy/rules/support/reader`
- [Rule Factory](https://github.com/j-easy/easy-rules/blob/master/easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java): descriptor bridge · Converts rule definitions into executable rules · `easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java`
- [Composite Rules](https://github.com/j-easy/easy-rules/tree/master/easy-rules-support/src/main/java/org/jeasy/rules/support/composite): rule grouping · Activation, conditional, and unit rule groups · `easy-rules-support/src/main/java/org/jeasy/rules/support/composite`

### Integrations

Expression-language rule modules

- [MVEL](https://github.com/j-easy/easy-rules/tree/master/easy-rules-mvel/src/main/java/org/jeasy/rules/mvel): expression integration · MVEL-backed rules, conditions, actions, and factory · `easy-rules-mvel/src/main/java/org/jeasy/rules/mvel`
- [SpEL](https://github.com/j-easy/easy-rules/tree/master/easy-rules-spel/src/main/java/org/jeasy/rules/spel): expression integration · Spring Expression Language-backed rules and factory · `easy-rules-spel/src/main/java/org/jeasy/rules/spel`
- [JEXL](https://github.com/j-easy/easy-rules/tree/master/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl): expression integration · Apache JEXL-backed rules and factory · `easy-rules-jexl/src/main/java/org/jeasy/rules/jexl`

### Tutorials

Sample applications and usage examples

- [Hello World](https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/helloworld): tutorial app · Basic starter example · `easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/helloworld`
- [FizzBuzz](https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz): tutorial app · Console rules example · `easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz`
- [Shop](https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop): tutorial app · Domain example using YAML rule input · `easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop`
- [Web Demo](https://github.com/j-easy/easy-rules/tree/master/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web): servlet demo · Servlet and filter integration example · `easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web`

### Scaffold

Project archetype resources

- [Archetype](https://github.com/j-easy/easy-rules/tree/master/easy-rules-archetype/src/main/resources/archetype-resources): project scaffold · Maven archetype for bootstrapping new projects · `easy-rules-archetype/src/main/resources/archetype-resources`

## Connections

- 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
