Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Structarmed Laravel Package

boundwize/structarmed

StructArmed is a dev-only PHP architecture guard: define layers and dependency rules, start from presets (PSR-4/1/12, MVC, DDD), then tune or skip checks in PHP. Run it in CI to catch boundary violations before they become conventions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

StructArmed is a static architecture enforcement tool designed to validate PHP/Laravel projects against predefined architectural rules (e.g., layer isolation, PSR standards, DDD, MVC). It aligns well with Laravel’s modular, layered architecture (e.g., App/, Domain/, Infrastructure/), making it ideal for enforcing:

  • Layer dependencies (e.g., DomainApplicationInfrastructure).
  • PSR compliance (PSR-1, PSR-4, PSR-12, PSR-15).
  • Custom business rules (e.g., "Controllers must not depend on Domain entities").
  • Legacy migration via baselines.

Key Strengths:

  • Declarative configuration: Define rules in structarmed.php (e.g., layer(), ruleset(), presets).
  • Preset-driven: Prebuilt rules for DDD, MVC, PSR standards, and Laravel-like structures.
  • Customizable: Override or extend rules via replaceRule() or rule().
  • CI/CD integration: Fail builds on violations or generate baselines for gradual adoption.

Potential Gaps:

  • No runtime enforcement: Only static analysis (violations are detected post-code-writing).
  • Laravel-specific features: Limited native support for Laravel’s service container, Facades, or Blade templates (though custom rules can mitigate this).
  • Performance overhead: Parallel analysis is default, but large codebases may require tuning (--disable-parallel).

Integration Feasibility

Laravel Compatibility:

  • High: StructArmed is PHP-agnostic but works seamlessly with Laravel’s directory structure (e.g., app/, src/, database/).
  • Dependencies: Requires PHP 8.1+ (Laravel 9+ compatible). No Laravel-specific dependencies.
  • Tooling Integration:
    • PHPUnit: Fail tests on violations via StructArmedExtension.
    • CI/CD: JSON reports for tools like GitHub Actions or GitLab CI.
    • IDE: Static analysis tools (PHPStan, Psalm) can leverage rule constants for better autocompletion.

Migration Path:

  1. Initial Setup:
    • Install as a dev dependency (composer require --dev boundwize/structarmed).
    • Generate a baseline (structarmed analyse --generate-baseline).
  2. Incremental Enforcement:
    • Start with lightweight presets (e.g., PSR4, PSR12).
    • Gradually add stricter rules (e.g., DDD, MVC).
  3. Customization:
    • Define layers via layer() or layerPattern() (e.g., Domain, Application).
    • Enforce layer isolation with ruleset().
    • Skip legacy paths or known violations.

Example Laravel Integration:

// structarmed.php
use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;

return Architecture::define()
    ->layer('Domain', 'app/Domain/')
    ->layer('Application', 'app/Application/')
    ->layer('Infrastructure', 'app/Infrastructure/')
    ->ruleset([
        'Domain'       => [],          // Domain has no dependencies
        'Application'  => ['Domain'],  // App can depend on Domain
        'Infrastructure' => ['Application'], // Infra can depend on App
    ])
    ->withPresets(Preset::PSR12(), Preset::DDD())
    ->skipPaths(['tests/', 'vendor/']);

Technical Risk

Risk Area Assessment Mitigation
False Positives Custom rules or complex layer patterns may flag legitimate dependencies. Use skipClassViolation() for exceptions; test rules incrementally.
Performance Parallel analysis may slow CI/CD for large codebases. Disable parallel mode (--disable-parallel) or limit paths.
Rule Maintenance Custom rules require ongoing updates as architecture evolves. Document rules in structarmed.php; use presets where possible.
Laravel-Specific Quirks Facades, Blade, or dynamic class loading may trigger false violations. Exclude paths (e.g., resources/) or use skipPathsForRuleset().
Tooling Ecosystem Limited adoption (0 dependents) may lack community support. Leverage GitHub issues/Slack for questions; contribute custom presets.

Key Questions for TPM:

  1. Architecture Goals:
    • Are we enforcing layer isolation (e.g., DDD), PSR compliance, or both?
    • Should rules be strict (fail builds) or advisory (baseline + warnings)?
  2. Tooling Integration:
    • Will violations be checked in CI/CD (e.g., GitHub Actions) or pre-commit (e.g., Laravel Pint hooks)?
    • Should StructArmed replace or complement existing tools (e.g., PHPStan, Pest)?
  3. Customization Needs:
    • Do we need Laravel-specific rules (e.g., "Controllers must extend BaseController")?
    • How will we handle legacy code (baselines vs. refactoring)?
  4. Performance:
    • What’s the max acceptable analysis time in CI?
    • Should we cache results between runs (configurable via cacheDirectory)?
  5. Team Adoption:
    • How will developers debug violations (e.g., IDE integration, CLI flags)?
    • Will we train teams on reading rule outputs?

Integration Approach

Stack Fit

StructArmed is language-agnostic but optimally fits Laravel’s modular, layered architecture. Key alignments:

  • Directory Structure: Maps naturally to Laravel’s app/, src/, or custom namespaces.
  • Dependency Management: Composer-based (no Laravel-specific dependencies).
  • Tooling Ecosystem:
    • PHPUnit: Native extension for test-time enforcement.
    • CI/CD: JSON reports for integration with tools like SonarQube.
    • IDE: Rule constants enable static analysis tooling (PHPStan/Psalm).

Laravel-Specific Considerations:

  • Facades/Helpers: May require skipPaths() to avoid false positives.
  • Blade Templates: Exclude resources/views/ from ruleset checks.
  • Service Container: Custom rules can enforce container binding patterns (e.g., "Only App\Services\* can be bound to Illuminate\Contracts\*").

Migration Path

Phase Action Tools/Commands
Assessment Audit current architecture against target (e.g., DDD, Clean Architecture). Manual review + structarmed analyse --preset=all --report=json.
Baseline Creation Generate a baseline to capture existing violations. structarmed analyse --generate-baseline=baseline.php.
Preset Selection Start with lightweight presets (e.g., PSR12, PSR4). Edit structarmed.php; run structarmed analyse.
Layer Definition Map Laravel directories to StructArmed layers (e.g., Domain, Infrastructure). Use layer() or layerPattern() in config.
Rule Enforcement Incrementally add stricter rules (e.g., DDD, MVC). Use withPreset(); test with --report=json for CI integration.
Customization Add project-specific rules (e.g., "API layer must not depend on Domain"). Use rule() or replaceRule() in structarmed.php.
CI/CD Integration Fail builds on violations or require baseline compliance. Add to phpunit.xml or GitHub Actions workflow.
Legacy Handling Skip known violations or refactor incrementally. Use skipPaths() or skipClassViolation().

Example Migration Timeline:

  1. Week 1: Install StructArmed, generate baseline, enforce PSR12.
  2. Week 2: Define layers (Domain, Application), enforce DDD presets.
  3. Week 3: Add custom rules (e.g., "Controllers must not call DB::raw()").
  4. Week 4: Integrate with CI/CD; require compliance in PRs.

Compatibility

Component Compatibility Notes
PHP Version 8.1+ (Laravel 9+ compatible). Check composer.json for PHP version.
Laravel Version 9
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity