Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smortexa/laravel-arkitect

Test and enforce architectural rules in your Laravel applications. Keep your app's architecture clean and consistent!
https://github.com/smortexa/laravel-arkitect

architecture laravel php testing

Last synced: about 4 hours ago
JSON representation

Test and enforce architectural rules in your Laravel applications. Keep your app's architecture clean and consistent!

Awesome Lists containing this project

README

        

![art/laravel-arkitect.png](art/laravel-arkitect.png)
# Laravel Arkitect

[![Latest Stable Version](http://poser.pugx.org/mortexa/laravel-arkitect/v)](https://packagist.org/packages/mortexa/laravel-arkitect) [![Total Downloads](http://poser.pugx.org/mortexa/laravel-arkitect/downloads)](https://packagist.org/packages/mortexa/laravel-arkitect) [![Latest Unstable Version](http://poser.pugx.org/mortexa/laravel-arkitect/v/unstable)](https://packagist.org/packages/mortexa/laravel-arkitect) [![License](http://poser.pugx.org/mortexa/laravel-arkitect/license)](https://packagist.org/packages/mortexa/laravel-arkitect) [![PHP Version Require](http://poser.pugx.org/mortexa/laravel-arkitect/require/php)](https://packagist.org/packages/mortexa/laravel-arkitect)

Laravel Arkitect lets you test and enforce your architectural rules in your Laravel applications, and it's
a [PHPArkitect](https://github.com/phparkitect/arkitect) wrapper for Laravel. This package helps you to keep your app's
architecture clean and consistent.

```
├─ storage
├─ tests
│ ├─ Architecture ✅
│ ├─ Browser
│ ├─ Feature
│ └─ Unit
└─ vendor
```

## Installation

You can install the package via Composer:

```
composer require mortexa/laravel-arkitect --dev
```

## Usage

First, you should create your architectural rules by running the following Artisan command:

`php artisan make:arkitect ControllersNaming`

By running the command, the `ControllersNaming.php` file will be created in your application's `tests/Architecture` directory like this:

```php
If you want to stop checking command immediately after first violation, you can use `--stop-on-failure` option.

For all available rules, please take a look at the PHPArkitect repository: https://github.com/phparkitect/arkitect

### Default rules

Some opinionated rules are provided by the package and apply by default. These rules are about Laravel user-land structure. You are free to customize or ignore them entirely by [publishing config file](#configuration).

## Example

```php
that(new ResideInOneOfTheseNamespaces('App\Http\Controllers'))
->should(new HaveNameMatching('*Controller'))
->because('It\'s a Laravel naming convention');
}

public static function path(): string
{
return 'app/Http/Controllers';
}
}
```

## Configuration

If you want to customize the default rules provided by the package, You can publish the Laravel Arkitect configuration file using the following Artisan command:

`php artisan vendor:publish --provider="Mortexa\LaravelArkitect\ArkitectServiceProvider" --tag="config"`

The `arkitect` configuration file will be placed in your application's `config` directory.

```php
// config/arkitect.php

[
'naming' => [
ControllersNaming::class,
ExceptionsNaming::class,
NotificationsNaming::class,
ObserversNaming::class,
ProvidersNaming::class,
RequestsNaming::class,
ResourcesNaming::class,
ChannelsNaming::class,
SeedersNaming::class,
PoliciesNaming::class,
FactoriesNaming::class,
ScopesNaming::class,
BuildersNaming::class,
ContractsNaming::class,
RepositoriesNaming::class,
MailsNaming::class,
],
'extending' => [
ControllersExtending::class,
CommandsExtending::class,
ExceptionsExtending::class,
RequestsExtending::class,
ResourcesExtending::class,
ResourceCollectionsExtending::class,
ModelsExtending::class,
NotificationsExtending::class,
ProvidersExtending::class,
ViewsExtending::class,
FactoriesExtending::class,
SeedersExtending::class,
MailsExtending::class,
],
'implementing' => [
RulesImplementing::class,
CastsImplementing::class,
ScopesImplementing::class,
JobsImplementing::class,
],
],
'ignored_namespaces' => [],
];
```
### Ignore namespaces
If you want to ignore any namespaces from being under architectural test, you should add the related path to `ignored_namespaces` key in configuration file.
## Contributing

Thank you for considering contributing! If you find an issue, or have a better way to do something, feel free to open an
issue, or a PR.

## Licence

This repository is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).