October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Framework-Agnostic Hexagonal Architecture in Laravel

Use Laravel’s container and service providers to wire purposeful application ports to infrastructure adapters—without adding interfaces to every class.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can use Hexagonal Architecture in Laravel without making every class an interface or pretending the whole application is framework-independent. Keep business rules and use cases independent where that boundary matters, express the capabilities they need as application-owned ports, and use Laravel’s container and service providers to connect those ports to Laravel-specific adapters. The core and its ports can be framework-agnostic; the adapters and the wiring remain Laravel-specific.

What Hexagonal Architecture means in a Laravel application

Hexagonal Architecture, also called Ports and Adapters, separates an application’s inside from the technologies around it. A port describes a purposeful interaction with the application; an adapter translates technology-specific communication into or out of that interaction. Alistair Cockburn’s 2005 paper describes the pattern as a way to let users, programs, automated tests, and batch scripts drive an application while it is developed and tested independently of its eventual runtime devices and databases (Cockburn’s original article, 2005-09-04).

As an Amazon Associate I earn from qualifying purchases.

The hexagon is a diagrammatic metaphor, not a requirement to create six ports, six layers, or a particular directory tree. The useful question is which interactions cross the application boundary and whether translating or substituting them protects a real responsibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Ports belong to the application’s needs

A port can represent an inbound use-case operation or an outbound capability the application requires. For example, an order-processing use case might need to store an order. An application-owned OrderStore port describes that need without naming Eloquent, a database vendor, or Laravel.

Adapters translate technology at the boundary

An HTTP controller can translate request data into an application-level command. An Eloquent-backed repository can implement the order-storage port. A different adapter, such as an in-memory fake in a test, can satisfy the same port. The port describes the interaction; each adapter handles its own technology.

How to use Hexagonal Architecture in Laravel

A practical mapping separates framework entry points, application behavior, and infrastructure without insisting that every project use identical folders:

Part Laravel examples Responsibility
Inbound adapters HTTP controllers, console commands, queue handlers, scheduled entry points Translate framework input into an application-level request and invoke a use case.
Application core Use cases and domain behavior Coordinate the work and enforce business rules without relying on Laravel-specific types when framework independence is a goal.
Outbound ports Application-owned interfaces such as OrderStore State a capability the core needs in terms of the application’s purpose.
Outbound adapters Eloquent repositories, mail, queue, filesystem, external API implementations Implement a port using a specific technology.
Composition root Laravel service providers Connect ports to the adapters selected for the running application.

Laravel can inject dependencies into controllers, event listeners, middleware, queued jobs, and route closures. That makes framework-managed entry points suitable inbound adapters; it does not require the use case itself to accept a Laravel request or depend on a facade (Laravel 13.x Service Container; Laravel 13.x Contracts).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a meaningful boundary, keep Laravel request objects, Eloquent models, facades, and vendor-specific types out of core method signatures. That is a design choice for isolation, not a Laravel requirement. If a project does not need the core to remain independent of Laravel, a lighter arrangement may be more appropriate.

Where to bind an interface to an implementation

In Laravel, a service provider is the normal composition point for application bindings. In Laravel 13.x, user-defined providers are registered in bootstrap/providers.php. Put container bindings in the provider’s register method; Laravel advises that this method should be used for binding services (Laravel 13.x Service Providers).

<?php

namespace AppProviders;

use AppApplicationOrdersOrderStore;
use AppInfrastructurePersistenceEloquentOrderStore;
use IlluminateSupportServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->bind(OrderStore::class, EloquentOrderStore::class);
    }
}

With that binding, a use case that type-hints OrderStore can receive the Eloquent adapter through the container. A test can instead provide a fake or mock implementation to the use case. This is an illustrative wiring pattern, not a claim that any particular code has been executed.

Check the Laravel major version installed in your project before copying provider paths or APIs: the cited provider-registration path and documentation here are for Laravel 13.x.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Should you use Laravel contracts, facades, or concrete injection?

These choices solve different problems. Laravel explicitly supports both contracts and facades, says either can support robust, well-tested applications, and notes that choosing between them is often a matter of team preference. It also says the approaches are not mutually exclusive (Laravel 13.x Contracts).

Choice Good fit Boundary and trade-off
Application-owned port The core needs a capability that may have another adapter, benefits from a test seam, or should remain independent of Laravel. The application owns the abstraction. It adds value when it clarifies a boundary; a one-to-one interface that brings no meaningful isolation or substitution can add needless indirection.
Laravel contract Code intentionally depends on a Laravel service, or a package needs to integrate with framework services without requiring a concrete implementation. It is a framework contract, so using it in the core does not by itself make that core framework-agnostic.
Facade Framework-facing code values Laravel’s concise, supported facade API. Facade use is not inherently incompatible with sound design. For strict framework independence, keep it in Laravel-facing adapters rather than core business rules.
Direct concrete injection A concrete service is an implementation detail and no meaningful boundary or alternate implementation is needed. Laravel can resolve many concrete dependencies automatically, avoiding an interface and explicit binding where neither adds value.

A useful decision test is to ask who owns the abstraction, whether the core must be framework-independent, whether substituting an implementation is useful, and whether the extra contract makes responsibility clearer. Use the least elaborate option that preserves the boundary the team actually needs.

When explicit or contextual bindings are useful

Laravel’s container can automatically resolve classes that have no dependencies or only concrete-class dependencies. You do not need an interface or an explicit binding solely to enable dependency injection for every service (Laravel 13.x Service Container).

Use an explicit interface-to-implementation binding when the dependency is an application-owned port or when the container cannot infer which implementation is intended. Laravel also supports contextual bindings when different consumers need different implementations of the same interface. That is useful for a genuine consumer-specific difference; if two capabilities have distinct meanings, naming separate ports may communicate the design more clearly than relying on contextual wiring alone.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.