I make use of an AngularJS style guide. Within this guide there is a style called folder-by-feature
, instead of folder-by-type
, and I'm actually curious what's the best approach (in this example for Java)
Let's say I have an application where I can retrieve Users & Pets, using services, controllers, repositories and ofcourse domain objects.
Taking the folder-by-..... styles, we have two options for our packaging structure:
1. Folder-by-type
com.example
├── domain
│ ├── User.java
│ └── Pet.java
├── controllers
│ ├── UserController.java
│ └── PetController.java
├── repositories
│ ├── UserRepository.java
│ └── PetRepository.java
├── services
│ ├── UserService.java
│ └── PetService.java
│ // and everything else in the project
└── MyApplication.java
2. Folder-by-feature
com.example
├── pet
│ ├── Pet.java
│ ├── PetController.java
│ ├── PetRepository.java
│ └── PetService.java
├── user
│ ├── User.java
│ ├── UserController.java
│ ├── UserRepository.java
│ └── UserService.java
│ // and everything else in the project
└── MyApplication.java
What would be a good approach, and what are the arguments to do so?
Pet
, the controller, the repository, and the service. In what situation would I ever need all controllers, but non of the views, repos or services?