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

0.8.0(3mo ago)8853.8M—0.6%53[10 PRs](https://github.com/phparkitect/arkitect/pulls)15MITPHPPHP ^7.4|^8CI passing

Since Jul 11Pushed 1mo 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 1mo ago

READMEChangelog (10)Dependencies (15)Versions (153)Used By (15)

📐 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)

1. [Introduction](#introduction)
2. [Quick Start](#quick-start)
3. [Installation](#installation)
4. [Usage](#usage)
5. [Available rules](#available-rules)
6. [Rule Builders](#rule-builders)
7. [Integrations](#integrations)

Introduction
============

[](#introduction)

**PHPArkitect** is a tool to enforce architectural constraints in your PHP codebase. It helps you maintain clean architecture by preventing violations of your design rules during development and in CI/CD pipelines.

Why PHPArkitect?
----------------

[](#why-phparkitect)

As projects grow, maintaining architectural consistency becomes challenging. PHPArkitect helps you:

- **Prevent architectural drift**: Ensure your Domain layer doesn't depend on Infrastructure code
- **Enforce naming conventions**: Make sure all Controllers end with "Controller", all Services with "Service", etc.
- **Maintain layered architecture**: Keep your application, domain, and infrastructure layers properly separated
- **Catch violations early**: Get immediate feedback in your IDE or CI pipeline before code review
- **Document architecture as code**: Your architectural rules become executable and self-documenting

Example
-------

[](#example)

You can express architectural constraints in simple, readable PHP code:

```
Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
    ->should(new HaveNameMatching('*Controller'))
    ->because('it\'s a symfony naming convention');

Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App\Domain'))
    ->should(new NotHaveDependencyOutsideNamespace('App\Domain'))
    ->because('we want to protect our domain from external dependencies');
```

Since selecting classes by namespace is very common, there's a convenient shortcut:

```
Rule::namespace('App\Controller')
    ->should(new HaveNameMatching('*Controller'))
    ->because('it\'s a symfony naming convention');
```

You can also specify multiple namespaces: `Rule::namespace('App\Controller', 'App\Service')`.

Quick Start
===========

[](#quick-start)

Get started with PHPArkitect in 3 simple steps:

1. Install via Composer
-----------------------

[](#1-install-via-composer)

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

2. Create a configuration file
------------------------------

[](#2-create-a-configuration-file)

Create a `phparkitect.php` file in your project root:

```
