Android App Architecture Layers: UI, Domain and Data
When I was learning how to structure Android apps properly, I wrote a set of notes on each layer of the recommended app architecture. They ended up as three separate posts, so this page puts them together and shows how the layers fit.
The short version: an Android app is split into layers, and each layer has one job.
- The UI layer shows data on screen and handles what the user does.
- The domain layer holds business logic that several screens share. It is optional.
- The data layer owns the app's data and the rules for changing it.
Data flows up from the data layer to the UI, and events flow down from the UI to the data layer. Each layer only talks to the one next to it.
The UI layer
This is everything the user sees: your composables or views, plus the ViewModels that hold their state. The ideas that matter most here are separation of concerns, driving the UI from your data models, keeping a single source of truth, and unidirectional data flow. Dependencies between the layers are wired up with Hilt.
Read the notes: Android Clean Architecture: The UI Layer
The domain layer
The domain layer sits between the UI and data layers. Its classes are called use cases (or interactors), and each one does a single piece of business logic, such as combining data that more than one ViewModel needs. It is optional. Only add it when the logic gets complex or you find yourself repeating it.
Read the notes: Android Domain Layer: Use Cases in App Architecture
The data layer
The data layer is made of repositories, and each repository can use zero or more data sources (a network API, a database, a file). Other layers never touch a data source directly. They go through a repository, which exposes the data, centralises changes, resolves conflicts between sources and handles caching.
Read the notes: Android App Architecture: The Data Layer and Repository Pattern
Where to go next
My notes follow Google's own guide to app architecture, which goes deeper on each layer with code samples. If you are starting a new app, it is worth reading that guide once end to end, then coming back to these notes when you need a quick reminder.