andreyizmaylov / base-domain-structure
Base domain structure for Laravel applications
Package info
github.com/andrewizmaylov/ddd-structure
pkg:composer/andreyizmaylov/base-domain-structure
Requires
- php: ^8.2
Requires (Dev)
- orchestra/testbench: ^10.9
- pestphp/pest: ^4.3
README
A template scaffold that implements Domain-Driven Design principles for Laravel, providing a clean, opinionated structure so you can focus on what matters: your business domain.
🚀 Installation
composer require andreyizmaylov/base-domain-structure
🎯 Publish the configuration: *
php artisan vendor:publish --tag=base-domain-structure-config
🔄 Directory Structure Visualization
Here's a more detailed tree view of your configurable structure:
src/Balance/
├── ApplicationLayer/
│ └── UseCases/
│ └── UpdateBalanceUseCase.php
├── DomainLayer/
│ ├── Entities/
│ ├── Repository/
│ │ ├── AccountRepositoryInterface.php
│ │ └── BalanceTransactionRepositoryInterface.php
│ ├── Services/
│ │ ├── BalanceUpdateService.php
│ │ └── CreateTransactionsService.php
│ ├── Storage/
│ │ ├── AccountStorageInterface.php
│ │ └── BalanceTransactionStorageInterface.php
│ └── ValueObjects/
├── InfrastructureLayer/
│ ├── Repository/
│ │ ├── AccountRepository.php
│ │ └── BalanceTransactionRepository.php
│ └── Storage/
│ ├── AccountStorage.php
│ └── BalanceTransactionStorage.php
└── PresentationLayer/
└── HTTP/V1/
├── Controllers/
│ └── UpdateBalanceController.php
├── Requests/
│ └── UpdateBalanceRequest.php
├── Responders/
│ └── BalanceTransactionResponder.php
└── routes.php
After publishing, you can modify default domain structure:
'structure' => [ 'ApplicationLayer', 'DomainLayer' => [ 'Entities', 'ValueObjects', 'Repository', 'Storage' ], 'InfrastructureLayer' => [ 'Repository', 'Storage', ], 'PresentationLayer' => [ 'HTTP' => [ 'V1' => [ 'Controllers', 'Requests', 'Responders', 'routes.php' ] ] ], ],
📁 Customize Your Source Folder
By default, domains are created in app/src/. You can change this via your .env file:
BASE_DOMAIN_SRC_DIR=Domain
Commands
Create Context structured folder
php artisan make:context Balance
Create UseCase structured folder
php artisan make:use-case UpdateBalance Balance
🙏 Acknowledgements
Mehul Koradiya - For his foundational work on laravel-enterprise-structure, which inspired this package ❤️.
📄 License
The MIT License (MIT). See LICENSE file for details.