The value classes are part of the domain model and lives along side your entity classes
Imagine a folder structure (a VS project) that has four top level folders: Interactors, Entities, Boundaries, Gateways.
This is your application
What Uncle Bob calls entities on his Clean Architecture diagram is what DDD calls the domain model. The model consists of values, entities, aggregates, domain services, repository interfaces
Your mapping looks correct except for domain services -> interactors.
... Validation is a good one. The domain service can validate that an entity is in a valid state.
... A domain service is part of the domain model, but doesn't fit well into a single class. A domain service can perform a significant business process, transform a domain object from one composition to another, or calculate a value requiring input from more than one domain object. ...
... In DDD there are Application services that map to the interactors. "The application services are the direct clients of the domain model. These are responsible for task coordination of use case flows, one service method per flow. ...
Shouldn't an entity guaranty it's (enterprize wide) invariants so that it is impossible for it to be in an invalid state (regarding the enterprize wide invariants) in the first place?
so in DDD, when an operation does not conceptually belong to any domain object (Entity, Value Object or Aggregate[Root]) these operations can be implemented in domain services.
-> Where would those kinds of operations go in a CleanArchitecture?Would it be one more entity? Would it be something like the Authorizer used by the LoginInteractor in EP 23? Is the before mentioned Authorizer an entity in the first place? Would it be seen as application specific or as enterprize wide? Was it allowed to share logic/functionality residing outside of entities [if that is necessary in the first place!] enterprize wide? -> I assume not and thus (maybe naively) conclude that in a CleanArchitecture: Every functionality, may it conceptually belong to any existing domain object or not, when wanted to be available enterprize wide must again be in the form of an entity ... ehh, right? But then on the other hand, when the operation/functionality just needs to be used in the application specific context ... what would it be, where would it go? Probably into an Interactor (I guess there the concept intersects with DomainServices and ApplicationServices) .. or is it possible to have application specific entities?? .. I guess not.
annotation: In CleanArchitecture in addition to the entities the Interactors contain (only application specific instead of enterpize wide) (validation) business logic as well.-> This leads me to further questions.What if an application specific validation logic that conceptually belongs to a specific entity needs to be executed in several Interactors/UseCases? To what kind of component (outside of any entity) should this piece of functionality be extracted in order to stay DRY and where would it reside in the (folder) structure? I really can't imagine that it would be another Interactor because .. why would you potentially do an unnecessary mapping of data onto InteractorRequestDTOs again? We are behind the application boundary already and the logic that we want to call doesn't need to be called from outside the boundary and in addition it isn't necessarily a separate UseCase(Flow/Story).
This question is more of a general nature: As for entities setters (and getters) for private data fields should be avoided where possible, I assume application specific validation logic for such an entity (that resides in the interactors or in the above mentioned components in question) should be executed before the state-changing behaviour _of_ (or _on_) the entity is initiated?..... that's another part that's kinda difficult to grasp: How to avoid setters on entity objects .. or let's say: when _application specific behaviour_ should be initiated, how do you implement behaviour affecting entities if it is not allowed to implement it for the (enterprize wide) entity object itself? Can it be done only by having some private field setters on the entity? .. Does the term "application specific _behaviour_" makes any sense then? .. Or can the term only be seen for a level as granular as to the Interactors but not any further (because using setters on the entities then would technically not be behaviour anymore)?
That is business logic, not domain logic, and thus resides in the application layer.
The entities can be viewed as being only as restrictive as the domain requires. It should allow the maximum flexibility inherent to the domain. The application layer cannot make the domain more flexible than it already is, but it can make it more restrictive to address the use cases
... Break the code out into its own project ...
... and save it in your source code repository
That looks like it is more of a policy issue than anything you could really fix with code.
annotation: In CleanArchitecture in addition to the entities the Interactors contain (only application specific instead of enterpize wide) (validation) business logic as well.-> This leads me to further questions.What if an application specific validation logic that conceptually belongs to a specific entity needs to be executed in several Interactors/UseCases? To what kind of component (outside of any entity) should this piece of functionality be extracted in order to stay DRY and where would it reside in the (folder) structure? I really can't imagine that it would be another Interactor because .. why would you potentially do an unnecessary mapping of data onto InteractorRequestDTOs again? We are behind the application boundary already and the logic that we want to call doesn't need to be called from outside the boundary and in addition it isn't necessarily a separate UseCase(Flow/Story).Don't think that you are limited to the folder structure above. Every application is different and has different requirements. In this case, I might create a services folder (either at the root, or under the interactors folder) and put the validation logic there. But this could also be looked at as another use case itself.
And I don't see why a use case can't call another use case.
This question is more of a general nature: As for entities setters (and getters) for private data fields should be avoided where possible, I assume application specific validation logic for such an entity (that resides in the interactors or in the above mentioned components in question) should be executed before the state-changing behaviour _of_ (or _on_) the entity is initiated?..... that's another part that's kinda difficult to grasp: How to avoid setters on entity objects .. or let's say: when _application specific behaviour_ should be initiated, how do you implement behaviour affecting entities if it is not allowed to implement it for the (enterprize wide) entity object itself? Can it be done only by having some private field setters on the entity? .. Does the term "application specific _behaviour_" makes any sense then? .. Or can the term only be seen for a level as granular as to the Interactors but not any further (because using setters on the entities then would technically not be behaviour anymore)?I'm not entirely sure I'm following the question. The entities can be viewed as being only as restrictive as the domain requires. It should allow the maximum flexibility inherent to the domain. The application layer cannot make the domain more flexible than it already is, but it can make it more restrictive to address the use cases. If the entities need to be more flexible than they already are, then the models are now flawed in light of the new information and understanding, and need to be updated. This shouldn't be viewed as a bad thing as now you have increased your knowledge and understanding of the domain. The application specific validation logic should happen before modifying the entity. There may be side effects to modifying the entity like event triggering. When the entity is modified, It can fire an event off that other entities may be registered to be notified which in turn causes them to modify some state. That would be a real mess to try and undo. :) As for setters, I prefer using setters whether the fields are private or not. Its the perfect place to put validation logic.