In a mobile app's design, what do the presentation, domain and data layers each own, and what crosses the boundaries between them?
answer
- three jobs: show, decide, fetch
- screens render state, send actions down
- domain layer is optional
- data layer hides server and disk
- map wire models at the data edge
basics
~20 sThe presentation layer turns state into screens and taps into calls; an optional domain layer holds rules several screens share; the data layer owns server and disk behind repositories. Only app models cross, never wire formats or table rows.
solid answer
~50 sIn a workout-tracking app, the **presentation layer** is each screen plus its state holder (a view model or equivalent): it renders today's plan from a state object and turns a "log set" tap into a call downward, and it never touches the network or the store. The **data layer** owns where data comes from: repositories expose plans, sets and history, and behind them sit data sources for the local store and the server API. An optional **domain layer** of use cases sits between when a rule is shared, such as detecting a personal record on both the logging and the history screens. What crosses each boundary matters most: the data layer maps the server's JSON and the store's rows into the app's own models (`WorkoutSet`, `Plan`), so a renamed API field touches one mapper instead of every screen.
go deeper
Recall the three layers and one job for each, and say that the domain layer is optional. Use the app in front of you for examples rather than abstract boxes.
Explain what crosses each boundary: wire and storage models stop at the data layer, app models go up, user actions come down. Show why mapping at the data edge contains server changes.
Show the layering paying off under pressure: offline mode without touching screens, a server field rename confined to one mapper, a redesign that leaves repositories alone. Name the pass-through layer as a cost.
Frame the split as a team contract: the app models are the interface between people working on screens and people working on data, so agree them first and keep them stable while each side changes.
## Three layers, three jobs A **layer** in a mobile client is a group of classes with one kind of responsibility and a rule about what it may call. Common mobile architecture guidance describes two core layers and one optional one. Take a workout-tracking app with a "today's plan" screen, a set logger used in a gym basement with no signal, a history screen with progress charts, and sync with a server. | Layer | Owns | Must not hold | In the workout app | |---|---|---|---| | **Presentation** | Screens, their state holders, display formatting, user actions | Network calls, store queries, business rules shared by screens | The plan screen and its view model, the chart drawing code | | **Domain** (optional) | Use cases: business rules reused by several screens or combining several repositories | Screen state, network or storage details | "Is this set a personal record?" | | **Data** | Repositories and data sources for the server and the local store, mapping, the source of truth | Anything about how a screen looks | `PlanRepository`, `SetRepository`, the API client, the store's tables | The domain layer is **recommended, not required**: when a rule is used by one screen and is simple, the presentation layer calls the repository directly. ## What crosses each boundary The boundaries are where most layering bugs live, so be explicit about what travels across them: - **Server to data layer:** the API's JSON, with its own field names, units and date formats. It stops here. - **Store to data layer:** table rows or documents shaped for storage and indexing. They stop here too. - **Data layer upward:** the app's own models, such as `WorkoutSet(exercise, weightKg, reps, loggedAt)`, trimmed to what the app needs and immutable, so no caller can change them behind the owner's back. - **Presentation layer to screen:** a screen state built from those models, with display strings like "82.5 kg" and flags like "refreshing". - **Screen downward:** user actions only, such as "log set", "retry" or "pull to refresh", as calls on the state holder. Mapping at the data edge is the cheapest insurance in the design. When the server renames `wt` to `weight` or starts sending pounds for some users, one mapper changes; no screen notices. ## Why split a client this way - **Replaceable sources.** The screen does not know whether the plan came from disk or from the server, which is exactly what lets the app work offline. - **Testable rules.** A use case or repository can be tested with fake data sources and no UI at all. - **Parallel work.** Once the app model is agreed, one engineer builds the API mapping while another builds the screen. - **Smaller blast radius.** A server contract change, a storage migration or a redesign of one screen each stays inside one layer. ## A tap's round trip Following one action through the layers shows the split in motion: 1. The user taps "log set" on the plan screen. 2. The screen calls the state holder with the action; it does not change its own list. 3. The state holder calls the set repository (or a use case, if a shared rule applies first). 4. The repository records the set in the local store. Getting it to the server later is the sync design's job. 5. The store reports the change, the repository's observable data updates, and the state holder builds a new screen state. 6. The screen renders the new state, and the set appears. Data and state come back up the same way every time, which is what keeps the picture predictable. ## Mistakes interviewers listen for - A screen or state holder that calls the server API directly "because it is simpler": now offline mode and caching have to be solved again in every screen. - The server's response model passed all the way to the screen, so every field rename becomes a UI bug. - A use case for every repository method, each one only forwarding a call: extra files with no new behaviour. - Display formatting in the data layer, which then returns strings a chart cannot plot. - Treating layers as folder names. Layering is a rule about **what each class may call and what it may hand back**, not where the file sits. A junior answer names the three layers; a good answer also says what crosses each boundary and why the mapping happens at the data edge.
- Is a domain layer of use cases mandatory in a layered mobile app?No. Common guidance treats it as optional: add it when a rule is complex or reused by several screens, or when it combines data from several repositories. When a screen only needs one repository call, the presentation layer calls the repository directly; wrapping that call in a use case adds a class and a test with no new behaviour.
- Why not pass the server's JSON model straight to the screen, since it already has every field?Because the screen then depends on the wire format. A renamed field, a new nullable value or a unit change breaks screens instead of one mapper. Mapping at the data layer also trims the model to what the app uses and converts types, such as timestamps into dates, once for every caller.
- The screen can call the server API directly to save a layer.
- Every app needs a use case for each repository method.
- The server's response model can travel unchanged up to the UI.
- Layering is about folder names, not about what each class may call.
- The data layer should return display-ready strings such as "82.5 kg".