The basic purpose of clean architecture is to make clear the intention of what the application does and how it does it.
That is why these two things need to be separated.
Package | Intent |
---|---|
core | Should only need to look inside this package to know what the system does. Has no dependencies to any framework (e.g. Spring, hibernate, play, drop wizard…) |
core > domain | Entities and value objects |
core > usecase | The use cases (or application services) |
core > boundary | The only way into and out of the core. Contains only interfaces. |
core > boundary > enter | Interfaces that the core > usecase implements. These are used in the adapter (can also be used in the periphery). |
core > boundary > exit | Interfaces used by the core > usecase. These are implemented in the periphery (e.g. repositories). |
Module | Intent |
---|---|
adapter | Converts the domain objects returned by the uses cases into the appropriate format (e.g. DTO’s) for use in the periphery |
periphery | Anything framework related (e.g. repositories, controllers) |
configuration | How the application is glued together (e.g. spring @Configuration classes) |
Note: This example app uses Immutables, hence the need to enable annotation processing
In IntelliJ:
- File > Settings > Build > Compiler > Annotation Processors
- Tick Enable Annotation Processing and select Module content root
- Build the project via Build > Build Project
- In application > core module right click on generated folder and Mark directory as > Generated Sources Root
On the command line in the clean-architecture-example folder type gradlew bootRun
Application URL: http://localhost:13001
URL: http://localhost:13001/swagger-ui.html
To see the Swagger documentation in read-only mode run the application with production profile
On windows: gradlew bootRun -Dspring.profiles.active=production
On linux: SPRING_PROFILES_ACTIVE=production ./gradlew bootRun