PHPackages                             phparkitect/phparkitect - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. phparkitect/phparkitect

ActiveLibrary[Testing &amp; Quality](/categories/testing)

phparkitect/phparkitect
=======================

Enforce architectural constraints in your PHP applications

1.1.1(1mo ago)9224.3M↓26.2%52[20 issues](https://github.com/phparkitect/arkitect/issues)[13 PRs](https://github.com/phparkitect/arkitect/pulls)17MITPHPPHP ^8.0CI passing

Since Jul 11Pushed 1w ago11 watchersCompare

[ Source](https://github.com/phparkitect/arkitect)[ Packagist](https://packagist.org/packages/phparkitect/phparkitect)[ GitHub Sponsors](https://github.com/AlessandroMinoccheri)[ GitHub Sponsors](https://github.com/micheleorselli)[ RSS](/packages/phparkitect-phparkitect/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (57)Versions (184)Used By (17)

📐 PHPArkitect
=============

[](#-phparkitect)

[![Latest Stable Version](https://camo.githubusercontent.com/f8c42f1137854ae137cb862049f584674e754db47fca0c571da921cd1e69859a/68747470733a2f2f706f7365722e707567782e6f72672f70687061726b69746563742f70687061726b69746563742f762f737461626c65)](https://packagist.org/packages/phparkitect/phparkitect) [![PHPArkitect](https://github.com/phparkitect/arkitect/actions/workflows/build.yml/badge.svg)](https://github.com/phparkitect/arkitect/actions/workflows/build.yml/badge.svg) [![Packagist](https://camo.githubusercontent.com/d6dae0170ef1857b87a36450709bd6a00e5311a1919c58c2fc8444f6c0bbd6e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687061726b69746563742f70687061726b69746563742e737667)](https://packagist.org/packages/phparkitect/phparkitect) [![codecov](https://camo.githubusercontent.com/021d7a380d501dad159354fa836b2dbba52ddf187438ff8d17beb0c9508b3af3/68747470733a2f2f636f6465636f762e696f2f67682f70687061726b69746563742f61726b69746563742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/phparkitect/arkitect)

**PHPArkitect** lets you write architectural rules for your PHP codebase as plain PHP code and verify them in CI. Think of it as a test suite for your architecture: if a class in `App\Domain` imports something from `App\Infrastructure`, the check fails.

```
Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
    ->should(new NotHaveDependencyOutsideNamespace('App\Domain'))
    ->because('the domain must not depend on infrastructure');
```

> Upgrading from an older version? Check [UPGRADE.md](UPGRADE.md) for breaking changes.

Quick Start
-----------

[](#quick-start)

**1. Install**

```
composer require --dev phparkitect/phparkitect
```

**2. Create a config file**

```
vendor/bin/phparkitect init
```

This scaffolds `phparkitect.php` in the current directory. Edit it to add your rules.

**3. Run**

```
vendor/bin/phparkitect check
```

PHPArkitect reports every violation with the class name, the broken rule, and the `->because()` message you wrote.

Core concepts
-------------

[](#core-concepts)

ConceptWhat it is`ClassSet`The set of PHP files to analyse. `ClassSet::fromDir(__DIR__.'/src')` accepts one or more directories.`Rule`A constraint: a selector (`that()`), a check (`should()`), and a reason (`because()`). The `because()` string appears verbatim in violation output.`Expression`A single, composable condition — used in both `that()` and `should()`.`except()`Excludes specific classes from a rule's selector. Accepts wildcards.`andThat()`Narrows the selector with additional conditions (all must match).`runOnlyThis()`Runs only this rule during `check`; useful for debugging.A minimal config file:

```
