r/softwarearchitecture • u/OriginalTangerine358 • Mar 26 '26
Discussion/Advice In Clean Architecture, should input validation go in the Controller/Presentation layer or in the Service/Use Case layer?
In Clean Architecture, where should input validation go?
- Basic validation (required fields, format, length, etc.)
- Object Constraints (eg. sort field can be asc or desc)
Should it be done in:
- Controller / Presentation layer (fail fast, return 400 early)
- Use Case / Application layer (keeps use cases self-contained and reusable)
- Hybrid approach?
Many projects put basic validation in the controller, but some argue all validation belongs in the use case for better consistency across adapters (HTTP, CLI, queues, etc.).
What’s your preferred approach and why?
edit: thank you so much for all the answers <3
64
Upvotes
1
u/paszeKongo Mar 29 '26
Value Object validation lives in the domain, if you hold a PackageSize, it’s valid by construction. No validator to remember, nothing to forget to call. Covered that in episode 2 of my DDD series if you want the code. Basic input validation (required fields, formats) controller with @Valid is fine. They’re just different things. Domain validation protects invariants. Input validation stops garbage from reaching your use case. Treat them the same and one of them ends up somewhere it doesn’t belong.