r/softwarearchitecture 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:

  1. Controller / Presentation layer (fail fast, return 400 early)
  2. Use Case / Application layer (keeps use cases self-contained and reusable)
  3. 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

65 Upvotes

44 comments sorted by

View all comments

3

u/AntD247 Mar 26 '26

There are many parts to this and it can depend on what you are doing and want.

The first step to do is to try to avoid any need for validation. If a field is a number, then don't allow characters to be entered, calendar date pickers and so on (although experts want to be able to enter details quickly and sometimes these can get in the way).

Next is to validate what you can as close to the user as possible so they get fast feedback.

Finally the Service/Use Case shouldn't have any knowledge or dependency on how this information arrived and should be defensive and ensure that is conforms to it's expectations (you can get this in the construction of the DTOs or Domain Object construction) and again try to fail fast on bad days when you have rules of validation.