xmolecules / jmolecules

Libraries to help developers express architectural abstractions in Java code
http://jmolecules.org
Apache License 2.0
1.21k stars 102 forks source link

Define strategy to avoid need for over declaring architectural concepts #19

Open odrotbohm opened 3 years ago

odrotbohm commented 3 years ago

jDDD artifacts are designed to be usable as independently as possible. E.g. the onion architecture annotations are usable completely without the building blocks annotations in jDDD Core. That however also imposes an interesting challenge. Let's say your project combines the two artifacts. To benefit from both the declarations, you would now have to do the following:

@AggregateRoot // from jddd-core
@DomainLayer // from jddd-architecture-onion
class MyAggregate { … }

This is basically expressing the same thing twice as you could argue that from the fact, that MyAggregate is an @AggregateRoot, it belonging to the domain layer is implicit.

A very direct solution for that would be to meta-annotate @AggregateRoot with @DomainLayer. However, that would introduce a dependency in the wrong direction and kind of imply that jDDD Core annotations would imply onion architecture, despite that technical dependency not be a strong one at runtime (as annotations can be missing without failure). It would be logically more consistent to transparently "annotate" MyAggregate with @DomainLayer if it is annotated with @AggregateRoot and jDDD Onion Architecture is in use.

There are two options to achieve that:

  1. We could leave that semantic derivation to downstream tools that can embed such rules into the implementation of their analysis. E.g. jQAssistant could easily add that additional metadata to its model based on that rule. I'd love to see that in those tools (ArchUnit, too) but at the same time it means that other tools evaluating the annotations only would not see those "derived" annotations.
  2. Just like we already prototypically add technology specific annotations derived from metamodel ones in the jDDD JPA Plugin, we could use ByteBuddy to declares these additional annotations transparently by implementing a plugin.
  3. Lombok seems to be getting a meta-annotation feature soon.
ikysil commented 3 years ago

There are way too many @Domain... annotations defined in the jmolecules to make the semantic derivation safe. I doubt it will be safe to derive ALL of those for @AggregateRoot:

A set of the ArchUnit rules enforcing particular combination would be more useful, as projects then may decide which combination (one or many) fits the context.

Also, the dependency on the implicit annotations makes architectural checks fragile. I would insist on explicit declarations in the projects I'm working for.

odrotbohm commented 3 years ago

Thanks for the feedback, Illya. I share your concerns and it's very likely that we end up doing just nothing for now. It's still good to have the ticket around to gather feedback.