Architecture Patterns

Software architecture patterns and design principles for Laravel applications.

Model-View-Controller is an architectural pattern that separates an application into three interconnected components: Models (data and business logic), Views (presentation/UI), and Controllers (handle HTTP requests and coordinate between models and views).

Repository Pattern abstracts data access behind an interface. A Repository class handles all database queries, and the rest of the application depends on the interface, not the concrete implementation.

Service classes encapsulate business logic that spans multiple models or involves external services. They sit between controllers and models, handling the orchestration of operations.

Action classes (or single-action controllers) encapsulate one specific operation into its own class. Each action handles one business operation from start to finish.

DTOs are simple objects that carry data between layers. They define a clear contract for what data is expected and provide type safety for transferred data.

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets you select an algorithm at runtime.

The Observer Pattern defines a one-to-many dependency between objects. When one object (subject) changes state, all its dependents (observers) are notified and updated automatically.

The Singleton Pattern ensures a class has only one instance and provides a global point of access to it. In Laravel, the service container manages singletons.

The Factory Pattern provides an interface for creating objects without specifying their exact class. The creation logic is centralized in a factory method or class.

API Resources transform Eloquent models into JSON responses with a consistent format. They act as a presentation layer for your API, decoupling the database schema from the response structure.

Form Requests are custom request classes that encapsulate validation and authorization logic. They keep validation rules out of controllers and provide reusable, testable validation.

Middleware provides a mechanism to filter and process HTTP requests and responses. Each middleware performs a specific task and passes the request to the next middleware in the chain.

Events represent something that happened in the application. Listeners react to events and perform side effects. This decouples the triggering code from its consequences.

Policies organize authorization logic around a specific model. Gates define authorization checks for actions not tied to a model. Together they provide a structured authorization system.

Service Providers are the central bootstrapping mechanism for Laravel applications. They register services, configurations, and perform initialization when the application starts.