Technical Blog about Joomla API
How to implement Domain-driven Design and Hexagonal Architecture in your own Joomla custom components
- Details
- Written by: Mr Alexandre J-S William ELISÉ
- Category: API Technical Blog
![](/images/andrea-leopardi-AZuhLLBG6iw-unsplash.jpg)
About 8mn to read
Component - DDD
Example Component using Domain-driven Design and Hexagonal Architecture principles and recommandations based on what have learned by reading DDD related books, watching YouTube videos and conferences about DDD and hexagonal architecture specifically applied to PHP and also some developer focused podcasts on this topic.
DISCLAIMER:
This repo is more or less like a folder structure to ease the use of "DDD" and "Hexagonal Architecture" also known as "Ports and Adapters" applied to Joomla component. In other words, I'm constantly learning every day new stuff, mainly about tech and here, I share what I've learned about Domain-driven Design applied to Joomla custom component development
HOW IT WORKS:
There are mainly 3 layers :
- 3 - Infrastructure : Code specific to your favorite CMS (Drupal,Joomla,TYPO3,WordPress,etc...)
- 2 - Application : Code where you put Interfaces of Repository pattern, Clock Service to alter time
- 1 - Domain : Code of your Value Objects, your Entities and your Business Rules specific to your Domain
I would like to add 2 more layers which are "horizontal layers" that can be used cross layers on all other layers
- B - Libraries : PHP Libraries for example from packagist.org
- A - Internal : PHP Core (or any language used by your component. It's the foundation on everything else depends)
SUMMARY:
Basically a layer MAY depend on itself and/or lower layers
EXAMPLE USE CASE: You own a Digital Marketing Agency
You want to be able to publish your content simultanuously on Drupal, Joomla, TYPO3 and WordPress because
that's what your VIP clients use. So you hire a team of 6 developers aware of DDD best practices. One of them used Joomla and stumbled on this article. How would these principles apply in real life for your agency?
-
3: Infrastructure
- Drupal
- Drupal specific code implementing Application layer code and/or using Domain layer code
- Joomla
- Joomla specific code implementing Application layer code and/or using Domain layer code
- TYPO3
- TYPO3 specific code implementing Application layer code and/or using Domain layer code
- WordPress
- WordPress specific code implementing Application layer code and/or using Domain layer code
- Your favorite CMS and/or Framework here
- CMS and/or Framework specific code implementing Application layer code and/or using Domain layer code
- Drupal
-
2: Application:
- VIPClient
- VIPClientRepositoryInterface
- VIPClientRepositoryServiceInterface
- ...
- ClockInterface (Could use PSR-20 from Libraries "horizontal" layer)
- VIPClient
-
1: Domain
- BusinessRules
- DeployArticlesToVIPClientsOnly
- ...
- DeployArticlesToVIPClientsOnly
- Common
- AbstractValueObject
- Name
- Company
- Role
- ...
- AbstractValueObject
- VIPClient
- Reward
- LifetimeCustomerValue
- ...
- Reward
- ...
- BusinessRules
-
B : Libraries layer
- composer packages, npm packages, ...
-
A : Internal layer
- PHP Core (the language), Javascript (the language), etc...