laravel-brain  by laramint

Visualize and analyze Laravel application architecture

Created 2 months ago
848 stars

Top 41.3% on SourcePulse

GitHubView on GitHub
Project Summary

LaraMint\LaravelBrain visualizes Laravel application request lifecycles as interactive graphs, enabling developers to quickly understand complex codebases. It analyzes routes, controllers, services, models, jobs, events, commands, and channels, providing a bird's-eye view to aid in debugging and architectural comprehension.

How It Works

The tool operates via the php artisan brain:scan command, which recursively analyzes PHP files within the routes/ directory and traces call chains from controller actions through services, repositories, models, jobs, and events. Specialized analyzers identify database queries, Eloquent relationships, Artisan commands, scheduled tasks, and broadcast channels. The collected data is assembled into a graph structure and served as a React Single Page Application through Laravel routes, accessible via /_laravel-brain. This approach offers deep introspection without manual code reading.

Quick Start & Requirements

  • Installation: Install as a development dependency using Composer: composer require --dev laramint/laravel-brain. Laravel auto-discovers the service provider.
  • Requirements: PHP 8.0+ and Laravel 9, 10, 11, or 13.
  • Usage: Run php artisan brain:scan to analyze the project. Then, navigate to the provided URL (e.g., http://localhost:8000/_laravel-brain) in your browser while your Laravel application is running.
  • Watch Mode: Automatically re-scans on PHP file changes with php artisan brain:scan --watch.

Highlighted Details

  • Comprehensive Tracing: Maps full request lifecycles, including HTTP verbs, controllers, services, models, jobs, events, Artisan commands, scheduled tasks, broadcast channels, and database queries.
  • AI Integration: Generates deterministic, token-optimized context snapshots for LLMs (e.g., Claude, Copilot) via the UI or brain:export-context command. It can also generate AI assistant rule files (brain:generate-rules) for various coding assistants.
  • Interactive Visualization: Features dark/light themes, accent-colored nodes, interactive edges, per-route subgraph tabs, method flowcharts, and an inline source viewer.
  • Route Stress Testing: Integrates laramint/laravel-stress to perform concurrent HTTP load tests directly from a selected route node within the UI.
  • Export Options: Supports exporting graphs as PNG or Mermaid diagrams, AI context, and AI rules files.
  • Fat-Class Detection: Flags controllers and services exceeding predefined line or method count thresholds.

Maintenance & Community

The project welcomes pull requests. While specific community links (Discord/Slack) or notable contributors are not detailed in the README, the project actively supports recent Laravel versions up to 13, indicating ongoing maintenance.

Licensing & Compatibility

  • License: MIT License.
  • Compatibility: Permissive for commercial use. Designed as a development dependency; it is excluded from production builds via composer install --no-dev. Routes are registered only in the local environment by default.

Limitations & Caveats

This tool is strictly for development and should not be present in production environments. By default, its routes are only registered locally. If deployed in a networked, non-production environment, securing the /_laravel-brain routes with appropriate middleware is recommended. Target hosts for stress testing are enforced by the package.

Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
14
Issues (30d)
1
Star History
61 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.