PHPackages                             azaharizaman/nexus-uom - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. azaharizaman/nexus-uom

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

azaharizaman/nexus-uom
======================

Framework-agnostic Unit of Measurement (UoM) management and conversion engine for the Nexus ERP system

v0.1.0-alpha1(1mo ago)022MITPHPPHP ^8.2

Since May 5Pushed 1mo agoCompare

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

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

Nexus UoM Package
=================

[](#nexus-uom-package)

**Framework-agnostic Unit of Measurement (UoM) management and conversion engine for the Nexus ERP system.**

Overview
--------

[](#overview)

The `Nexus\Uom` package provides a pure PHP, framework-agnostic engine for managing units of measurement, performing conversions, and handling complex measurement scenarios including:

- **Immutable Quantity Value Objects** for type-safe measurement handling
- **Dimension-based unit organization** (Mass, Length, Time, Temperature, etc.)
- **Conversion graph engine** with automatic pathfinding for multi-hop conversions
- **Packaging hierarchies** (Pallets → Cases → Eaches)
- **Complex conversions** with offset support (e.g., Celsius to Fahrenheit)
- **Arithmetic operations** on quantities with automatic conversion
- **Unit systems** (Metric, Imperial) for regional consistency

Features
--------

[](#features)

### Core Capabilities

[](#core-capabilities)

- **Framework Agnostic**: Pure PHP with no Laravel dependencies
- **Immutable Value Objects**: Thread-safe, predictable quantity handling
- **Type-Safe Operations**: Automatic validation prevents incompatible unit operations
- **Precision Math**: Uses BCMath/GMP for arbitrary precision calculations
- **Performance**: Direct conversions &lt; 5ms, complex multi-hop &lt; 20ms
- **Extensible**: Define custom dimensions, units, and conversion rules

### Key Components

[](#key-components)

1. **Quantity Value Object** (`ValueObjects/Quantity.php`)

    - Primary API entry point
    - Immutable value + unit pairing
    - Arithmetic operations with automatic conversion
    - Serialization support for JSON/arrays
2. **Conversion Engine** (`Services/UomConversionEngine.php`)

    - Graph-based pathfinding for multi-hop conversions
    - Direct ratio-based conversions
    - Offset conversions for temperature
    - Packaging hierarchy conversions
3. **Validation Service** (`Services/UomValidationService.php`)

    - Dimension compatibility checking
    - Ratio validation
    - Circular reference detection
    - System unit protection
4. **Dimension Value Object** (`ValueObjects/Dimension.php`)

    - Groups related units (Mass, Length, etc.)
    - Defines base unit for each dimension
    - Ensures conversion compatibility

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

[](#installation)

Add to your `composer.json`:

```
composer require azaharizaman/nexus-uom:"*@dev"
```

Basic Usage
-----------

[](#basic-usage)

### Creating Quantities

[](#creating-quantities)

```
use Nexus\Uom\ValueObjects\Quantity;

// Create a quantity with value and unit code
$weight = new Quantity(100.5, 'kg');
$distance = new Quantity(1000, 'm');
```

### Arithmetic Operations

[](#arithmetic-operations)

```
// Addition with automatic conversion
$total = $weight1->add($weight2); // Converts to same unit automatically

// Subtraction
$difference = $weight1->subtract($weight2);

// Multiplication (by scalar)
$doubled = $weight->multiply(2);

// Division (by scalar)
$half = $weight->divide(2);
```

### Unit Conversion

[](#unit-conversion)

```
// Convert to different unit
$pounds = $weight->convertTo('lb');

// Check if convertible
if ($validator->areConvertible($qty1, $qty2)) {
    $sum = $qty1->add($qty2);
}
```

### Formatting for Display

[](#formatting-for-display)

```
// Format with locale-specific separators
echo $weight->format('en_US'); // "100.50 kg"
echo $weight->format('de_DE'); // "100,50 kg"
```

### Serialization

[](#serialization)

```
// To array
$array = $quantity->toArray();
// ['value' => 100.5, 'unit' => 'kg']

// To JSON
$json = $quantity->toJson();
// {"value":100.5,"unit":"kg"}

// From array
$quantity = Quantity::fromArray(['value' => 100.5, 'unit' => 'kg']);
```

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

[](#architecture)

This package follows the **"Logic in Packages, Implementation in Applications"** principle:

- **Package Layer** (`packages/Uom/`): Framework-agnostic business logic

    - Interfaces defining all persistence needs
    - Value Objects for immutable data structures
    - Services containing conversion and validation logic
    - Domain-specific exceptions
- **Application Layer** (`apps/Atomy/`): Laravel-specific implementation

    - Eloquent models implementing package interfaces
    - Database migrations for schema
    - Repository implementations
    - Service provider for IoC bindings

Requirements Satisfied
----------------------

[](#requirements-satisfied)

This package satisfies **58 total requirements**:

- 10 Architectural Requirements
- 10 Business Requirements
- 13 Functional Requirements
- 5 Performance Requirements
- 5 Security Requirements
- 5 Reliability Requirements
- 10 User Stories

See `docs/UOM_IMPLEMENTATION.md` for complete requirement mapping.

Dependencies
------------

[](#dependencies)

**Package Dependencies:**

- PHP ^8.2
- No framework dependencies

**Atomy Implementation Dependencies:**

- Laravel 12
- Laravel Eloquent ORM

Testing
-------

[](#testing)

```
# Package tests (unit tests, no database)
cd packages/Uom
composer test

# Atomy tests (feature tests with database)
cd apps/Atomy
php artisan test --filter=Uom
```

Documentation
-------------

[](#documentation)

- [Complete Implementation Guide](../../docs/UOM_IMPLEMENTATION.md)
- [Architecture Documentation](../../ARCHITECTURE.md)
- [Requirements Specification](../../REQUIREMENTS.csv)

Security
--------

[](#security)

- Tenant isolation enforced at application layer
- Audit logging for custom unit creation
- Version tracking for conversion ratio changes
- System unit protection (cannot delete/modify)

Performance
-----------

[](#performance)

- Simple conversions: &lt; 5ms
- Multi-hop conversions (up to 5 hops): &lt; 20ms
- Arithmetic operations with conversion: &lt; 10ms
- Conversion path caching for repeated operations
- Supports 1,000+ defined units without degradation

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

For issues, questions, or contributions, please refer to the main Nexus monorepo documentation.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance93

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76.6% 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

36d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/117408?v=4)[Azahari Zaman](/maintainers/azaharizaman)[@azaharizaman](https://github.com/azaharizaman)

---

Top Contributors

[![azaharizaman](https://avatars.githubusercontent.com/u/117408?v=4)](https://github.com/azaharizaman "azaharizaman (461 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (139 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/azaharizaman-nexus-uom/health.svg)

```
[![Health](https://phpackages.com/badges/azaharizaman-nexus-uom/health.svg)](https://phpackages.com/packages/azaharizaman-nexus-uom)
```

PHPackages © 2026

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