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

Php Structure Discoverer Laravel Package

spatie/php-structure-discoverer

Discover PHP classes, interfaces, traits, and enums that match conditions (e.g., implement an interface) across your project. Fast scanning with built-in caching and rich metadata—ideal for auto-registration, tooling, and framework integrations.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Native Integration: The package is designed with Laravel in mind, offering built-in Laravel cache drivers, Artisan commands, and config publishing. This aligns seamlessly with Laravel’s ecosystem, reducing friction for adoption.
  • Modular Design: The package follows a fluent, chainable API (e.g., Discover::in()->classes()->implementing()), which is intuitive and composable. This fits well with Laravel’s expressive syntax and dependency injection patterns.
  • Extensibility: Supports custom conditions, cache drivers, and parallel processing, allowing TPMs to tailor behavior for specific use cases (e.g., large codebases, performance-critical paths).
  • Metadata-Rich Output: Returns structured objects (DiscoveredClass, DiscoveredInterface, etc.) with inheritance chains, attributes, and file metadata. This is valuable for tooling, migrations, or dynamic feature flags.

Integration Feasibility

  • Low Coupling: The package operates on filesystem paths and class reflection, with minimal Laravel-specific dependencies (e.g., cache drivers). Can be integrated into non-Laravel PHP projects with minor adjustments.
  • Dependency Graph: Requires amphp/parallel for parallel scanning (optional but recommended for large codebases). No other heavy dependencies.
  • Backward Compatibility: MIT-licensed with a mature API (last release 2026). Risk of breaking changes is low, but TPMs should validate against their PHP/Laravel version.
  • Testing: Includes CI workflows for PHPStan and tests, indicating robustness. TPMs should add unit tests for custom conditions or cache strategies.

Technical Risk

  • Performance Overhead:
    • Initial discovery scans can be slow for large codebases (mitigated by caching and parallel processing).
    • Chain resolution (inheritance graphs) is resource-intensive. Disable with withoutChains() if not needed.
  • Cache Invalidation:
    • Cached results may stale if files change. TPMs must design a cache-warming strategy (e.g., post-deploy Artisan command).
    • No built-in event listeners for file changes (e.g., Laravel’s filesystem.updated). TPMs may need to integrate with spatie/laravel-medialibrary or similar.
  • Edge Cases:
    • Custom autoloading (e.g., dynamic class loading) may break discovery. Test with composer dump-autoload.
    • Namespace collisions or ambiguous class names could require custom conditions.

Key Questions for TPM

  1. Use Case Priority:
    • Is this for runtime discovery (e.g., dynamic feature toggles) or build-time analysis (e.g., migrations, linting)?
    • If runtime, prioritize cache strategies and parallel scanning.
  2. Scale:
    • How large is the codebase? For >10K classes, test parallel processing and chain resolution tradeoffs.
  3. Cache Strategy:
    • Will caches be warmed manually (Artisan) or automatically (e.g., post-deploy hook)?
    • Is a custom cache driver needed (e.g., Redis for distributed caching)?
  4. Maintenance:
    • Who owns cache invalidation? Will deployments trigger structure-scouts:cache?
  5. Alternatives:
    • Could phpDocumentor or Symfony ClassLoader meet needs with less overhead?
    • For Laravel, does laravel-zero or roave/security-advisories offer similar functionality?

Integration Approach

Stack Fit

  • Laravel: Ideal fit. Leverages Laravel’s cache, config, and Artisan systems out-of-the-box.
  • Non-Laravel PHP: Feasible but requires manual setup (e.g., custom cache drivers, no Artisan commands).
  • Monorepos: Supports multi-directory discovery (e.g., Discover::in(app_path(), package_path())).
  • Tooling: Integrates with:
    • Static Analysis: Feed results to PHPStan, Psalm, or custom linters.
    • Dynamic Features: Use for runtime class discovery (e.g., plugin systems).
    • Migrations: Generate schema or data migrations based on discovered models.

Migration Path

  1. Pilot Phase:
    • Install via Composer: composer require spatie/php-structure-discoverer.
    • Publish config: php artisan vendor:publish --tag="structure-discoverer-config".
    • Test basic discovery in a non-critical module (e.g., Discover::in(app_path('Models'))->get()).
  2. Cache Integration:
    • Configure structure_scout_directories in config/structure-discoverer.php.
    • Warm caches post-deploy: php artisan structure-scouts:cache.
  3. Advanced Features:
    • Implement custom conditions for complex filtering.
    • Enable parallel scanning for large codebases.
    • Integrate with CI/CD to auto-warm caches.
  4. Production Rollout:
    • Monitor cache hit/miss ratios.
    • Set up cache invalidation triggers (e.g., Git hooks, deploy scripts).

Compatibility

  • Laravel Versions: Tested with modern Laravel (8+). Validate against your version’s PHP reflection and cache APIs.
  • PHP Versions: Requires PHP 8.0+. Check for amphp/parallel compatibility if using parallel scanning.
  • Autoloading: Ensure composer dump-autoload is run post-install.
  • IDE Support: No IDE-specific features, but metadata-rich output aids tooling (e.g., PhpStorm’s "Go to Implementation").

Sequencing

  1. Discovery:
    • Start with simple queries (e.g., Discover::in()->classes()->get()).
    • Gradually introduce conditions (e.g., implementing(), withAttribute()).
  2. Caching:
    • Implement StructureScout for reusable queries.
    • Test cache invalidation workflows.
  3. Performance:
    • Benchmark parallel scanning vs. sequential for your codebase size.
    • Profile chain resolution (extendsChain, implementsChain) overhead.
  4. Integration:
    • Hook into Laravel events (e.g., Illuminate\Foundation\Bootstrap\LoadConfiguration) for auto-cache warming.
    • Expose discovered structures via API or service container for other packages.

Operational Impact

Maintenance

  • Cache Management:
    • Pros: Dramatically reduces discovery time in production (cached results).
    • Cons: Requires manual or automated cache invalidation. Add structure-scouts:clear to deploy scripts if needed.
  • Configuration:
    • Centralized in config/structure-discoverer.php. Easy to update ignored directories or cache drivers.
  • Dependencies:
    • Minimal (amphp/parallel optional). No major version conflicts expected.
  • Deprecation Risk:
    • Low. Spatie packages are stable, but monitor for Laravel version drops.

Support

  • Debugging:
    • Use full() mode to inspect DiscoveredStructure objects for issues.
    • Log cache misses to identify stale data: Discover::in()->withCache('key', driver)->get().
  • Common Issues:
    • False Positives/Negatives: Validate custom conditions with edge cases (e.g., anonymous classes, dynamic imports).
    • Performance: Monitor Discover::in()->parallel()->get() for memory spikes in large codebases.
  • Community:
    • GitHub issues are responsive. Spatie offers paid support for enterprises.

Scaling

  • Horizontal Scaling:
    • Cache drivers (e.g., Redis) can distribute cache across instances.
    • Parallel scanning reduces discovery time but increases memory usage.
  • Vertical Scaling:
    • Disable chain resolution (withoutChains()) for large inheritance graphs.
    • Limit scan directories to essential paths (e.g., app_path(), not vendor/).
  • Load Testing:
    • Simulate production traffic with repeated cache misses to validate performance.

Failure Modes

Failure Scenario Impact Mitigation
Cache corruption Stale/incomplete results Use structure-scouts:clear or fallback to non-cached discovery.
Filesystem permission issues Discovery fails Ensure PHP process has read access to scanned directories.
Memory exhaustion (parallel scans) Crash or timeouts Reduce parallel batch size or disable parallel mode.
Custom condition bugs Incorrect filtering Unit test conditions with mock DiscoveredStructure objects.
Laravel cache driver failure Cached results unavailable Fallback to FileDiscoverCacheDriver or disable caching.

Ramp-Up

  • Onboarding:
    • Developers: 1–2 hours to understand fluent API and caching.
    • Ops: 30 mins to configure Artisan commands and cache warming.
  • Documentation:
    • README is comprehensive. Add internal docs for:
      • Cache invalidation workflows.
      • Custom condition examples.
      • Performance tuning tips.
  • Training:
    • Demo use cases (e.g., "How to find all Arrayable models").
    • Show cache hit/miss metrics in production.
  • Adoption Barriers:
    • Perceived Complexity: Start
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata