New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jafar-albadarneh/laravel-ddd

Scaffold your Laravel services and actions in a Domain-Driven-Design architecture
3,871 8
Install
composer require jafar-albadarneh/laravel-ddd
Latest Version:0.4.0
PHP:^8.0|7.4
Laravel:10 – 13
Older releases:9
License:MIT
Last Updated:Mar 20, 2023
Links: GitHub  ·  Packagist
Maintainer: jafar.albadarneh

Domain-Driven in Actions

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

In a Domain-Driven environment, you would want to keep your code as clean and organized as possible. This package allows to create a domain-driven architecture in your Laravel app. The package assumes the following code structure:

- app
    - Domains
        - [DomainA]
            - Actions
            - Events
            - Http
            - Listeners
            - Models
            - Services

By design, each domain should be treated in isolation, where all of the actions and services are scoped to the domain.

In regard to inter-domain communication, you can create a proxy service at the domain level to bridge the communication gap between the domains. Internally you're free to either:

  • Inject and class services directly
  • Follow an internal pub/sub mechanism, where you publish events from (Domain X) and listen to them in other domains [Domain Y, Domain Z ..etc).

Installation

You can install the package via composer:

composer require jafar-albadarneh/laravel-ddd

Usage

The package is equipped with a command line tool that allows you to create a domain-driven architecture in your Laravel app. These command line tools include:

Generating the Domain

After you identify the domain, you can generate it by running the following command:

php artisan make:domain [domain-name]

The command accepts the following options:

  • [domain-name]: The name of the domain you want to create.
  • --with-samples=1: If you want to generate the domain with sample actions and services.

Generating Domain Services

After creating the domain, you can generate the services by running the following command:

php artisan make:service domain=[domain-name]

The command accepts the following options:

  • domain=[domain-name]: The name of the domain you want to generate the services for.
  • --name=[service-name]: If you want to generate a service with a custom name.

Generating Domain Actions

After creating the domain, you can generate the actions by running the following command:

php artisan make:action domain=[domain-name] --name=[action-name]

The command accepts the following options:

  • domain=[domain-name]: The name of the domain you want to generate the actions for.
  • --name=[action-name]: The name of action class within the domain.

Generating Domain DTOs

After creating the domain, settle with your services, you can generate DTOs by running the following command:

php artisan make:dto domain=[domain-name] --name=[dto-name]

The command accepts the following options:

  • domain=[domain-name]: The name of the domain you want to generate the DTO for.
  • --name=[dto-name]: The name of DTO class within the domain.

Generating Domain DTOs

After creating the domain, you can generate DTOs to support data streams among your services and actions by running the following command:

php artisan make:dto domain=[domain-name] --name=[dto-name]

The command accepts the following options:

  • domain=[domain-name]: The name of the domain you want to generate the actions for.
  • --name=[action-name]: The name of DTO class within the domain.

Generating Native Laravel Resources

You won't be getting the full potential of the package if you can't associate native laravel resources (Controllers, Requests, Resources, Middlewares) with your domain. There are two ways to achieve this:

1- Laravel artisan commands already support passing a namespace to any command. So instead of placing all the resources within the App\Http namespace, you can prefix your resource with the FULL domain namespace. For example, if you want to create a controller for the Authentication domain, you can run the following command:

php artisan make:controller \\App\\Domains\\Authentication\\Http\\Controllers\\LoginController

2- [TODO] The package overrides Laravel artisan commands to support passing a domain name to the command. So instead of passing the full namespace of the domain, you can pass a --domain=[domain-name] parameter to your command.

Note: This feature is not yet implemented.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

samrat415/laravel-ddd

Laravel DDD Toolkit - A lightweight Laravel package to scaffold and manage Domai...

557 6
foxws/laravel-ddd

Domain Driven Design scaffolding for Laravel projects

2,969 1
tey/laravel-ddd

A Laravel toolkit for Domain Driven Design patterns

43,971 196
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982

Version History

Version Released PHP Laravel License
0.4.0 ^8.0|7.4 MIT
0.3.0 ^8.0|7.4 MIT
0.2.0 ^8.0|7.4 ^9.0 MIT
0.1.0 ^8.0|7.4 ^9.0 MIT