bentools/treerex

🦖 Declarative YAML flowcharts for complex decision trees.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/bentools/treerex

dev-main 2025-12-03 17:15 UTC

This package is auto-updated.

Last update: 2025-12-03 17:15:50 UTC


README

CI Workflow codecov

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

TL;DR (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.

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]); // <-- will be merged with `requiresApproval` above

$canEdit = $runner->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 đź’ľ

composer require bentools/treerex

Table of contents 📚

License đź“„

MIT.