Java Rule Engine library over a tree data-structure
Each of us would have encountered decision trees and rule engines of various kinds in our software journeys. Rule engines are typically structured as a set of rules that are evaluated against a Context. Bonsai is a data structure that models such engines as a tree of knots and edges. The kicker here is that the tree can be recursively nested, allowing you to represent really complex rules as simple nested forest of trees.
Bonsai is a Java Library for data selection based on conditions. It is a powerful tree-based rule engine that enables you to:
- Create a forest of trees with key-to-data mappings
- Build complex decision trees with conditional branching
- Represent nested, hierarchical rule structures
- Evaluate rules against a context to traverse the tree and select the right data element. The Context and Rules are represented by a combination of JsonPath and Query-DSL
- Modify trees dynamically with delta operations
- Maintain versioning of tree components
- Plug any storage implementations
Add the Bonsai dependency to your Maven project:
<dependency>
<groupId>com.phonepe.commons</groupId>
<artifactId>bonsai-core</artifactId>
<version>${bonsai.version}</version>
</dependency>
For Gradle:
implementation 'com.phonepe.commons:bonsai-core:${bonsai.version}'
Contributions to Bonsai are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please ensure your code follows the project's coding standards and includes appropriate tests.
Bonsai is licensed under the Apache License 2.0. See the LICENSE file for details.