For now, JHipster is only able to create CRUD entities and JHipster's goal is to help developers in building all the technical aspect of an application.
It could be interesting to explore how JHipster could also help them build the "business" of the application.
One approach for that is the methodology called Domain Driven Design.
This ticket is to:
I would like to work on a application generated by JHipster and to refactor it in order to bring DDD concepts (aggregates, entities, value objects, domain events, ...) and have example to show and to discuss about.
If some of you have experience with bringing DDD concepts to a JHipster application, feel free to participate, to give ideas and feedback.
For me, it is a must have. It can be helped by repositories as example, by documentation, by modifying the current generated code etc...
There is a lot of work I think, so I'm putting a big bounty on this. You'll be the lead on this part @hdurix, don't hesitate to ask help
cc @nonomoho as you probably have ideas on this
I think the most important part of DDD lies in the strategic patterns(bounded contexts and context mapping) instead of the tatics patterns(repositories, aggregates etc). As long as you have a clear separation of contexts, a good idea of their relationships and a conceptual model within each context, you are using DDD even you are just CRUDing all the way through in each these contexts.
So perhaps we should start by telling people how to organize their code by contexts and apply “clean architecture“ within some key context which have a relatively complex domain model, instead of going for the tactics patterns right away?
I completely agree with @johnbanq advice. In early phase, starting with "clean architecture" for complex domain model.
Do you have a specific flavor of "clean architecture" in mind? Hexagonal, onion, ...
Personally I like the modulith approach: package by feature/context and using spring events for inter module communication
@gmarziou spring events have the problem of lost events if an exception happens during event publication, listeners will never get notified
@mohamedzaki90 Well, I never experienced this in my apps, do you have some reference to share?
My understanding is that if an exception is thrown during event publication, the publisher will get it and its transaction will rollback. So I can't imagine how you could lose an event at least in a transactional context. If you' re not in a transaction, then you will have to catch and manage the exception.
@gmarziou take a look at the caveats here
https://www.baeldung.com/spring-data-ddd
here's a proposed workaround (by the author of @Modulith)
https://github.com/odrotbohm/spring-domain-events
Thanks, I have never experienced this case maybe because I always used them inside a transaction and recording state change in database both from publisher and listeners, and then scheduling retry for unprocessed changes.
Interesting DSL: https://www.innoq.com/en/blog/code-your-model/
Do you have a specific flavor of "clean architecture" in mind? Hexagonal, onion, ...
Personally I like the modulith approach: package by feature/context and using spring events for inter module communication
My take on this is pretty much the same, build modulith and use a hexagon-ish architecture in each of the contexts but I also allow cross-context communication by calling interfaces in a dedicated "api" package in each context(the implementation of the interfaces are provided by DI).
Maybe we can build a small sample that demonstrates this as a starting point?
PetClinic might be a good project to start
@hdurix I hope to start on my first DDD JHipster / Angular application on Feb 1. To me, DDD has two advantages:
It seems to me that a functionality associated with this tickect could be to create a multi-module project with the same notation in JDL of microservices, that is to say, use the same microservice notation to map DDD modules, said roughly, the possibility of having microservices packaged in the same application.
@hdurix : what is the state of this ticket ?
hi @hdurix, do we have to consider this ticket for the v7?
@hdurix After close to 5 months of using DDD with JHipster, I can wholeheartedly recommend this approach:
@ksilz that's interesting. Are you willing to share more details about the project structure? As @johnbanq suggested, we should start with some samples.
DDD strategic patterns are just a way of naming, delineating and organizing concepts.
I think developers who want to use a DDD approach in their project want to be able to use tactical DDD patterns.
In my opinion, the biggest challenge with the DDD approach in JHIPSTER is to model the processing and the business rules inside the entities which will be overwritten during the next regeneration. The “side by side” approach does not work well in this case without making the domain model more complex, which we especially don't want in DDD.
Another thing, it is also currently impossible to model concepts in JDL using ValueObjects.
It can be a good start ...
@ksilz that's interesting. Are you willing to share more details about the project structure?
@ecostanzi Sure! In my current projects, I have three goals:
application/port/in
folder has the use case, application/port/out
the ports, and application
the services that implement the use case with the help of the ports. adapter/out
has the adapters implementing my ports, and adapter/in
the REST controllers. My domain classes are in domain
. Angular is nearly the same: It's missing the application/port/in
folder but has a ui
folder with Angular UI modules. I still have JHipster generate an Angular UI, but I disabled its loading and move all these UI files into a separate folder outside of src
(just in case I want to see how something is done there in the latest JHipster version).This approach in JHipster is something a lot of people want: it's in V7 roadmap.
But as this ticket has been opened since january, so I'd like to know if someone is willing to work on this.
Otherwise, I'll remove this ticket from our roadmap.
Anyway, the sample app can be coded during JHipster Code, and probably the templates would be for the next major version V8, in 1 or 2 years.
cc @hdurix @jhipster/developers @johnbanq @huytmb @ksilz
I plan to work at some point on extending what has been called embedded
entities - which could be seen as ValueObjects - currently supported only for MongoDB and Couchbase, to other databases that could be supported (SQL, Cassandra, ...), because IMO ValueObjects are a must have for DDD approach.
Not sure I can do it for V7, but since it would be a new feature without breaking change, it doesn't have to wait for a major release.
@ksilz : really sorry I didn't saw you mentioned me. Use what you want:
For your information, at JHipster Code, we'll have a live stream Twitch and we'll talk about Hexagonal Architecture, so it will be really interesting I'm sure ;)
@pascalgrimaud Thank you for your reply! I'll watch the conference videos for sure! My current project is a JHipster Angular application, soon with Flutter apps for iOS & Android. Using the same clean architecture in two platforms (Java, Angular) has helped a lot. Using the same approach in Flutter will make my life easier.
Here is the example application produced during JHipster code: https://gitlab.com/cdamon/padbowl feel free to use any part you want.
Replays of the live will come as soon as we finished editing them
thanks a lot @DamnClin !
Sure it will help a lot
Wooow that's HUGE! I didn't have the opportunity to watch the live video yet but the code is a really great example of how DDD can be applied in a JHipster project.
A big thanks to @DamnClin!
I'm sure that adding this video (with the GitLab repository link) to a dedicated section in jhipster.tech would help a lot of people wishing to understand how DDD can be used in a JHipster project.
I agree @hdurix so I'm proposing this:
Then, after that, I think the bounty is for @DamnClin ! Really well deserved
About Hexagonal Architecture, it can't be done for v7. There are too much work in our template. But we can start it in a blueprint or for v8. But for V8, we'll have it !
@pascalgrimaud just to let you know I plan to work on this sooner. Probably next month.
Currently I am applying DDD to projects ignoring the fact everything is monolith for now.
I have plan to create the following structure for Foo
entity and Bar
domain:
Without this basic structure, it's really difficult to create blueprints for DDD approach.
I am using spring events and hibernate events, which aren't scalable.
They would fit as blueprints, but don't have plans to do it.
Thoughts?
It's similar to https://gitlab.com/cdamon/padbowl/-/tree/master/src/main/java/com/jhipster/padbowl/game :
For blueprint, I thought about changing destination of folder. Instead of moving to "repository/", moving to "infrastructure/secondary", etc... That's why I think a blueprint would be not so difficult. And maybe directly in generator-jhipster too.
But I need time to think more :D
I don't like infrastructure and primary/secondary naming.
Infrastructure as a non native speaker means something physical, it should be something more generic as adapter or port.
Primary/secondary means importance but I think they are just adapters/ports, every one doing it's job.
Replaced rest with web, it's more specific.
I have implemented adapter/event
and adapter/monolith
.
I created monolith has a service abstraction form keeping domains independent, so they communicate using adapter/monolith/*Service
.
yes, the final name can be discussed and maybe could be customized, as I've seen so different namings
as you seem very active these last months, do you think it could be possible to have this for JHipster v7 ?
Of course, all the team need to agree
@pascalgrimaud yes, it's possible, but this new rule to require reviews can complicate, most of my PRs are related to the generator, and they stay most of the time unreviewed forever just like the incremental changelog one that you said to merge it after almost 1 month.
My workflow was: create PRs, keep them open for 2-7 days (new features I kept longer) depending on how certain I was about the implementation, then If no feedback was given, I went ahead and merge.
I have 4 PRs ready, I think they can be merged, but the angular one I would keep open longer.
In my opinion this change should be reverted or we should implement code owners so a member of a team could commit to some files without requiring reviews.
IMO the basic task are:
After that, we should discuss domain isolation.
I agree with you. We should not block workflow and go on
cc @deepu105 : do you agree to remove the last rule about asking each PR to be approved ?
@mshima I don't think using web / repository or some other protocol / pattern specific naming for adapters is a good idea because you'll have other type of adapters as soon as you need orchestration between your contexts (just an example).
Perhaps driving (for primary) and driven (for secondary) can be good candidates as they speak what they are doing. I like using primary and secondary simply because it's the name you'll find most of time since they are coming from Alistair : "In implementation, ports and adapters show up in two flavors, which I’ll call ‘’primary’’ and ‘’secondary’’, for soon-to-be-obvious reasons. They could be also called ‘’driving’’ adapters and ‘’driven’’ adapters.".
Using this kind of architecture without breaking it's principle is hard enough when you are not used to it so I try to stick to some well known references.
For the "infrastructure" level I think all naming can be good as soon as it exists, I think "outside" can also be good (same, i don't really using a pattern name for a package (module if we stick to ddd)).
@pascalgrimaud I was also think about a fun idea to help people stick to this architecture: blocking all spring dependencies in **/domain. This shouldn't be hard to do an may be a good help.
BUT, as i sayed many time during that day: I'm not a JHipster contributor (and probably never will be) so, those are just my though on this. It's easy for me since I'm only here to criticize :D. Of course, this in just an advice of a guy doing this (and really enjoying the approach) on multiple products for a year now. Take it as an advice, nothing more !
@DamnClin : about blocking spring dependencies in **/domain, it's easy to do with ArchUnit. This librairies is there for this specific reason, something like:
all class in **/domain should not import org.springframework.*
Then, we can add more rules of courses.
thanks a lot @DamnClin : approved
@pascalgrimaud if you think thats appropriate its ok for me. Anyway my aim was just to disable direct commit to master without PR. The review rule was just a way to achieve it
I don't know if we should do a drastic breaking change of folder structure
closer to release. I assume this would break all server side blueprints. We
should have atleast communicated earlier to give blueprints authors time to
prepare. Else we should do it as an option but then it will be maintainance
burden unless we find some smart solutions
On Sat, 26 Sep 2020, 8:40 am Pascal Grimaud, notifications@github.com
wrote:
thanks a lot @DamnClin https://github.com/DamnClin : approved
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/11122#issuecomment-699440584,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAIOKF3FTQ65RLW6YQGYLY3SHWEHTANCNFSM4KGXDFYQ
.
Hello,
I would like to propose the following hierarchy for the domain package and application package, the objective being to have a hierarchy quite close to the principles defined by the Domain Driven Design and Hexagonal Architecture.
├───domain/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
|SUB-DIRECTORY |CONTENT |REQUIRED |
|----------------------|-------------------------------|------------|
|Entity |The business entities of the domain.|Yes |
|ValueObject |The business value objects of the domain.|No |
|Exception |Business exceptions in the domain.|No |
|Service |Business Domain Service.|No |
├───application/
│ ├───usecase/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
|SUB-DIRECTORY |CONTENT |REQUIRED |
|----------------------|-------------------------------|------------|
|UseCase|The use cases are the processes that can be triggered in our Application Core by one or several User Interfaces in our application.|Yes |
|Command |The commands used in use cases supported by the command handler.|Yes |
|CommandHandler |The Command Handlers.|Yes|
|Queries |Query Managers or Handlers.|No |
|Port|Secondary ports. |No |
|DTO |Data transfert object|No|
The Command Handlers can be used in two different ways:
The secondary ports will be interfaces implemented in the infrastructure.
Typically, their role is to :
@deepu105 : I'm not sure we are closer to the release. There are still some work to achieve. Then, we should not target a specific date, it will be released when it's ready.
Major version is perfect to introduce breaking changes. We should not be afraid about that.
Otherwise, we'll need to wait V8, it will be in 2 years
Then, this ticket is opened since January so the users are already aware of that
@DevAlves1993 I strongly advise against this as this is totally the opposite of DDD principles. In DDD modules (packages in Java) are parts of the Ubiquituous Language. Packaging by feature allow really better designs, one of the main goal of this package organization is to keep an high cohesion in each module.
We don't really need to see immediately if some class is an Aggregate or a Value Object since it will be obvious when looking at the APIs. We do really need to know what business logic stands in a given module.
Another important thing: ports, queries and command are part of the domain otherwise you'll have to break the: "Everything depends on the domain, the domain depends on nothing" principle. The application layer must remain really thin: for a given context there is no need to split it.
@pascalgrimaud the changes I will implement are opt-in, so traditional generation will be applied if no domain is specified.
About your hexagonal project, I think we shouldn't convert the main application/user management into domain for v7 by default but it would be ok with opt-in.
But it's really cool to test different package structure.
@mshima : I'm beginner in this kind of architecture, don't rely on my project, I only played this morning with JHipster, and did some refactoring/renaming folder, nothing more
If we can keep both type of generation, I afraid it will be a lot of stuff to maintain...
Let's keep on thinking and discussing about how to deal with the future of JHipster
cc @jhipster/developers : your opinion is important here. Should we change the JHipster folder to match with an Hexagonal Architecture or is it too early ?
@DamnClin
Another important thing: ports, queries and command are part of the domain otherwise you'll have to break the: "Everything depends on the domain, the domain depends on nothing" principle. The application layer must remain really thin: for a given context there is no need to split it.
I agree with you ports, queries and command are part of the domain. The mention "Application Layer" can be confusing, I would have said "Application Business Rule".
I define the domain as the combination of the Application Business Rule and the Enterprise Business Rule and the fact that the Application Business Rule is closely related to the Enterprise Business Rule.
Packaging by feature allow really better designs, one of the main goal of this package organization is to keep an high cohesion in each module.
Indeed, an organization by functionality would be the best and would be closer to the representation of the company. What is your definition of the word "feature", is it a sub-domain or a delimited context or both?
Personal opinion :
Enterprise Business Rule and Application Business Rule must be as pure as possible, it must not depend on external elements (framework & co). Nevertheless, Application Business Rule can depend on hundreds of libraries (also quite pure) such as the Javax Validation library.
├───domain/
│ ├───subdomain1/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
│ ├───subdomain2/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
├───application/
│ ├───usecase/
├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
or
├───domain/
│ ├───subdomain1/
│ ├───.... (java files)/
│ ├───subdomain2/
│ ├───.... (java files)/
├───application/
│ ├───usecase/
├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
├───domain/
│ ├───application/
│ ├───usecase/
│ ├───subdomain1/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
│ ├───subdomain2/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
or
├───domain/
│ ├───application/
│ ├───usecase/
│ ├───subdomain1/
│ ├───.... (java files)/
│ ├───subdomain2/
│ ├───.... (java files)/
├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
├───domain/
│ ├───subdomain1/
│ ├───application(Application Business Rule)/
│ ├───usecase/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
│ ├───core(Enterprise Business Rule)/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
│ ├───subdomain2/
│ ├───application(Application Business Rule)/
│ ├───usecase/
│ ├───command/
│ ├───commandhandler/
│ ├───queries/
│ ├───port/
│ ├───core(Enterprise Business Rule)/
│ ├───entity/
│ ├───objectvalue/
│ ├───exception/
│ ├───service/
├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
Personally I prefer the third proposal.
@DamnClin what would be the best hierarchy for you ?
I honestly don't care about DDD and such. To me you use whatever works for
your project (many benefits that we theoritically claim from certain
approach is often superficial in practice). So if there is a majority
consensus on something then go with that. my only concern would be if we
end up making things more complicated than it is today just to fit certain
approach without any tangible value in real world use. But if DDD makes
things simpler than I'm fine with it.
On Sat, 26 Sep 2020, 3:05 pm Pascal Grimaud, notifications@github.com
wrote:
@mshima https://github.com/mshima : I'm beginner in this kind of
architecture, don't rely on my project, I only played this morning with
JHipster, and did some refactoring/renaming folder, nothing moreIf we can keep both type of generation, I afraid it will be a lot of stuff
to maintain...Let's keep on thinking and discussing about how to deal with the future of
JHipstercc @jhipster/developers
https://github.com/orgs/jhipster/teams/developers : your opinion is
important here. Should we change the JHipster folder to match with an
Hexagonal Architecture or is it too early ?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/11122#issuecomment-699493168,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAIOKF4ZSYNMF4O7VBU5DP3SHXRITANCNFSM4KGXDFYQ
.
@DevAlves1993 your proposal seems too specific and complex.
Having a common infrastructure for the entire application hurts DDD concepts, by hurting domain isolation.
A jdl concept:
store_domain.jdl
:
entity Product {}
entity Consumer {}
entity Order {}
domain Store {
entity Product, Consumer, Order
}
notification_domain.jdl
:
entity Channel {}
domain Notification {
entity Channel
}
commerce_application.jdl
:
application Commerce {
config {
applicationType: monolith
prodDatabaseType: postgres
}
load domain Store from 'store_domain.jdl', Notification from 'notification_domain.jdl'
entity Store.*, Notification.*
}
Convert commerce to microservice:
application Commerce {
config {
applicationType: gateway
prodDatabaseType: postgres
}
load domain Store from 'store_domain.jdl', Notification from 'notification_domain.jdl'
entity Store.*, Notification.*
}
application Store {
config {
applicationType: microservice
prodDatabaseType: neo4j
}
load domain Store from 'store_domain.jdl'
entity Store.*
}
application Notification {
config {
applicationType: microservice
prodDatabaseType: couchbase
}
load domain Notification from 'notification_domain.jdl'
entity Notification.*
}
@DevAlves1993 your proposal seems too specific and complex.
I admit, it's really complex.
Having a common infrastructure for the entire application hurts DDD concepts, by hurting domain isolation.
The proposals I made completely ignore the infrastructure (it's done express), the most important for an application that uses the DDD principle is to have a code base that identically represents the business. I consider the infrastructure as a disposable element.
I also note that the objective of the hexagonal architecture is to completely isolate the business code base (while keeping it pure enough) from the infrastructure code base.
A proposal based on your jdl concept.
├───commerce(domain)/
│ ├───store(sub-domain)/
│ ├───usecase/
│ ├───entity/
│ ├───port/
│ ├───command/
│ ├───commandhandler/
│ ├───other/
│ ├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
│ ├───notification(sub-domain)/
│ ├───usecase/
│ ├───entity/
│ ├───port/
│ ├───command/
│ ├───commandhandler/
│ ├───other/
│ ├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
or
├───commerce(domain)/
│ ├───store(sub-domain)/
│ ├───application/
│ ├───core/
│ ├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
│ ├───notification(sub-domain)/
│ ├───application/
│ ├───core/
│ ├───infrastructure/
│ ├───primary/
│ ├───rest/
│ ├───cli/
│ ├───secondary/
│ ├───repository/
│ ├───entity/
│ ├───service/
│ ├───config/
│ ├───otherspackage/
I don't like all the nested packages with generic names. People hate Java because you have to navigate so deep to find anything. This seems to be just making it worse.
On Sep 25, 2020, at 14:49, Pascal Grimaud notifications@github.com wrote:
I agree with you. We should not block workflow and go on
cc @deepu105 : do you agree to remove the last rule about asking each PR to be approved ?—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
I don't think to go DDD this way will be beneficial, usually you are better off using multi-module but makes things a bit more complicated if not using a bus to connect each micro-service (domain context).
Nowadays I use AxonFramework, I split core domains, events, controllers, query handler/projection, DB definition and DB access, etc in specific modules.
I just give my opinion here, I know jHipster will not have a hard dependency on another framework.
Event if DDD is a good approach to solve some complex situation within a given context, without an actual framework to support it, I think it is better to keep jHipster the way it is currently working.
And a generated code will quite often not fit the DDD domain, APIs should not be CRUD anymore, multi-module, etc; what's been generated will have to be moved, etc; Still good for monoliths/micro-service and establish a good starting structure for a project.
@DevAlves1993 For me you don't need to split things that works together in separated modules. I'm always trying to make things more cohesive (Kent beck came up with the word "cohesivating" (hoping somebody will find better) to talk about that during DDD Europe 2020).
So, in my definition, a feature is something cohesive :) (yep, a pretty bad definition I must admit) so you'll have:
|context1
|-application
|--Feature1ApplicationService.java
|--Feature2ApplicationService.java
|-domain
|-java files
|-feature1
|--java files
|-feature2
|--java files
|--feature3 (domain specific)
|--java files
|-infrastructure
|--primary
|---feature1
|----java files
|---feature2
|----java files
|--secondary
|---feature1
|----java files
|---feature2
|----java files
|context2
The number of features in each "parts" of the architecture (application, domain, primary and secondary) can vary depending on internal needs. The key is to be highly cohesive and lowly coupled. I use a lot of package (default) visibility in primary and secondary because the stuff here don't need to go outside.
In a given binary (a microservice for example) you can have multiple Bounded Contexts, each context can have his architecture. In my projects, most of them are using hexagonal architecture but some of them are just anemic CRUD (because sometimes I just need that).
As always, there is no Silver Bullet. The goal of Clean Architectures is to allow domain protection (so we can code business value here). I like the flavor of hexagonal architecture I showed at JHipster code but, like i sayed live: "This is suiting MY needs: allowing to go faster to a better solution". It may not suit yours! Switching from a classic layered architecture to this one skyrocket the team velocity, highly reduce (understand to zero) the number of bugs and cost of changes. This is my personal observation made on several projects but this comes with a cost: a mindset change for some developers and "managers" (or the likes).
@Blackdread Event if DDD is a good approach to solve some complex situation within a given context, without an actual framework to support it, I think it is better to keep jHipster the way it is currently working.
I agree with you on that! I don't think we should try to have a generator for DDD (in fact it's a nonsense) but perhaps, JHipster can help create an hexagonal architecture: those are 2 separated thinks. My goal at JHipster code was to show how I used this kind of architecture along with JHipster, I dropped the DDD parts somewhere on the way preparing this track.
I really don't know what you, JHipster contributors, can get out of that :)
I think there is a misunderstanding here about DDD and Hexagonal Architecture.
From @DamnClin :
I don't think we should try to have a generator for DDD (in fact it's a nonsense)
From @hdurix :
It could be interesting to explore how JHipster could also help them build the "business" of the application.
JHipster proposes a technical project base.
This ticket is here because some people are convinced that JHipster can provide an Hexagonal Architecture structure where you can apply DDD concept for your customer.
Sorry, but I don't talk about demo or hello world application.
I talk about real project, for real customer, built from scratch with JHipster. That's the main reason of the success of JHipster.
Let me resume what can be done:
Solution 1: nothing, stay like this
The user can build his business code like it is done here:
game
folder, with application
, domain
and infrastructure
pros:
cons:
domain/
, new entities from hexagonal architecture will be in game/infrastructure/secondary
web/rest
, new implementations of API will be in game/infrastructure/primary
Solution 2: move to Hexagonal Architecture structure
Default JHipster application already contains User domain, which can be improved a lot to provide a good example.
What can be done (can be changed, of course): when generating a new JHipster app
Then, I can only +1 on this:
Switching from a classic layered architecture to this one skyrocket the team velocity, highly reduce (understand to zero) the number of bugs and cost of changes.
@pascalgrimaud Problem is: users management won't be a dedicated context for all applications. In fact User
is a very good example of something changing from one context to another. Nevertheless I think it's possible to create a shared user kernel and an account context. It will have to be adapted but that look like a decent example when generating the application.
The shared kernel can come with a Username value object in domain enforcing some simple rules:
You'll also find an infrastructure/primary in this shared kernel with:
Username
). I didn't moved it in PadBowl because I wanted to keep something looking a bit like a JHipster application for this demo.In the account
context you'll find account management tools:
Username
as Id);Then comes the endpoint security question and this is a though one. Sticking to RBAC by default seems to be a good call. People needing to check who can do operations on which data will come up with solutions like kipe (as you can see this is a shared kernel in PadBowl).
JHipster can also come with a rich Assert class providing fluent assertions for the most common types (String, Numbers, Collections, ...).
There is something really important to keep in mind: this way of working works well only when working in TDD to design domains. Fact is: TDD takes a lot of work and time to master! You also have to switch from technology being the goal of a project to technology just being a tool helping you build your product. Not all teams are willing to do this switch; to learn the approaches and to tackle the final boss: DDD. This is totally fine! Giving users options to do so can be great but you can't force everybody to do that as it takes way too much time and dedication to code!
I'm turning 34, been doing code for almost 20 years and I'm still really enjoying doing so! I'm really lucky, I'm doing a work I love but many developers out there don't have that luck. They don't like coding, they are doing it because you can live doing that. You can't ask them to work full evenings and weekends just to be able to barely understand what's going on!
Of course, when I see the value we can bring to users using those tools I'd like every product out there to use them but this is not possible. We can only help people accepting help. For those ones, switching from a JHipster generated project to one using hexagonal architecture and enabling a DDD approach can be done in a matter of hours with an example. I think this is fair enough.
If JHipster can provide some easy to maintain tooling (like Assert or stuff like that) it will be awesome. Then let's continue the switch on PadBowl and add it in the documentation. In my opinion, this is better than trying to generate applications that way because it will mean maintaining both ways.
For me, this struggle is way to hard and peoples willing to do DDD will find a way! Again, this is just my advice, it doesn't worth much since I won't do this code in JHipster!
I added an actual repository implementation and some business rules to PadBowl. We can add more business rules or work to add another context to this example application. Anybody want's to do this with me live on Ippon's Twitch Channel (so we'll have the replays)?
Can we close this now? I don't think we're ready to make this the default option for JHipster.
@DamnClin @pascalgrimaud @mraible Sorry for only chiming in now!
Here's how I structured my application with my first attempt at clean architecture. I the same set of folders, classes & interfaces in Java and Angular:
So here's what my folder structure looks like in Java. Everything's in a clean
package. The four bounded contexts each have a folder of their own with identical structure:
|--clean
|--app
|--organization
|--shared
|--visit
|--adapter
|--in
|--VGetCustomerController.java
|--out
|--VGetCustomerAdapter.java
|--application
|--port
|--in
|--VGetCustomerUseCase.java
|--out
|--VGetCustomerPort.java
|--VGetCustomerService.java
|--domain
|--VCustomerService.java
All my Java classes in a bounded context start with the first name of that context for easier navigation (V
here). Here are the classes mentioned above. The methods are complete, except for VGetCustomerAdapter
.
public interface VGetCustomerUseCase {
VCustomer get(Long id);
}
public interface VGetCustomerPort {
VCustomer get(Long id);
}
public class VGetCustomerService implements VGetCustomerUseCase {
private final VGetCustomerPort port;
@Override
public VCustomer get(Long id) {
return this.port.get(id);
}
}
@RestController
public class VCustomerController {
private final VGetCustomerUseCase useCase;
@GetMapping(URL_VISITS_CUSTOMER + "/{id}")
public ResponseEntity<VCustomer> getCustomer(@PathVariable Long id) {
VCustomer feedback = this.useCase.get(id);
return ResponseEntity.ok().body(feedback);
}
}
public class VGetCustomerAdapter implements VGetCustomerPort {
@Override
public VCustomer get(Long id) {
// my own code for validation
// using JHipster-generated code to load customers
}
}
I've used this for half a year now. So here are the pros of my approach:
The one con is that my ports & use cases are nearly always identical. So I could do away with the port interfaces and the service classes and have my adapter implement the use case directly. I won't do this for now because there are reasons for having use cases and ports. Maybe I'll still encounter them!
Most helpful comment
I think the most important part of DDD lies in the strategic patterns(bounded contexts and context mapping) instead of the tatics patterns(repositories, aggregates etc). As long as you have a clear separation of contexts, a good idea of their relationships and a conceptual model within each context, you are using DDD even you are just CRUDing all the way through in each these contexts.
So perhaps we should start by telling people how to organize their code by contexts and apply “clean architecture“ within some key context which have a relatively complex domain model, instead of going for the tactics patterns right away?