0

I'm trying to organize DDD project using hexagonal architecture in java 9 (using maven modules). Is there anywhere working example that is already being used in productions systems? So, far I have only some idea how to do this:

Here I have domain module which has all commands, events, domain model (with aggregates, entities and value objects), and repository interfaces + domain service interfaces (if relay on infrastructure) and implementations. Other application module holds application services where I have "use-cases" of the application (simple methods that orchestrate loading of aggregates etc.).

Now what about these adapters in hex architecture? Should every adapter be separated in module (e.g. mysql-adapter where I could implement repositories that rely on infrastructure? Also, having separate module for rabbitmq aggregate?

Any examples on this would be great!

enter image description here

Bojan Vukasovic
  • 1,474
  • 14
  • 28

1 Answers1

0

I'm writing a hexagonal architecture example with java 9 and maven. Still not finished, I will publish it when done.

But so far I can tell you my approach:

  • One module for the hexagon (it requires no other module). For each port I have a package that the module exports.

  • One module for each adapter. Requires the hexagon module.

  • One module for main. Requires the hexagon and all adapters modules. No other module requires main module. It builds the the whole system and run the driver adapters.

For selecting one adapter for each driven port I use the serviceloader mechanism.


I don't use DDD in this example, but if I used it, the structure would be:

  • The hexagon would be an aggregator module (no source code), just with 2 requires transtive to application module and domain module.

  • Application module requires domain module. It exports packages which are the driver ports (use cases), and maybe driven ports too (implemented by driven adapters.

  • Domain requires no module. It exports packages which are the driven ports.


I recommend the book "Java 9 Modularity" by Sander Mark and Paul Bakker.

I will publish an article at

https://softwarecampament.wordpress.com/portsadapters/

and my example at github if you wanna take a look when done.

choquero70
  • 3,332
  • 2
  • 24
  • 40