Laravel Architecture Patterns
Agent Workflow (MANDATORY)
Before ANY implementation, use TeamCreate to spawn 3 agents:
- fuse-ai-pilot:explore-codebase - Analyze existing architecture
- fuse-ai-pilot:research-expert - Verify Laravel patterns via Context7
- mcp__context7__query-docs - Check service container and DI patterns
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
Laravel architecture focuses on clean separation of concerns, dependency injection, and maintainable code organization. This skill covers everything from project structure to production deployment.
When to Use
- Structuring new Laravel projects
- Implementing services, repositories, actions
- Setting up dependency injection
- Configuring development environments
- Deploying to production
Critical Rules
- Thin controllers - Delegate business logic to services
- Interfaces in app/Contracts/ - Never alongside implementations
- DI over facades - Constructor injection for testability
- Files < 100 lines - Split larger files per SOLID
- Environment separation - .env never committed
Architecture
app/
├── Actions/ # Single-purpose action classes
├── Contracts/ # Interfaces (DI)
├── DTOs/ # Data transfer objects
├── Enums/ # PHP 8.1+ enums
├── Events/ # Domain events
├── Http/
│ ├── Controllers/ # Thin controllers
│ ├── Middleware/ # Request filters
│ ├── Requests/ # Form validation
│ └── Resources/ # API transformations
├── Jobs/ # Queued jobs
├── Listeners/ # Event handlers
├── Models/ # Eloquent models only
├── Policies/ # Authorization
├── Providers/ # Service registration
├── Repositories/ # Data access layer
└── Services/ # Business logic
Reference Guide
Core Architecture
| Reference |
When to Use |
| container.md |
Dependency injection, binding, resolution |
| providers.md |
Service registration, bootstrapping |
| facades.md |
Static proxies, real-time facades |
| contracts.md |
Interfaces, loose coupling |
| structure.md |
Directory organization |
| lifecycle.md |
Request handling flow |
Configuration & Setup
| Reference |
When to Use |
| configuration.md |
Environment, config files |
| installation.md |
New project setup |
| upgrade.md |
Version upgrades, breaking changes |
| releases.md |
Release notes, versioning |
Development Environments
| Reference |
When to Use |
| sail.md |
Docker development |
| valet.md |
macOS native development |
| homestead.md |
Vagrant (legacy) |
| octane.md |
High-performance servers |
Utilities & Tools
| Reference |
When to Use |
| artisan.md |
CLI commands, custom commands |
| helpers.md |
Global helper functions |
| filesystem.md |
File storage, S3, local |
| processes.md |
Shell command execution |
| context.md |
Request-scoped data sharing |
Advanced Features
| Reference |
When to Use |
| pennant.md |
Feature flags |
| mcp.md |
Model Context Protocol |
| concurrency.md |
Parallel execution |
Operations
| Reference |
When to Use |
| deployment.md |
Production deployment |
| envoy.md |
SSH task automation |
| logging.md |
Log channels, formatting |
| errors.md |
Exception handling |
| packages.md |
Creating packages |
Templates
| Template |
Purpose |
| UserService.php.md |
Service + repository pattern |
| AppServiceProvider.php.md |
DI bindings, bootstrapping |
| ArtisanCommand.php.md |
CLI commands, signatures, I/O |
| McpServer.php.md |
MCP servers, tools, resources, prompts |
| PennantFeature.php.md |
Feature flags, A/B testing |
| Envoy.blade.php.md |
SSH deployment automation |
| sail-config.md |
Docker Sail configuration |
| octane-config.md |
FrankenPHP, Swoole, RoadRunner |
Feature Matrix
| Feature |
Reference |
Priority |
| Service Container |
container.md |
High |
| Service Providers |
providers.md |
High |
| Directory Structure |
structure.md |
High |
| Configuration |
configuration.md |
High |
| Installation |
installation.md |
High |
| Octane (Performance) |
octane.md |
High |
| Sail (Docker) |
sail.md |
High |
| Artisan CLI |
artisan.md |
Medium |
| Deployment |
deployment.md |
Medium |
| Envoy (SSH) |
envoy.md |
Medium |
| Facades |
facades.md |
Medium |
| Contracts |
contracts.md |
Medium |
| Valet (macOS) |
valet.md |
Medium |
| Upgrade Guide |
upgrade.md |
Medium |
| Logging |
logging.md |
Medium |
| Errors |
errors.md |
Medium |
| Lifecycle |
lifecycle.md |
Medium |
| Filesystem |
filesystem.md |
Medium |
| Helpers |
helpers.md |
Low |
| Pennant (Flags) |
pennant.md |
Low |
| Context |
context.md |
Low |
| Processes |
processes.md |
Low |
| Concurrency |
concurrency.md |
Low |
| MCP |
mcp.md |
Low |
| Packages |
packages.md |
Low |
| Releases |
releases.md |
Low |
| Homestead |
homestead.md |
Low |
Quick Reference
Service Injection
public function __construct(
private readonly UserServiceInterface $userService,
) {}
Service Provider Binding
public function register(): void
{
$this->app->bind(UserServiceInterface::class, UserService::class);
$this->app->singleton(CacheService::class);
}
Artisan Command
php artisan make:provider CustomServiceProvider
php artisan make:command ProcessOrders
Environment Access
$debug = env('APP_DEBUG', false);
$config = config('app.name');
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: laravel-architecture3description: Design Laravel app architecture with services, repositories, actions, and clean code patterns. Use when structuring projects, creating services, implementing DI, or organizing code layers. Use when this capability is needed.4---56# Laravel Architecture Patterns78## Agent Workflow (MANDATORY)910Before ANY implementation, use `TeamCreate` to spawn 3 agents:11121. **fuse-ai-pilot:explore-codebase** - Analyze existing architecture132. **fuse-ai-pilot:research-expert** - Verify Laravel patterns via Context7143. **mcp__context7__query-docs** - Check service container and DI patterns1516After implementation, run **fuse-ai-pilot:sniper** for validation.1718---1920## Overview2122Laravel architecture focuses on clean separation of concerns, dependency injection, and maintainable code organization. This skill covers everything from project structure to production deployment.2324### When to Use2526- Structuring new Laravel projects27- Implementing services, repositories, actions28- Setting up dependency injection29- Configuring development environments30- Deploying to production3132---3334## Critical Rules35361. **Thin controllers** - Delegate business logic to services372. **Interfaces in app/Contracts/** - Never alongside implementations383. **DI over facades** - Constructor injection for testability394. **Files < 100 lines** - Split larger files per SOLID405. **Environment separation** - .env never committed4142---4344## Architecture4546```text47app/48├── Actions/ # Single-purpose action classes49├── Contracts/ # Interfaces (DI)50├── DTOs/ # Data transfer objects51├── Enums/ # PHP 8.1+ enums52├── Events/ # Domain events53├── Http/54│ ├── Controllers/ # Thin controllers55│ ├── Middleware/ # Request filters56│ ├── Requests/ # Form validation57│ └── Resources/ # API transformations58├── Jobs/ # Queued jobs59├── Listeners/ # Event handlers60├── Models/ # Eloquent models only61├── Policies/ # Authorization62├── Providers/ # Service registration63├── Repositories/ # Data access layer64└── Services/ # Business logic65```6667---6869## Reference Guide7071### Core Architecture7273| Reference | When to Use |74|-----------|-------------|75| [container.md](references/container.md) | Dependency injection, binding, resolution |76| [providers.md](references/providers.md) | Service registration, bootstrapping |77| [facades.md](references/facades.md) | Static proxies, real-time facades |78| [contracts.md](references/contracts.md) | Interfaces, loose coupling |79| [structure.md](references/structure.md) | Directory organization |80| [lifecycle.md](references/lifecycle.md) | Request handling flow |8182### Configuration & Setup8384| Reference | When to Use |85|-----------|-------------|86| [configuration.md](references/configuration.md) | Environment, config files |87| [installation.md](references/installation.md) | New project setup |88| [upgrade.md](references/upgrade.md) | Version upgrades, breaking changes |89| [releases.md](references/releases.md) | Release notes, versioning |9091### Development Environments9293| Reference | When to Use |94|-----------|-------------|95| [sail.md](references/sail.md) | Docker development |96| [valet.md](references/valet.md) | macOS native development |97| [homestead.md](references/homestead.md) | Vagrant (legacy) |98| [octane.md](references/octane.md) | High-performance servers |99100### Utilities & Tools101102| Reference | When to Use |103|-----------|-------------|104| [artisan.md](references/artisan.md) | CLI commands, custom commands |105| [helpers.md](references/helpers.md) | Global helper functions |106| [filesystem.md](references/filesystem.md) | File storage, S3, local |107| [processes.md](references/processes.md) | Shell command execution |108| [context.md](references/context.md) | Request-scoped data sharing |109110### Advanced Features111112| Reference | When to Use |113|-----------|-------------|114| [pennant.md](references/pennant.md) | Feature flags |115| [mcp.md](references/mcp.md) | Model Context Protocol |116| [concurrency.md](references/concurrency.md) | Parallel execution |117118### Operations119120| Reference | When to Use |121|-----------|-------------|122| [deployment.md](references/deployment.md) | Production deployment |123| [envoy.md](references/envoy.md) | SSH task automation |124| [logging.md](references/logging.md) | Log channels, formatting |125| [errors.md](references/errors.md) | Exception handling |126| [packages.md](references/packages.md) | Creating packages |127128---129130## Templates131132| Template | Purpose |133|----------|---------|134| [UserService.php.md](references/templates/UserService.php.md) | Service + repository pattern |135| [AppServiceProvider.php.md](references/templates/AppServiceProvider.php.md) | DI bindings, bootstrapping |136| [ArtisanCommand.php.md](references/templates/ArtisanCommand.php.md) | CLI commands, signatures, I/O |137| [McpServer.php.md](references/templates/McpServer.php.md) | MCP servers, tools, resources, prompts |138| [PennantFeature.php.md](references/templates/PennantFeature.php.md) | Feature flags, A/B testing |139| [Envoy.blade.php.md](references/templates/Envoy.blade.php.md) | SSH deployment automation |140| [sail-config.md](references/templates/sail-config.md) | Docker Sail configuration |141| [octane-config.md](references/templates/octane-config.md) | FrankenPHP, Swoole, RoadRunner |142143---144145## Feature Matrix146147| Feature | Reference | Priority |148|---------|-----------|----------|149| Service Container | container.md | High |150| Service Providers | providers.md | High |151| Directory Structure | structure.md | High |152| Configuration | configuration.md | High |153| Installation | installation.md | High |154| Octane (Performance) | octane.md | High |155| Sail (Docker) | sail.md | High |156| Artisan CLI | artisan.md | Medium |157| Deployment | deployment.md | Medium |158| Envoy (SSH) | envoy.md | Medium |159| Facades | facades.md | Medium |160| Contracts | contracts.md | Medium |161| Valet (macOS) | valet.md | Medium |162| Upgrade Guide | upgrade.md | Medium |163| Logging | logging.md | Medium |164| Errors | errors.md | Medium |165| Lifecycle | lifecycle.md | Medium |166| Filesystem | filesystem.md | Medium |167| Helpers | helpers.md | Low |168| Pennant (Flags) | pennant.md | Low |169| Context | context.md | Low |170| Processes | processes.md | Low |171| Concurrency | concurrency.md | Low |172| MCP | mcp.md | Low |173| Packages | packages.md | Low |174| Releases | releases.md | Low |175| Homestead | homestead.md | Low |176177---178179## Quick Reference180181### Service Injection182183```php184public function __construct(185 private readonly UserServiceInterface $userService,186) {}187```188189### Service Provider Binding190191```php192public function register(): void193{194 $this->app->bind(UserServiceInterface::class, UserService::class);195 $this->app->singleton(CacheService::class);196}197```198199### Artisan Command200201```shell202php artisan make:provider CustomServiceProvider203php artisan make:command ProcessOrders204```205206### Environment Access207208```php209$debug = env('APP_DEBUG', false);210$config = config('app.name');211```212213---214> Converted and distributed by [TomeVault](https://tomevault.io/claim/fusengine) — claim your Tome and manage your conversions.215<!-- tomevault:4.0:skill_md:2026-04-13 -->