Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefining ArchUnit tests #3552

Merged
merged 1 commit into from Sep 27, 2022

Conversation

onepunchmagne
Copy link
Contributor

@onepunchmagne onepunchmagne commented Sep 14, 2022

Fix #2921

  • Shared kernels cannot depend on bounded contexts
  • Bounded context can calls each others only using secondary to primary Java adapters communications
  • Domain cannot use anything but its self-domain, Java vanilla features or some common utils libraries
  • Application cannot call infrastructure
  • Primary cannot directly call secondary
  • Secondary cannot call any application service

@onepunchmagne onepunchmagne changed the title Redefining ArchUnit tests Draft: Redefining ArchUnit tests Sep 14, 2022
@hdurix hdurix marked this pull request as draft September 14, 2022 16:52
@onepunchmagne onepunchmagne changed the title Draft: Redefining ArchUnit tests Redefining ArchUnit tests Sep 14, 2022
@pascalgrimaud
Copy link
Member

Does it fix #2921 @onepunchmagne ?

@onepunchmagne
Copy link
Contributor Author

onepunchmagne commented Sep 14, 2022

Work left:

@DamnClin
Copy link
Collaborator

I have a problem understanding why module is a shared kernel and project a bounded context

Not sure to understand the question so I can only answer by saying that module is a shared kernel and project is a business context (I don't think we have a bounded context annotation as this would be really wrong and missleading !)

we have an architecture issue on FileSystemJHipsterModulesRepository calling JavaProjects

This is not a bug, JavaProject is a primary adapter, it's totally normal

@onepunchmagne
Copy link
Contributor Author

onepunchmagne commented Sep 14, 2022

I don't think we have a bounded context annotation as this would be really wrong and missleading !

Here is the thing that should be discussed, the annotation is called @BusinessContext but the tests say otherwise, here is the behavior implemented in the existing tests (before this PR): "Shared kernels should not have dependencies to bounded contexts"
Moreover in the hexagonal-architecture.md we explain in the same paragraph:

So, first things first: an application is made of multiple "hexagons", one for each Bounded Context. (Yes, sometimes you can have only one but this is an exception). We usually have each Bounded Context as root packages in the application.

  • my_business_context: root package for the context (naming depends on your technology naming conventions)

I think @pascalgrimaud and @hdurix aggried that JHLite generates bounded contexts from DDD, but this is very confusing in JHLite code itself. As a user of JHLite our project team also understood that @BusinessContext annotation was from "bounded context" (without understanding why it was not named exactly after the DDD strategic patterns). Also the other annotation coming in pair is the @SharedKernel so it made perfectly sense for JHLite users (not contributors). But for contributors point of view, it is indeed misleading, I can't understand our package-info.java descriptors.

If I may, I would suggest we rename to @BoundedContext explicitely to stick to a well-documented notion that would wear a conviction along with @SharedKernel. But that we remove/redefine the existing package-info.java that seems to randomly wear the annotations. (ticket is here #3540)

@DamnClin
Copy link
Collaborator

Ok, if I'm the only one finding that misleading let's rename it

@codecov
Copy link

codecov bot commented Sep 22, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (814712a) compared to base (40c6e96).
Patch has no changes to coverable lines.

❗ Current head 814712a differs from pull request most recent head 2fcac00. Consider uploading reports for the commit 2fcac00 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##                main     #3552   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity      2093      2074   -19     
===========================================
  Files            545       541    -4     
  Lines           8930      8876   -54     
  Branches         175       174    -1     
===========================================
- Hits            8930      8876   -54     
Impacted Files Coverage Δ
...re/primary/SpringdocOauth2ModuleConfiguration.java 100.00% <ø> (ø)
...va/tech/jhipster/lite/common/domain/Memoizers.java 100.00% <0.00%> (ø)
...e/module/domain/javadependency/JavaDependency.java 100.00% <0.00%> (ø)
...dule/domain/javadependency/JavaDependencyType.java 100.00% <0.00%> (ø)
...le/domain/javabuild/command/AddJavaDependency.java 100.00% <0.00%> (ø)
...or/client/common/domain/ClientsModulesFactory.java 100.00% <0.00%> (ø)
...astructure/secondary/javadependency/MavenType.java 100.00% <0.00%> (ø)
.../secondary/javadependency/MavenCommandHandler.java 100.00% <0.00%> (ø)
...customjhlite/domain/CustomJHLiteModuleFactory.java 100.00% <0.00%> (ø)
...y/FileSystemProjectJavaDependenciesRepository.java 100.00% <0.00%> (ø)
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -1,2 +1,2 @@
@tech.jhipster.lite.BusinessContext
@tech.jhipster.lite.SharedKernel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project is not a shared kernel, I don't understand this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible I'd like to take also this job but in issue #3540
because sticking to the architecture tests, we have a failure because project is called directly by module which is tagged as a shared kernel.

To be honest I have absolutely no clue currently of which package is a shared kernel and which is a "business" context, but there is something to do in this separate issue I think to realign the dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake :D project is a business context and module is a SharedKernel, what is the link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the whole thing about SharedKernels.shouldNotDependOnBoundedContexts is wrong I suppose, I delete it. A shared kernel can actually call bounded contexts following the same rule as passing through its secondary adapter to call the bounded context primary adapter, is that right?

Thus the shouldBeAnHexagonalArchitecture test should also be applied to shared kernel in the exact same way. Please check new change where I applied this logic

classes()
.that()
.resideInAnyPackage(context + ".domain..")
.resideInAPackage(".domain..")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, here we are allowing domain to depend on any domain no? No more check for domain dependencies to other domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but there were a lot of overlaying tests so I tried defining different separate responsibility tests such as:

  • BoundedContexts.shouldNotDependOnOtherBoundedContextDomains which will verify our hexagons co-existence and boundaries
  • Domain.shouldNotDependOnOutside which does not even know it co-exists with other hexagons, it simply check its dependencies to "outside" of a domain package

@onepunchmagne
Copy link
Contributor Author

This can give some god hints: https://github.com/whiskeysierra/archunit-hexagonal/blob/trunk/src/main/kotlin/io/github/whiskeysierra/archunit/hexagonal/HexagonalArchitecture.kt

Thanks for the correction you're right, I used the hint trying to define some basics rules, I get that it's hard to define "the" hexagonal architecture test but it should probably serve as a good base for people to update according to their definition.

* Shared kernels cannot depend on bounded contexts
* Bounded context can calls each others only using secondary to primary Java adapters communications
* Domain cannot use anything but its self-domain, Java vanilla features or some common utils libraries
* Application cannot call infrastructure
* Primary cannot directly call secondary
* Secondary cannot call any application service

Remove empty packages/"todo" contexts to restart from a clean implementation matching expected architecture.
@DamnClin DamnClin merged commit 04fe364 into jhipster:main Sep 27, 2022
@onepunchmagne
Copy link
Contributor Author

@DanielFran
Copy link
Member

@onepunchmagne approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hexagonal Arch: add new test - secondary can call primary from another context
4 participants