Laravel - DDD

Using Domain-Driven Design in Laravel framework

DDD

Domain-Driven Design
An approach to software development for complex needs 
by connecting the implementation to an evolving model.

- https://en.wikipedia.org/wiki/Domain-driven_design

Expressing a meaningful object-oriented model that says what it does.

- https://medium.com/the-coding-matrix/ddd-101-the-5-minute-tour-7a3037cf53b8

Concepts

  • Context
  • Domain
  • Model
  • Ubiquitous Language

The Ubiquitous Language

- https://medium.com/the-coding-matrix/ddd-101-the-5-minute-tour-7a3037cf53b8

Strategic

  • Bounded context
  • Continuous integration
  • Context map

- https://martinfowler.com/bliki/BoundedContext.html

Bounded Context

- https://en.wikipedia.org/wiki/Domain-driven_design

- https://en.wikipedia.org/wiki/Domain-driven_design

Patterns

  • You model your business using Entities (the ID matters) and Value Objects (the values matter).
  • ​You use Repositories to retrieve and store them.
  • You create them with the help of Factories.
  • If an object is too complex for a single class, you’ll create Aggregates that will bind Entities & Value Objects under the same root.
  • If a business logic doesn’t belong to a given object, you’ll define Services that will manipulate the involved elements.
  • Eventually, when the state of the business changes (a change that matters to business experts), you’ll publish Domain Events to communicate the change.

- https://medium.com/the-coding-matrix/ddd-101-the-5-minute-tour-7a3037cf53b8

Disadvantages

A system based on domain-driven design can come at a relatively high cost.
Microsoft recommends that it be applied only to complex domains.

- https://en.wikipedia.org/wiki/Domain-driven_design

References

Laravel

Using Domain-Driven Design in Laravel
in a way that leverages a maximum of the framework features

- http://lorisleiva.com/conciliating-laravel-and-ddd

Architecture

  • Green is for the domain.
  • Blue is for any technical implementation of domain interfaces.
  • Grey is for everything we are familiar with in Laravel.
  • Hexagons are interfaces.
  • Dashed arrows make up the logical workflow of incoming requests

- http://lorisleiva.com/conciliating-laravel-and-ddd

A possible folder structure

/app
    |___ ...
    |___ /DomainA
    |___ /DomainC
        |___ /CloseIO
        |___ /Repositories (implementation)
        |___ /Stripe
        |___ AggregateA1Resource.php (if using API interface)
        |___ DomainCServiceProvider.php
        |___ ...

/src
    |___ ...
    |___ /DomainA
    |___ /DomainB
        |___ /Factories
        |___ /Repositories (interfaces)
        |___ AggregateA1.php
        |___ EntityA2.php
        |___ EntityB.php
        |___ CRMInterface.php
        |___ PaymentInterface.php
        |___ ValueObjectA3.php
        |___ ValueObjectA.php
        |___ ...

References

Thank you

https://tenor.com/es/ver/thank-you-thankyou-thanks-dance-gif-9394190

Laravel and DDD

By theanh nguyen

Laravel and DDD

Discuss on defining common ground for using Domain-Driven Design in Laravel framework.

  • 558