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
DDD approach in JHipster #11122
Comments
For me, it is a must have. It can be helped by repositories as example, by documentation, by modifying the current generated code etc... |
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, ... |
@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 here's a proposed workaround (by the author of @modulith) |
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/ |
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? |
@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:
|
DDD strategic patterns are just a way of naming, delineating and organizing concepts. |
@ecostanzi Sure! In my current projects, I have three goals:
|
@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, ***@***.***> 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
<#11122 (comment)>,
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 Layer
Application Layer
The Command Handlers can be used in two different ways:
The secondary ports will be interfaces implemented in the infrastructure.
|
@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. 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. |
@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 ? |
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".
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 : New proposalsFirst proposal
or
Second proposal
or
Third proposal
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, ***@***.***> 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 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
<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
<#11122 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIOKF4ZSYNMF4O7VBU5DP3SHXRITANCNFSM4KGXDFYQ>
.
|
@DevAlves1993 your proposal seems too specific and complex. A jdl concept:
Convert commerce to microservice:
|
I admit, it's really complex.
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.
or
|
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 ***@***.***> 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). 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. |
@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:
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). |
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 :
From @hdurix :
JHipster proposes a technical project base. 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:
pros:
cons:
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.
Then, I can only +1 on this:
|
@pascalgrimaud Problem is: users management won't be a dedicated context for all applications. In fact 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:
In the
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
All my Java classes in a bounded context start with the first name of that context for easier navigation (
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! |
For all users who participated to this ticket, you can have a look at this project: https://github.com/jhipster/jhipster-lite A generated project with JHipster Lite will help to adopt a DDD approach |
DDD approach
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.
Why this ticket?
This ticket is to:
First step
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.
More to come...
If some of you have experience with bringing DDD concepts to a JHipster application, feel free to participate, to give ideas and feedback.
The text was updated successfully, but these errors were encountered: