Skip to content

Suggestion: support for modular architecture rules via auto-loaded files #493

@pfazzi

Description

@pfazzi

I recently implemented a simple pattern that allows us to split our architectural rules across multiple files, making our phparkitect.php setup easier to scale and maintain as our codebase grows.

Here’s a simplified version of what we’re doing:

<?php

declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;

// Auto-require all PHP files in the architecture folder
foreach (glob(__DIR__.'/architecture/*.php') as $file) {
    require_once $file;
}

return static function (Config $config): void {
    $classSet = ClassSet::fromDir(__DIR__.'/src');

    $allRules = [];

    foreach (get_defined_functions()['user'] as $fn) {
        if (str_ends_with($fn, 'architecturerules')) {
            foreach ($fn() as $rule) {
                $allRules[] = $rule;
            }
        }
    }

    $config->add($classSet, ...$allRules);
};

Each file inside the /architecture folder defines a single function (e.g. clockArchitectureRules, quotingArchitectureRules, etc.) that returns an iterable of rules.

I'm sharing this in case it could inspire a similar built-in feature, or if we'd be interested in documenting this pattern as a recommended practice.

Happy to hear your thoughts!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions