Skip to content

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

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!

Activity

  1. added
    enhancement
    on May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions