- OpsFlow Newsletter
- Posts
- Clean architecture and system boundaries
Clean architecture and system boundaries
3 things I’ve learned about clean architecture
As I spend more time in the .NET community, I've been gaining increasing exposure to Clean Architecture. I love how it lays out responsibilities between layers and provides a framework for structuring software.
But one thing kept nagging at me.
Are client apps like web apps running in browsers or mobile apps on phones part of Clean Architecture's presentation layer, or something else entirely?
Working through this question not only deepened my understanding of the Clean Architecture but also broadened my understanding of system architecture.
Here's what I learned.
Client apps aren't the presentation layer.
In Clean Architecture, layers are defined per system.
The definition of what a “system” is in software architecture is quite ambiguous.
After some research, I have come to define a system as an independently deployable piece of software that fulfils a distinct purpose and has a clear boundary separating it from the outside world.
So the backend is a system, and the clean architecture defines its structure.
The presentation layer is the interface that presents data to the outside world within that system.
Since client apps and backend APIs are independently deployable units, and client apps clearly sit outside the backend API's boundary, they aren't part of the backend's presentation layer.
For a backend system, the presentation layer consists of REST controllers, GraphQL resolvers, or gRPC endpoints. That's where the backend's Clean Architecture ends.
Backend services aren’t only systems in a product.
I'd been thinking of backend services that run in the cloud as systems. But I hadn't given much thought to client apps like mobile or web apps in the same way.
If client apps aren't part of the presentation layer, what are they?
Given that a system is an independently deployable piece of software, client apps are systems in their own right.
A mobile app is a system.
A web app is a system.
Just like a backend API, a database, or a payment gateway microservice is a system.
Client apps can benefit from clean architecture.
Since a mobile app is as much a software system as a backend system, the same architectural patterns can apply.
Maybe Clean Architecture isn't the best fit for every client app. Something like MVVM might be more appropriate.
But I can still see how concepts from Clean Architecture could benefit frontend applications.
E.g., a layered structure like:
Presentation Layer: UI components and screens that render the interface
Application Layer: Use cases that orchestrate frontend business logic
Domain Layer: Client-side business rules
Infrastructure Layer: API clients, local storage, browser APIs, external services
The presentation layer of the backend ends with the API, and client apps are independent systems that are not just views for the backend.
As systems with their own complexity, I think client apps deserve the same architectural consideration we give to backend systems.