PHPackages                             azaharizaman/nexus-policy-engine - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. azaharizaman/nexus-policy-engine

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

azaharizaman/nexus-policy-engine
================================

Deterministic policy evaluation for authorization and workflow decisions.

v0.1.0-alpha1(1mo ago)02↓100%MITPHPPHP ^8.3

Since May 5Pushed 1mo agoCompare

[ Source](https://github.com/azaharizaman/nexus-policy-engine)[ Packagist](https://packagist.org/packages/azaharizaman/nexus-policy-engine)[ RSS](/packages/azaharizaman-nexus-policy-engine/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Nexus\\PolicyEngine
===================

[](#nexuspolicyengine)

Overview
--------

[](#overview)

`Nexus\PolicyEngine` is a Layer 1 package that evaluates tenant-scoped policies with deterministic outcomes. Version 1 supports:

- Authorization decisions
- Workflow decisions
- Threshold/limit runtime decisions (numeric comparator-based)

Architecture
------------

[](#architecture)

- Layer 1 (pure PHP, framework-agnostic)
- Interface-first boundaries via `src/Contracts`
- Immutable domain/value objects
- Deterministic conflict resolution and default outcomes

Key Interfaces
--------------

[](#key-interfaces)

- `Nexus\PolicyEngine\Contracts\PolicyEngineInterface`
- `Nexus\PolicyEngine\Contracts\PolicyRegistryInterface`
- `Nexus\PolicyEngine\Contracts\PolicyCompilerInterface` (reserved for future compilation/caching use in v1)
- `Nexus\PolicyEngine\Contracts\PolicyDefinitionDecoderInterface` (JSON to typed domain policy)

Requirements Mapping
--------------------

[](#requirements-mapping)

- Authorization policy evaluation (A)
- Workflow policy evaluation (B)
- Threshold policy runtime (C: `GT`, `GTE`, `LT`, `LTE`, `BETWEEN`)
- Stateless JSON policy decoding and domain validation

Multi-Layer Usage Pattern
-------------------------

[](#multi-layer-usage-pattern)

- **Layer 1 (`Nexus\PolicyEngine`)**
    - Owns typed policy model, evaluator, validator, and JSON decode contract/service.
    - Remains stateless and framework-agnostic.
- **Layer 2 (orchestrators)**
    - Coordinates when policy decode/evaluate is invoked in business workflows.
    - Composes cross-package context before calling the engine.
- **Layer 3 (adapters/apps)**
    - Provides storage-backed policy registries and transport concerns (HTTP/UI/DB).
    - Admin UI and persistence adapters live here, not in Layer 1.

Installation
------------

[](#installation)

From monorepo root, ensure autoload is refreshed:

`composer dump-autoload`

Run package tests:

`vendor/bin/phpunit -c packages/PolicyEngine/phpunit.xml`

Usage Examples
--------------

[](#usage-examples)

### 1) Authorization policy evaluation

[](#1-authorization-policy-evaluation)

Use this when deciding if a subject can perform an action on a resource.

```
