How bdelespierre/laravel-clean-architecture-demo works
Project Type and Purpose
• This is a full-stack Laravel application structured according to Clean/Hexagonal Architecture (also known as Ports & Adapters).
• Its primary feature (demonstrated in the codebase) is a “Create User” use case, exposed over HTTP (JSON/HTML) and CLI.
High-Level View of the File Structure
• app/Domain holds pure business logic: Entities, Interfaces (ports), and Use Case Interactors.
• app/Adapters implements output ports (Presenters) and ViewModels for different delivery mechanisms (CLI, HTTP, JSON).
• app/Http and app/Console are framework-specific adapters (controllers and Artisan commands).
• app/Repositories is the infrastructure adapter implementing the UserRepository interface against a relational database.
• resources/views, resources/js/css represent the frontend.
• config/, bootstrap/, public/, routes/ are standard Laravel framework layers and entry points.
Main Components and Their Interactions
a. Clients / Entry Points
• Web Browser → HTTP(S)
• CLI → Artisan commands
b. Framework Adapters
• Public/index.php → HTTP Kernel → Middleware → Controllers (app/Http/Controllers)
• artisan → Console Kernel → Commands (app/Console/Commands)
c. Use Case Layer (app/Domain/UseCases/CreateUser)
• CreateUserRequestModel → CreateUserInteractor → CreateUserResponseModel
• Interactor depends on two ports: UserRepository (to persist data) and CreateUserOutputPort (to present results).
d. Infrastructure Adapters
• UserDatabaseRepository implements UserRepository, communicates with the database via Eloquent (app/Models/User).
e. Output Adapters (Presenters & ViewModels)
• CreateUserHttpPresenter → HttpResponseViewModel → JSON or Blade view
• CreateUserJsonPresenter → JsonResourceViewModel → JSON API
• CreateUserCliPresenter → CliViewModel → Console output
f. Persistence
• MySQL (or configured DB) with migrations in database/migrations
g. Frontend
• Blade templates (resources/views/user/create.blade.php, show.blade.php)
• JS/CSS assets built via webpack.mix.js
Architectural Patterns & Principles
• Dependency Inversion: Domain depends on interfaces only; concrete implementations live in Adapters.
• Single Responsibility: Controllers orchestrate request mapping; Interactors handle business rules; Presenters format output.
• Ports & Adapters (Hexagonal): Clear separation between core business logic and framework/infrastructure.