I'm trying to group the components of my system by funtionality. This is the analysis class diagram of my system model.
A service class that involves a Post
entity might necessarily interact sometimes with Section
, User
, or also (to a lesser degree) PostVote
. This also applies with the repository classes of each entity of course.
As an example, here's my PostService#newPost
method:
@AuthenticationRequired //auth interceptor
public int newPost(@NotBlank String title,
@Size(max=65535) String body,
@NotNull String sectionName){
//currentUser is an authentication related DTO
User user = userRepository.findById(currentUser.getUsername());
Section section = sectionRepository.findByNaturalId(sectionName);
if(section == null)
throw new SectionDoesntExistException();
Post post = new Post();
post.setTitle(title);
post.setContent(body == null || body.isBlank() ? "" : body);
post.setAuthor(user);
post.setSection(section);
post.setType(TEXT);
return postRepository.insert(post).getId();
}
The SectionRepository
class is an included dependency that is used only to check for the Section existance and to get a managed entity. This happens in a lot of other places in my code base.
I could try of course to move this retrieval logic in PostRepository
(the insert
method calls SectionRepository#findByNaturalId
and fails if none found), but this wouldn't answer my question: should the entities and/or its repositories be included in the package that outlines the vertical slice in my system in the first place? Or should they be put in a common entity
and repository
bucket that sits underneath all vertical slices in my system architecture?
The reason I'm asking this is that many see these vertical slices as independent codebases with minimal dependencies with peer subsystems. Introducing the entities in these package may add inevitably some dependencies.
What's the common practice for this kind of architectural pattern?