Laravel Architecture Patterns
Agent Workflow (MANDATORY)
Before ANY implementation, launch in parallel:
- 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');
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.4---5
6# Laravel Architecture Patterns
7
8## Agent Workflow (MANDATORY)
9
10Before ANY implementation, launch in parallel:
11
121. **fuse-ai-pilot:explore-codebase** - Analyze existing architecture
132. **fuse-ai-pilot:research-expert** - Verify Laravel patterns via Context7
143. **mcp__context7__query-docs** - Check service container and DI patterns
15
16After implementation, run **fuse-ai-pilot:sniper** for validation.
17
18---
19
20## Overview
21
22Laravel architecture focuses on clean separation of concerns, dependency injection, and maintainable code organization. This skill covers everything from project structure to production deployment.
23
24### When to Use
25
26- Structuring new Laravel projects
27- Implementing services, repositories, actions
28- Setting up dependency injection
29- Configuring development environments
30- Deploying to production
31
32---
33
34## Critical Rules
35
361. **Thin controllers** - Delegate business logic to services
372. **Interfaces in app/Contracts/** - Never alongside implementations
383. **DI over facades** - Constructor injection for testability
394. **Files < 100 lines** - Split larger files per SOLID
405. **Environment separation** - .env never committed
41
42---
43
44## Architecture
45
46```text
47app/
48├── Actions/ # Single-purpose action classes
49├── Contracts/ # Interfaces (DI)
50├── DTOs/ # Data transfer objects
51├── Enums/ # PHP 8.1+ enums
52├── Events/ # Domain events
53├── Http/
54│ ├── Controllers/ # Thin controllers
55│ ├── Middleware/ # Request filters
56│ ├── Requests/ # Form validation
57│ └── Resources/ # API transformations
58├── Jobs/ # Queued jobs
59├── Listeners/ # Event handlers
60├── Models/ # Eloquent models only
61├── Policies/ # Authorization
62├── Providers/ # Service registration
63├── Repositories/ # Data access layer
64└── Services/ # Business logic
65```
66
67---
68
69## Reference Guide
70
71### Core Architecture
72
73| 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 |
81
82### Configuration & Setup
83
84| 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 |
90
91### Development Environments
92
93| 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 |
99
100### Utilities & Tools
101
102| 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 |
109
110### Advanced Features
111
112| 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 |
117
118### Operations
119
120| 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 |
127
128---
129
130## Templates
131
132| 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 |
142
143---
144
145## Feature Matrix
146
147| 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 |
176
177---
178
179## Quick Reference
180
181### Service Injection
182
183```php
184public function __construct(
185 private readonly UserServiceInterface $userService,
186) {}
187```
188
189### Service Provider Binding
190
191```php
192public function register(): void
193{
194 $this->app->bind(UserServiceInterface::class, UserService::class);
195 $this->app->singleton(CacheService::class);
196}
197```
198
199### Artisan Command
200
201```shell
202php artisan make:provider CustomServiceProvider
203php artisan make:command ProcessOrders
204```
205
206### Environment Access
207
208```php
209$debug = env('APP_DEBUG', false);
210$config = config('app.name');
211```