I’m implementing a NestJS application following Clean Architecture principles. I want to validate if a user has access to a premium feature.
Here’s my current architecture:
Controller (Application Layer):
Validates user authentication using decorators.
Prepares input for the use case by creating a use case adapter.
Use Case Adapter: Performs basic validation on the input.
Use Case: Contains the business logic.
My goal:
I want to add validation to check if the user has access to a premium feature. Ideally, this validation should not clutter the controller or the use case with additional logic.
What I have considered:
Creating a custom decorator and using it in the controller for business rule validation.
Implementing a guard to handle the validation logic and using a service to encapsulate the actual validation checks.
eg: @PremiumFeature('can-create-more-than-10-posts')
But I think this will break the clean-architecture principles, As I am doing the business rule validation in the application layer.
1