DEV Community

Cover image for Eligify — The Criteria and Rule Engine for Explainable Decisions
Nasrul Hazim Bin Mohamad
Nasrul Hazim Bin Mohamad

Posted on

Eligify — The Criteria and Rule Engine for Explainable Decisions

Business eligibility logic has a habit of hiding in plain sight.

It starts with a few if statements in a controller, a couple more in a form request — and before long, the logic has spread across jobs, listeners, and policies.

And then the inevitable happens:

  • Different parts of the system disagree on what “eligible” means.
  • Making changes becomes risky because rules are scattered.
  • When someone asks, “Why was this rejected?” there’s no single, auditable answer.

Eligibility determines who qualifies — for a loan, a scholarship, a feature upgrade, or access to a service.
It’s too important to be buried inside conditional statements.

That’s where Eligify comes in.


Introducing Eligify — A Criteria and Rule Engine for Explainable Decisions

Eligify turns eligibility from hidden code into a first-class decision engine.

It gives you a declarative, data-driven, and auditable way to define and evaluate business rules — making decisions predictable and explainable.

Instead of scattering logic across your application, you define criteria (the decision context) and rules (the conditions). Each evaluation produces a clear outcome — with the “why” built in.

$criteria = Eligify::criteria('loan_approval')
    ->addRule('income', '>=', 3000)
    ->addRule('credit_score', '>=', 650)
    ->passThreshold(75)
    ->save();

$result = Eligify::evaluate('loan_approval', [
    'income' => 5000,
    'credit_score' => 720,
]);

Enter fullscreen mode Exit fullscreen mode

Example result

[
  'passed' => true,
  'score' => 90,
  'failed_rules' => [],
  'decision' => 'Approved',
]
Enter fullscreen mode Exit fullscreen mode

Whether you run it in a controller, background job, or policy — Eligify ensures every decision follows the same consistent logic.


How Eligify Works — The Core Architecture

Eligify separates definition, data extraction, evaluation, and audit — so every layer is clear, testable, and reusable.

Component Purpose
🧠 Criteria & Rules Define logical conditions with a fluent DSL. Supports AND/OR/XOR/MAJORITY groups, weights, and thresholds.
🔍 Model Data Extractor Normalises attributes and relationships into a flat structure. Keeps business logic decoupled from model internals.
⚙️ Evaluator Engine Runs rules, computes scores, and triggers callbacks (onPass, onFail, onExcellent).
📜 Audit Trail Stores every evaluation: what ran, what passed, what failed, and why — critical for transparency and compliance.

Architecture Flow (Text Diagram)

Eligify Sequence Diagram

You can see more details architecture design from here.


Practical Usage — From Definition to Decision

Eligify makes complex logic readable and repeatable. Here’s how it fits naturally into any application flow.

Step 1: Define Your Criteria

Eligify::criteria('membership_upgrade')
    ->addRule('account_age_days', '>=', 30)
    ->addRule('total_purchases', '>=', 5)
    ->addRule('support_tickets', '<=', 2)
    ->save();
Enter fullscreen mode Exit fullscreen mode

Step 2: Extract Model Data

$data = ModelDataExtractor::forModel(User::class)->extract($user);
Enter fullscreen mode Exit fullscreen mode

Step 3: Evaluate and Act

$result = Eligify::evaluate('membership_upgrade', $data);

if ($result['passed']) {
    // Upgrade membership
} else {
    Log::info('User not eligible', $result['failed_rules']);
}
Enter fullscreen mode Exit fullscreen mode

Each evaluation is audited, giving you a full history of what happened, when, and why — no more guesswork.


Why Eligify Matters

Eligify isn’t just a rules engine — it’s a mindset shift.

Instead of burying decisions inside conditionals, it makes them transparent, explainable, and reusable.

Centralised rule definitions — one source of truth
Consistent outcomes across systems
Auditable results for compliance and debugging
Extensible design for any domain — finance, education, HR, SaaS, government

When decisions impact real people, clarity and fairness matter.
Eligify helps you build both into your software.


🌟 Get Started

composer require cleaniquecoders/eligify
php artisan vendor:publish --tag="eligify-config"
php artisan migrate
Enter fullscreen mode Exit fullscreen mode

🔗 View on GitHub → cleaniquecoders/eligify

Stop scattering your eligibility logic. Centralise it. Audit it. Trust it.

Eligify — make decisions explainable.

Top comments (1)

Collapse
 
nasrulhazim profile image
Nasrul Hazim Bin Mohamad

new version released - v1.2.0 - which has a UI to manage all your Criteria & Rules. It's even better, you can test your Criteria & Rules in the Playground.

Go grab Eligify now at github.com/cleaniquecoders/eligify