mcpField
L
laravel-architecture

laravel-architecture

github.com/fusengineDevelopment34142 installsUpdated 2w ago
Repository

About laravel-architecture

laravel-architecture is a reference skill for Laravel developers covering project organization, dependency injection, configuration, development environments, and production deployment. It combines guides with code templates, including one for MCP servers, tools, resources, and prompts.

Key features

  1. 01Project structure and layering guidance
  2. 02Service container and dependency injection reference
  3. 03Configuration and development environment guides
  4. 04Artisan, filesystem, and concurrency references
  5. 05Deployment, logging, and error handling guides
  6. 06MCP server template

Use cases

  1. 01Plan a new Laravel project structure
  2. 02Implement services, repositories, and dependency injection
  3. 03Configure development environments and deployment
  4. 04Create an MCP server in a Laravel project

MCP support

The material includes an MCP reference and a template for creating MCP servers, tools, resources, and prompts.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fusengine/agents --skill laravel-architecture

After installing, type/laravel-architecturein Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
artisan.md
concurrency.md
configuration.md
container.md
context.md
contracts.md
deployment.md
envoy.md
errors.md
facades.md
filesystem.md
helpers.md
homestead.md
installation.md
lifecycle.md
logging.md
mcp.md
octane.md
packages.md
pennant.md
processes.md
providers.md
releases.md
sail.md
structure.md
references/templates/
AppServiceProvider.php.md
ArtisanCommand.php.md
Envoy.blade.php.md
McpServer.php.md
octane-config.md

Details

From the project README
Covers Laravel application architecture end to end: project structure (Actions, Contracts, DTOs, Services, Repositories layout), the service container and dependency injection, service providers and facades, environment/configuration, development environments (Sail, Valet, Homestead, Octane), Artisan CLI, filesystem/processes/context, feature flags (Pennant), MCP servers, concurrency, and production deployment (including Envoy, logging, error handling, and package authoring).

Laravel Architecture Patterns

Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:

  1. fuse-ai-pilot:explore-codebase - Analyze existing architecture
  2. fuse-ai-pilot:research-expert - Verify Laravel patterns via Context7
  3. 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

  1. Thin controllers - Delegate business logic to services
  2. Interfaces in app/Contracts/ - Never alongside implementations
  3. DI over facades - Constructor injection for testability
  4. Files within FUSE_SOLID_MAX_LINES - Split larger files per SOLID
  5. 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
ReferenceWhen to Use
container.mdDependency injection, binding, resolution
providers.mdService registration, bootstrapping
facades.mdStatic proxies, real-time facades
contracts.mdInterfaces, loose coupling
structure.mdDirectory organization
lifecycle.mdRequest handling flow
Configuration & Setup
ReferenceWhen to Use
configuration.mdEnvironment, config files
installation.mdNew project setup
upgrade.mdVersion upgrades, breaking changes
releases.mdRelease notes, versioning
Development Environments
ReferenceWhen to Use
sail.mdDocker development
valet.mdmacOS native development
homestead.mdVagrant (legacy)
octane.mdHigh-performance servers
Utilities & Tools
ReferenceWhen to Use
artisan.mdCLI commands, custom commands
helpers.mdGlobal helper functions
filesystem.mdFile storage, S3, local
processes.mdShell command execution
context.mdRequest-scoped data sharing
Advanced Features
ReferenceWhen to Use
pennant.mdFeature flags
mcp.mdModel Context Protocol
concurrency.mdParallel execution
Operations
ReferenceWhen to Use
deployment.mdProduction deployment
envoy.mdSSH task automation
logging.mdLog channels, formatting
errors.mdException handling
packages.mdCreating packages

Templates

TemplatePurpose
UserService.php.mdService + repository pattern
AppServiceProvider.php.mdDI bindings, bootstrapping
ArtisanCommand.php.mdCLI commands, signatures, I/O
McpServer.php.mdMCP servers, tools, resources, prompts
PennantFeature.php.mdFeature flags, A/B testing
Envoy.blade.php.mdSSH deployment automation
sail-config.mdDocker Sail configuration
octane-config.mdFrankenPHP, Swoole, RoadRunner

Feature Matrix

FeatureReferencePriority
Service Containercontainer.mdHigh
Service Providersproviders.mdHigh
Directory Structurestructure.mdHigh
Configurationconfiguration.mdHigh
Installationinstallation.mdHigh
Octane (Performance)octane.mdHigh
Sail (Docker)sail.mdHigh
Artisan CLIartisan.mdMedium
Deploymentdeployment.mdMedium
Envoy (SSH)envoy.mdMedium
Facadesfacades.mdMedium
Contractscontracts.mdMedium
Valet (macOS)valet.mdMedium
Upgrade Guideupgrade.mdMedium
Logginglogging.mdMedium
Errorserrors.mdMedium
Lifecyclelifecycle.mdMedium
Filesystemfilesystem.mdMedium
Helpershelpers.mdLow
Pennant (Flags)pennant.mdLow
Contextcontext.mdLow
Processesprocesses.mdLow
Concurrencyconcurrency.mdLow
MCPmcp.mdLow
Packagespackages.mdLow
Releasesreleases.mdLow
Homesteadhomestead.mdLow

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');

Laravel 13 Notes

Updated stack
  • Symfony 7.4 and 8.0 supported side by side (HttpFoundation, Console, Mailer)
  • PHP 8.3 minimum (8.2 dropped)
  • pda/pheanstalk 7.x / 8.x required for the Beanstalk driver (5.x dropped)
  • Current stable version: 13.33 (September 2026)
Cache::touch() API

New method to refresh the TTL without recomputing the value.

Cache::touch('user:123', 3600);
Cache::touch('user:123', now()->addHour());
Queue::route() for dynamic routing

See [[laravel-queues]] for declarative routing per job class (Queue::route(ProcessPodcast::class, connection: 'redis', queue: 'podcasts')) and Queue::forward() (13.26+).

Nested model boot → LogicException

Laravel 13 throws a LogicException when a model is instantiated during its own boot (new static() inside the model's boot() or a trait's boot*()). Move that logic out of the boot cycle.

What's new in 13.x (13.1 → 13.33)
  • php artisan dev (13.16+): runs the server, queue:listen, Pail and Vite in a single terminal; customizable via Illuminate\Foundation\DevCommands::artisan('horizon', 'horizon') in AppServiceProvider::boot(), listed via php artisan dev:list (requires Node 22.13+)
  • #[BindWhen(Impl::class, static fn () => ...)] (13.22+): conditional binding declared on the interface — requires PHP 8.5
  • Enum (UnitEnum) support in most managers (Cache::store(), Queue, Log, Mail, Auth::guard()…) (13.3 → 13.7)
  • Guzzle 8 supported (13.26+)

Migration Laravel 12 → 13

TopicBefore (12)After (13)
PHP minimum8.28.3
PHPUnit1112 (13 supported)
Pest34 (5 with PHP 8.4+)
CSRFVerifyCsrfTokenPreventRequestForgery (origin check via Sec-Fetch-Site)
Cache prefixunderscorehyphens by default (set CACHE_PREFIX, REDIS_PREFIX, SESSION_COOKIE for backward compatibility)
Beanstalkpheanstalk 5.xpheanstalk 7.x / 8.x
Symfony7.x7.4 / 8.0
Model boottoleratednested instantiation during the model's boot → LogicException
Config—new cache.serializable_classes (allowlist hardening, default false)
# Backward-compatible cache prefixes when upgrading from L12
CACHE_PREFIX=laravel_cache_
REDIS_PREFIX=laravel_database_
SESSION_COOKIE=laravel_session
// config/cache.php — deserialization hardening
'serializable_classes' => [
    App\DTO\PaymentDto::class,
    App\DTO\OrderDto::class,
],

Best Practices

DO
  • Use final readonly class for DTOs and Value Objects (PHP 8.3+)
  • Inject via constructor promotion + interface (dependency inversion)
  • Log via Context::add() to propagate metadata across jobs/requests
  • Configure serializable_classes in production
  • Prefer app(Contract::class) over App::make() (strict typing)
DON'T
  • Instantiate a model during its own boot (new static() inside boot() → LogicException in L13)
  • Hardcode absolute paths (use base_path(), storage_path())
  • Mix Repository and Service (one per responsibility)
  • Bypass the container with new ConcreteClass()
  • Ignore the cache prefix change when upgrading from L12

Comments

Markdown supported