This project demonstrates how to implement Clean Architecture principles in a Laravel 12 application.
The goal of this repository is to show a clear separation of concerns, making the application more maintainable, testable, and scalable by decoupling business logic from the framework's HTTP layer.
The application follows a modular structure inspired by Clean Architecture:
app/
├── Http/
│ └── Controllers/ # Entry points (Thin controllers)
├── Models/ # Eloquent Models (Data structure)
├── Repositories/ # Data Access Layer (Repository Pattern)
└── UseCases/ # Business Logic (Application specific use cases)
- Use Cases: Contain the core business logic. They are framework-agnostic where possible and orchestrate the flow of data.
- Repositories: Handle data persistence and retrieval, abstracting the database layer from the business logic.
- Controllers: Responsible only for handling HTTP requests, validating input, calling the appropriate Use Case, and returning a response.
- PHP 8.2+
- Composer
- SQLite (default) or MySQL
-
Clone the repository
git clone https://github.com/rahmatrdn/clean-architecture.git cd example-laravel -
Automated Setup We have a convenient composer script to set up everything for you:
composer run setup
This command will install dependencies, setup the
.envfile, generate the app key, run migrations, and build frontend assets.OR Manual Setup
composer install cp .env.example .env php artisan key:generate php artisan migrate
-
Start the Server
composer run dev
Or manually:
php artisan serve
This project uses Pest PHP for testing.
# Run all tests
php artisan test
# Run specific test
php artisan test --filter=TaskTestAPI documentation and collection are available in the bruno-api-docs directory. You can use Bruno to open and test the API endpoints.
- Framework: Laravel 12
- Architecture: Clean Architecture
- Testing: Pest PHP
- API Docs: Bruno
- Code Style: Laravel Pint
The Laravel framework is open-sourced software licensed under the MIT license.