DDD usually means at least 3 layers: Application Services, Domain Service and Infrastructure.

Some ideas to use them (depends on what it makes sens for your project)

  • Create these three folders for each Module. Let’s say you have a module Calendar and one called Leads. Each module will have same structure.
  • Do not use Controllers as Application Service. Application is the your main entry point in the app. You can enter either from a Controller, a Job, or a Command.
  • Controllers’ main responsibility is to parse http request and pass the right data back in a http format (json,html, binary)
  • Controllers are tight to the Laravel Framework. Your app should not be so coupled
  • In DDD validations happens in all layers so you should have a Validation folder for each layer. I mean validations Rule. Validation infrastructure should be in infrastructure or in your vendor (like Illuminate Validator).
  • Same with events. You might have Domain Events like: “EventCreated”, “EventCanceled” or infrastucture events like : “JobFailed”, etc.
  • Migrations are part of “Laravel’s infrastructure”. Do not put it in your in your “App code”.
  • Looking at the infrastructure, there are two folder gain in size during the project: Presenters and Transformers. That’s why i like to extract them a in folder called “UI” (it’s also an infrastructure layer).

App code might look like this

Calendar/
├── Application/
│ ├── Validation/
│ ├── CreateEvent.php
├── Domain/
│ ├── Validation/
│ ├── Event.php
└── Infrastructure/
│ ├── Listeners/
│ ├── Jobs/
│ ├── Repositories/
└── UI/
│ ├── Presenters/
│ ├── Transformers/
│ ├── ViewComposers/
Lead/
├── Application/
│ ├── Validation/
│ ├── CreateLead.php
├── Domain/
│ ├── Validation/
│ ├── Lead.php
└── Infrastructure/
│ ├── Listeners/
│ ├── Jobs/
│ ├── Repositories/
└── UI/
│ ├── Presenters/
│ ├── Transformers/
│ ├── ViewComposers/

Developerul DeLaUnu

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade