In the process of developing and implementing a new service/API, sometimes the question arises regarding where to place the validation logic. I will attempt to provide a perspective on its placement and provide an example of its implementation in Clean Architecture using Java/Spring Boot, utilizing Exceptions (`jakarta`) and Non-Exceptions (`vavr`).
·
15 min read
·
Jul 10
106
4

Table of content
- Validation in context
- Test Driven Development (Contract-First approach)
- Organising Code
- Implementing a Use Case in Spring Boot
- Conclusions
This article covers various topics, but it will not delve extensively into subjects such as architecture, spring-boot exception handling, optimal library usage, TDD, or Contract First Testing. It assumes that you already have some knowledge about these topics or can refer to the resources provided at the end of the article for further information. The main focus of the article will be on validations, specifically addressing them within the context of Clean Architecture and Hexagonal Architecture.
Validation in context
The concept of “validation” is broad and ambiguous as it carries different interpretations depending on the context in which it is used. However, there is a common misconception that validation only serves a singular purpose. In reality, validation plays a role in various aspects. Similar to Clean Architecture, where responsibilities are divided into layers, each layer possesses its own validation logic.
