PHPackages                             decodelabs/monarch - 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. decodelabs/monarch

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

decodelabs/monarch
==================

A single shared source of truth for your PHP apps

v0.2.3(8mo ago)08.3k20MITPHPPHP ^8.4CI passing

Since Apr 9Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/decodelabs/monarch)[ Packagist](https://packagist.org/packages/decodelabs/monarch)[ RSS](/packages/decodelabs-monarch/feed)WikiDiscussions develop Synced today

READMEChangelog (10)Dependencies (5)Versions (12)Used By (20)

Monarch
=======

[](#monarch)

[![PHP from Packagist](https://camo.githubusercontent.com/a6e383060cda9605a6fa85b69de392e524c457dc3bfa4a1f1942e16bfa2e20a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f6d6f6e617263683f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/monarch)[![Latest Version](https://camo.githubusercontent.com/943d14ac627c2bf8dcefa6cc41fea6c7599a1e1f0cb4380d0c0a55bcad6e11e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f6d6f6e617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/monarch)[![Total Downloads](https://camo.githubusercontent.com/88dbe741a0b6c97f963fafd18f74e68d73e40262bb2654c2cfcff5fa3e3fc0a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f6d6f6e617263682e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/monarch)[![GitHub Workflow Status](https://camo.githubusercontent.com/e87580df3fcd16f534d4451e5a68ec8c7f61f5115276a48639bb06c955ee6a0e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f6d6f6e617263682f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/monarch/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/8c31f297d682f7370db6e7cc7cfcab296a5418298f8c258908606b53286099c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f6d6f6e617263683f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/monarch)

### A single shared source of truth for your PHP apps

[](#a-single-shared-source-of-truth-for-your-php-apps)

Monarch provides a single shared source of truth for your PHP applications. It allow commonly referenced paths and items to be centralised into a predictable location, making it easier to manage accessing that data from code that needs to maintain minimal coupling to the rest of the application.

It acts as the top level oversight for your entire application space and acts as an orchestrator for your application's container and services within.

`Monarch` works in tandem with [Kingdom](https://github.com/decodelabs/kingdom) - it manages the *active* `Kingdom` instance that in turn contains all of your application's services.

---

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

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/monarch
```

Usage
-----

[](#usage)

Monarch should be populated in your bootstrap otherwise it will use reasonable defaults where possible. If you use `Genesis` to bootstrap your application, Monarch will be automatically populated for you.

For example:

```
use DecodeLabs\Monarch;
$paths = Monarch::getPaths();

$paths->root = '/var/www/my-cool-app';
$paths->run = '/var/www/my-cool-app/dist';
$paths->localData = '/var/www/my-cool-app/data/local';
$paths->sharedData = '/var/www/my-cool-app/data/shared';

Monarch::setKingdom(new MyKingdom());
```

### Path aliasing

[](#path-aliasing)

Monarch allows you to define aliases for commonly used paths. This is useful for avoiding hardcoded paths in your codebase. `@root` and `@run` are automatically defined for you, but you can define your own aliases as needed.

```
$paths->alias('@components', '@root/components');
$paths->alias('@assets', '@root/assets');
```

You can then use these aliases in your code:

```
$path = $paths->resolve('@components/MyComponent.php');
// /var/www/my-cool-app/components/MyComponent.php
```

### Services

[](#services)

Monarch provides a simple way to access `Kingdom`services from your application. Services must implement the Kingdom `Service` interface and may provide the ability to self-instantiate.

```
$service = Monarch::getService(MyService::class);
```

This method is a simple wrapper around the `getService()` method of the active `Kingdom` instance. It will only work if you supply an instance of the `Kingdom` interface in your bootstrap.

While this method is useful for quick access to services, it is not recommended for regular use as it is essentially an implementation of the Service Locator pattern. It *works*, but is inflexible and can lead to tight coupling between your code and the container.

Instead, the `Kingdom` instance provided to `Monarch` is also made available to [Slingshot](https://github.com/decodelabs/slingshot) which can then be used to automatically inject services into your code.

Many common DecodeLabs libraries use `Slingshot` in their architecture and allow arbitrary constructor parameters to be handled seamlessly.

Licensing
---------

[](#licensing)

Monarch is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance76

Regular maintenance activity

Popularity24

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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

Every ~20 days

Total

10

Last Release

269d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (43 commits)")

---

Tags

appcontainerphpsingleton

### Embed Badge

![Health badge](/badges/decodelabs-monarch/health.svg)

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.3k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/packages/illuminate-container)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k52](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M270](/packages/symfony-type-info)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

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