This is an opinionated modified version of the Laravel framework which aims at providing a Domain-Driven Design (DDD) structure.
Laravel is a popular PHP web framework that provides an easy and efficient way to build web applications. However, the default structure of Laravel, coupled with Eloquent's active record pattern, may not always fit the needs of a project that requires a Domain-Driven Design (DDD) architecture. Eloquent's active record pattern breaks DDD principles and make it difficult to separate your business logic from your infrastructure code.
This repository provides a modified file structure for Laravel that follows DDD principles and tries to adhere to best practices, such as those outlined in Spatie's Laravel Beyond CRUD. The goal is to provide a starting point for building Laravel applications using a DDD approach, while still leveraging the power and convenience of the Laravel framework.
๐ If you find this repository useful, consider giving it a โญ๏ธ. Thank you!
This starter template includes several added, changed, and removed features:
- Added:
- Strict types declaration in all PHP files
- Style checker package for custom rule-sets to php-cs-fixer โ wayofdev/php-cs-fixer-config
- Static analysis tool โ PHPStan and it's extensions:
- phpstan/extension-installer โ automatic installation of PHPStan extensions
- phpstan/phpstan-deprecation-rules โ rules for detecting usage of deprecated classes, methods, properties, constants and traits.
- nunomaduro/larastan โ PHPStan integration with Laravel
- Pest testing framework
- Github action workflows for:
- Continuous integration which includes coding standards checks, unit testing and static analysis
- Automatic pull-request labeling
- Deployer for automatic deployments to staging and production servers with support of Github Environments
- ergebnis/composer-normalize composer plugin for normalizing composer.json file
- roave/securityadvisories package to ensure that application doesn't have installed dependencies with known security vulnerabilities.
- Application dockerization using docker-compose and Makefile โ use
make help
to view available commands - Git pre-commit hooks using pre-commit package
- Changed:
- Marked default Laravel classes as
final
- Modified file structure to meet DDD principles
- Changed config folder files to use default PHP multi-line comment style
- Marked default Laravel classes as
- Removed:
- Dependencies like Laravel Sanctum, Laravel Pint, and Laravel Sail.
- Broadcasting service provider and it's routes. It can be added back, if it will be required for project
- Console routes in favor of Command classes.
- Sanctum migration files
To use this repository, you need to meet the following requirements:
- macOS Monterey+ or Linux
- Docker 20.10 or newer
- Installed dnsmasq service, running in the system. You can use ansible-role-dnsmasq to install and configure this service.
- Cloned, configured and running docker-shared-services to support system-wide DNS, routing, and TLS support via Traefik.
Warning: You should configure, set up, and run the docker-shared-services repository to ensure system-wide TLS and DNS support.
-
Clone repository:
After forking or creating generating repository from template, you can clone it to your local machine. In this example we will use
laravel-starter-tpl
repository as starting point.$ git clone [email protected]:wayofdev/laravel-starter-tpl.git
-
Generate
.env
fileGenerate .env file from .env.example file using Makefile command:
$ make env \ APP_NAME=laravel \ SHARED_SERVICES_NAMESPACE=ss \ PROJECT_SERVICES_NAMESPACE=wod \ COMPOSE_PROJECT_NAME=laravel-starter-tpl
Change generated
.env
file to match your needs, if needed.(Optional): to re-generate
.env
file, addFORCE=true
to the end of command:$ make env \ APP_NAME=laravel \ SHARED_SERVICES_NAMESPACE=ss \ PROJECT_SERVICES_NAMESPACE=wod \ COMPOSE_PROJECT_NAME=laravel-starter-tpl \ FORCE=true
-
Build, install and run. This will also generate Laravel app key:
$ make # or run commands separately $ make hooks $ make install $ make key $ make prepare $ make up
Useful resources about Laravel and DDD approach:
This repository was created in 2022 by lotyp / wayofdev.
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
- ๐ค Suggest a feature
- ๐ Report an issue
- ๐ Improve documentation
- ๐จโ๐ป Contribute to the code