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

Overview

art/laravel-arkitect.png

Laravel Arkitect

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Laravel Arkitect lets you test and enforce your architectural rules in your Laravel applications, and it's a PHPArkitect 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:arkitekt ControllersNaming

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

<?php

namespace Tests\Architecture;

use Arkitect\Rules\DSL\ArchRule;
use Mortexa\LaravelArkitect\Contracts\RuleContract;
use Mortexa\LaravelArkitect\Rules\BaseRule;

class ControllersNaming extends BaseRule implements RuleContract
{
    /**
     * Define your architectural rule
     *
     * @link https://github.com/phparkitect/arkitect
     *
     * @return \Arkitect\Rules\DSL\ArchRule
     */
    public static function rule(): ArchRule
    {
        // TODO: Implement rule() method.
    }

    /**
     * Define the path related to your rule
     *
     * @example app/Http/Controllers
     *
     * @return string
     */
    public static function path(): string
    {
        // TODO: Implement path() method.
    }
}

Then, you must implement rule() and path() methods based on the following example.

And finally, you can run your tests by the following command:

php artisan test:arkitect

Done!

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.

Example

<?php

namespace Tests\Architecture;

use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\DSL\ArchRule;
use Arkitect\Rules\Rule;
use Mortexa\LaravelArkitect\Contracts\RuleContract;
use Mortexa\LaravelArkitect\Rules\BaseRule;

class ControllersNaming extends BaseRule implements RuleContract
{
    public static function rule(): ArchRule
    {
        return Rule::allClasses()
            ->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.

// config/arkitect.php

<?php

use ...

return [
    'rules' => [
        '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,
        ],
    ],
];

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.

You might also like...
A Laravel 9 package that allows you enforce security of your artisan commands by authenticating users before running.

Introduction This package allows you as a developer to restrict who can and cannot run artisan commands, especially in a production environment. For e

Task for GrumPHP that adds CSS linting support with stylelint. An easy way to enforce convention and avoid errors in your styles

grumphp-stylelint-task Installation Stylelint is a static analysis tool for styles. A mighty, modern linter that helps you avoid errors and enforce co

Enforce that your classes get only instantiated by the factories you define!

Enforce that your classes get only instantiated by the factories you define!

A place where Magento architectural discussions happen

This repository is created by initiative of Magento architects to discuss with the Magento community any open questions around Magento 2 architecture

The Lucid Architecture for Scalable Laravel Applications.
The Lucid Architecture for Scalable Laravel Applications.

Website: https://lucidarch.dev Documentation: https://docs.lucidarch.dev Social: we share updates & interesting content from the web Twitter: @lucid_a

Orkestra is a library of infrastructure and architecture helpers for creating CQRS applications

Orkestra Orkestra is an opinionated framework with a plethora of recommendations on architectural design that we use internally at Morebec to develop

Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.

Metrics Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics API that doesn't cau

Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Keep control over the complexity of your methods by checking that they do not have too many arguments.

php arguments detector The ideal number of arguments for a function is zero. ~ Robert C. Martin Keep control over the complexity of your methods by ch

Comments
  • WIP: Upgrade to phparkitect v0.3

    WIP: Upgrade to phparkitect v0.3

    Simple upgrade to phparkitect v0.3.

    Test it

    • clone this branch
    composer install
    vendor/bin/lint
    vendor/bin/pest
    

    Test it as a required vendor

        "repositories": [
            {
                "type": "vcs",
                "url": "[email protected]:abenevaut/laravel-arkitect.git"
            }
        ],
        "require": {
    
            "mortexa/laravel-arkitect": "dev-feat/upgrade-v0.3"
    
        },
        "minimum-stability": "dev",
        "prefer-stable" : true
    
    composer update
    
    opened by abenevaut 1
Releases(v0.4.0)
  • v0.4.0(Dec 27, 2022)

    What's Changed

    • Upgrade to phparkitect v0.3 by @abenevaut in https://github.com/smortexa/laravel-arkitect/pull/15

    New Contributors

    • @abenevaut made their first contribution in https://github.com/smortexa/laravel-arkitect/pull/15
    Source code(tar.gz)
    Source code(zip)
  • v0.3.3(Aug 19, 2022)

    What's Changed

    • Running tests using GitHub Actions by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/7
    • Fix tests by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/8
    • Auto-fix coding styles with GitHub Actions by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/10
    • Add name for lint job by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/12
    • Add rule loader by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/13
    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Aug 16, 2022)

  • v0.3.1(Aug 10, 2022)

  • v0.3.0(Aug 10, 2022)

  • v0.2.0(Aug 7, 2022)

    What's Changed

    • Change test command signature by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/1
    • Add more default rules for Laravel by @smortexa in https://github.com/smortexa/laravel-arkitect/pull/2
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Aug 5, 2022)

Owner
SMorteza Ebadi
SMorteza Ebadi
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
A Pocketmine-MP (PMMP) plugin to help staff members enforce the rules of the server.

StaffMode is an all-in-one Pocketmine-MP (PMMP) moderation plugin made to simplify the life of staff members.

ItsMax123 9 Sep 17, 2022
FFCMS 3 version core MVC architecture. Build-on use with ffcms main architecture builder.

FFCMS 3 version core MVC architecture. Build-on use with ffcms main architecture builder.

FFCMS 0 Feb 25, 2022
my personal example of Laravel clean architecture

what is this repo about Clean Architect Laravel ###run we assume docker desktop is up and running open up a terminal cd project directory run "cp .env

Sadegh Salari 37 Dec 23, 2022
Clean Architecture, DDD and CQRS using Symfony 6

Task manager system using Clean Architecture, DDD and CQRS. Environment setup Install Docker Clone the project: git clone https://github.com/k0t9i/Tas

null 3 Sep 5, 2022
POC d'un projet Clean Architecture + DDD

Proof Of Concept - Clean Architecture & DDD Installation Dans un premier temps, cloner le repository : git clone https://github.com/TBoileau/rse cd rs

Thomas Boileau 11 Sep 3, 2022
Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

null 48 Jan 5, 2023
Phpcs-magento-rules - A set of PHPCS rules used by made.com when hacking Magento

Made.com PHPCS Magento Rules A set of PHPCS rules used by made.com when hacking Magento. Pre-Requisites PHPCS Installation Short Version Clone this re

Made.com Tech Team 26 Jun 3, 2020
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
EBook-Apps - The eBook Apps is a web application that helps you browse ebooks from anywhere using your smartphone and laptop.

⚡️ eBook Apps The eBook Apps is a web application that helps you browse ebooks from anywhere using your smartphone and laptop. ?? Getting Started To s

Ahmad Fauzy 32 Nov 14, 2022