The recommended structure.
WHAT THE RECOMMENDED LAYERS ARE
The interface layer: displaying state and sending events
The domain layer, optionally: business logic
The data layer: repositories and data sources
WHAT A VIEW MODEL DOES
Holds interface state, surviving configuration changes.
WHY THAT MATTERS
State held there is not lost on rotation.
WHAT IT MUST NOT HOLD
References to views or activities.
WHY
It outlives them, and holding a reference leaks memory.
WHAT OBSERVABLE STATE PROVIDES
The interface updating automatically when data changes.
WHAT A REPOSITORY DOES
Provides data, deciding between local and remote sources.
WHY THAT MATTERS
The interface does not know or care where data came from.
WHAT LOCAL PERSISTENCE PROVIDES
A database with compile-time verified queries.
WHAT BACKGROUND WORK SCHEDULING PROVIDES
Deferred work that survives restarts and respects system constraints.
WHAT TO USE IT FOR
Uploads, synchronisation, and anything that must eventually happen.
WHAT TO AVOID
Business logic in activities Data access from the interface layer