Installation
composer require --dev laramint/laravel-brain
No manual configuration or service provider registration is needed.
First Scan
php artisan brain:scan
This generates a graph JSON file in storage/app/laravel-brain/ and outputs the URL to access the viewer:
Done! Open the viewer at: http://localhost:8000/_laravel-brain
Access the Viewer
Navigate to /_laravel-brain in your browser while running php artisan serve or your Laravel application server.
Understand a Route Flow
GET /users).Code Review & Onboarding
php artisan brain:scan after major changes or when onboarding new developers.Debugging
Architecture Documentation
🤖 button) and share it with team members or AI assistants.php artisan brain:generate-rules) to populate coding guidelines for tools like GitHub Copilot or Cursor.Filament Development
Watch Mode for Live Development
php artisan brain:scan --watch --interval=5
Auto-rescans on PHP file changes, keeping the graph up-to-date without manual triggers.
Memory Management For large codebases, adjust the memory limit:
php artisan brain:scan --memory-limit=2G
Auto-Discover Routes Enable auto-discovery for programmatically registered routes (e.g., Filament, Sanctum):
php artisan brain:scan --auto-discover
Or configure it in .env:
LARAVEL_BRAIN_AUTO_DISCOVER_ROUTES=true
Export Context for AI Generate deterministic context for any node via:
php artisan brain:export-context --route="GET /users" --output=/tmp/context.md
Or use the API:
GET /_laravel-brain/api/context?route=GET+/users&format=json
Stress Testing Test route performance directly from the graph:
Auto-Discover Mode Limitations
Route::getRoutes() lack source file/line metadata.Memory Constraints
--memory-limit as needed.--memory-limit=-1 (unlimited) in CI/CD unless necessary.Vendor Route Exclusion
vendor/ classes (e.g., Telescope) are excluded.LARAVEL_BRAIN_AUTO_DISCOVER_EXCLUDE_VENDOR=false
Filament Auto-Discovery
composer require filament/filament) for panel/resource tracing.->discoverResources() is misconfigured.Watch Mode Stability
--interval for faster feedback.Clear Old Scans
Delete storage/app/laravel-brain/ to force a fresh scan if the graph appears stale.
Check Scan Logs
Run with --verbose for detailed tracing:
php artisan brain:scan --verbose
Isolate Nodes Use the Breadth-First layout to focus on a specific route’s call chain.
Query Tracing Filter nodes by type (e.g., Model) to locate DB-heavy operations.
Custom Node Styling
Override node colors or shapes by extending the BrainController or modifying the React SPA (located in vendor/laramint/laravel-brain/resources/js).
Additional Analyzers
Extend the scanner by adding a custom analyzer (e.g., for laravel-nova or livewire components) by implementing the AnalyzerInterface.
API Hooks
Use the /_laravel-brain/api/context endpoint to build custom integrations (e.g., CI/CD reports or documentation generators).
Graph Layouts Experiment with layouts (e.g., Circle, Grid) via the viewer’s layout dropdown to optimize readability for specific use cases.
Large Graphs Complex applications may slow down the viewer. Use the Force-Directed layout for better performance with dense graphs.
Stress Test Overhead Concurrent requests during stress tests may impact your local machine. Limit concurrency for testing:
php artisan brain:stress-test --concurrency=5
Watch Mode Polling
High --interval values (e.g., 1) may cause excessive rescans. Balance responsiveness with resource usage.
How can I help you explore Laravel packages today?