How do you handle cross-cutting concerns (like logging) in CA?
Updated Apr 28, 2026
Short answer
Cross-cutting concerns are handled via decorators, middleware, or dependency inversion of infrastructure interfaces.
Deep explanation
Concerns like logging, security, and caching shouldn't clutter the core business logic. In Clean Architecture, we define an interface in the domain/use-case layer for the concern. The implementation lives in the infrastructure layer. Alternatively, patterns like Decorator can wrap Use Cases to add logging without modifying the Use Case itself.
Real-world example
An authentication check middleware that runs before the Use Case is even called.
Common mistakes
- Hard-coding 'console.log' or a specific logging library inside an Entity.
Follow-up questions
- Where should error handling live?