PHPackages                             bentools/treerex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. bentools/treerex

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

bentools/treerex
================

🦖 Declarative YAML flowcharts for complex decision trees.

1.0-alpha1(2mo ago)128MITPHPPHP &gt;=8.4CI passing

Since Mar 9Pushed 2mo agoCompare

[ Source](https://github.com/bpolaszek/treerex)[ Packagist](https://packagist.org/packages/bentools/treerex)[ RSS](/packages/bentools-treerex/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (3)Used By (0)

TreeRex 🦖
=========

[](#treerex-)

[![CI Workflow](https://github.com/bpolaszek/treerex/actions/workflows/ci.yml/badge.svg)](https://github.com/bpolaszek/treerex/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/a8baba11c132153f49a737aad8958837f960e4736ef704eea08a7165d4ab7a48/68747470733a2f2f636f6465636f762e696f2f67682f62706f6c61737a656b2f747265657265782f67726170682f62616467652e7376673f746f6b656e3d4a764870326259313635)](https://codecov.io/gh/bpolaszek/treerex)

Declaratively describe complex decision trees ("flowcharts") in *YAML* and run them against arbitrary subjects.

TL;DR (what you get in practice) 🫵
----------------------------------

[](#tldr-what-you-get-in-practice-)

- ✅ **Zero if‑else spaghetti** – complex validation / eligibility logic lives in *YAML*, not buried in controllers.
- 🧩 **Composable rules** – re‑use the same *checker services* across many flowcharts.
- 🔍 **Full observability** – inspect the last node, the *full decision history*, and enriched *context*.
- 🧪 **Test‑friendly** – feed any subject + context, assert the final result and the reasons attached in context.
- 🧠 **Business‑driven** – Product Owners can reason about the YAML flowchart *without reading PHP*.
- ⚡ **Side effects** – trigger external actions (dispatch messages, write to cache, …) alongside decisions.

What it looks like
------------------

[](#what-it-looks-like)

```
# config/user_can_edit_post.yaml
options:
  defaultChecker: BenTools\TreeRex\Checker\ExpressionLanguageChecker

context:
  requiresApproval: ~

entrypoint:
  criteria: "subject.isAdmin()"
  when@true:
    end: true
  when@false:
    criteria: "subject.id === context.post.authorId"
    when@true:
      end: true
    when@false:
      criteria: "subject.roles in ['ROLE_REVIEWER']"
      when@true:
        end:
          result: true
          context:
            requiresApproval: true
```

```
use BenTools\TreeRex\Factory\FlowchartYamlFactory;
use BenTools\TreeRex\Runner\FlowchartRunner;
use BenTools\TreeRex\Runner\RunnerContext;

$flowchart = new FlowchartYamlFactory()->parseYamlFile(__DIR__.'/config/user_can_edit_post.yaml');
$runner = new FlowchartRunner();
$context = new RunnerContext(['post' => $post]); // satisfies($user, $flowchart, $context);
var_dump($canEdit); // bool
var_dump($context['requiresApproval']); // bool|null
var_dump($context->state); // RunnerState -> gives you the full history of decisions
```

Installation 💾
--------------

[](#installation-)

```
composer require bentools/treerex
```

Table of contents 📚
-------------------

[](#table-of-contents-)

- 🚀 [Getting started](docs/01-getting-started.md)
- 🔍 [Flowchart state &amp; context](docs/02-flowchart-state.md)
- 🧠 [Core concepts](docs/03-core-concepts.md)
- ⚙️ [Advanced usage](docs/04-advanced-usage.md)
- 🤝 [Contributing](docs/05-contributing.md)

License 📄
=========

[](#license-)

MIT.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance86

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

69d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acdd1a8ee0e657ddd06cf11f98a32100ef7121afb8aa270a5b295f5c29c038b3?d=identicon)[bpolaszek](/maintainers/bpolaszek)

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (3 commits)")

---

Tags

yamlflowchartdecision-tree

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bentools-treerex/health.svg)

```
[![Health](https://phpackages.com/badges/bentools-treerex/health.svg)](https://phpackages.com/packages/bentools-treerex)
```

###  Alternatives

[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[spatie/yaml-front-matter

A to the point yaml front matter parser

3411.8M68](/packages/spatie-yaml-front-matter)[pragmarx/yaml

Load your Laravel config files using yaml

1152.8M29](/packages/pragmarx-yaml)[sspooky13/yaml-standards

Standards for yaml files

11518.3k3](/packages/sspooky13-yaml-standards)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
