skip to content

Client Architecture

Structuring a large app as layers over one source of truth and feature modules with scoped dependencies, with screens the OS can kill and rebuild. Interviewers ask if it survives many teams.

on this pageshow

explore

questions

22

In a mobile app's design, what do the presentation, domain and data layers each own, and what crosses the boundaries between them?

level: juniorimportance: must knowfreq 55%

answer

  1. three jobs: show, decide, fetch
  2. screens render state, send actions down
  3. domain layer is optional
  4. data layer hides server and disk
  5. map wire models at the data edge

basics

~20 s

The 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 s

In 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

for a junior

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.

for a middle

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.

for a senior

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.

for a principal

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".
open as a page

In a mobile app's design, what do the foreground, background, suspended and terminated states mean, and what can the app rely on in each?

level: juniorimportance: must knowfreq 58%

basics

~20 s

Foreground: visible and interactive, with priority on CPU and memory. Background: off screen, briefly running, expected to save and go quiet. Suspended: in memory but not running, killable without notice. Terminated: no process; only saved UI state and disk remain.

open as a page

In an offline-capable mobile workout app, how should a repository arbitrate between the server and the local store as the single source of truth?

level: middleimportance: must knowfreq 60%

basics

~20 s

Make the local store the source of truth: screens observe the repository, which reads from the store, and server responses are written into the store and reach the screen only through it. Offline, the screen keeps working from what is stored.

open as a page

In a mobile loan-application form, which state belongs in memory, which in small saved UI state and which on disk, and why?

level: middleimportance: must knowfreq 66%

basics

~20 s

Memory holds the loaded screen state; it survives a UI rebuild but not process death. Small saved UI state holds the draft's identifier and step index needed to rebuild. Disk holds the draft and the ID photo, which must survive everything.

open as a page

In a modularized mobile app, why should one feature depend only on another feature's API module rather than on its implementation module?

level: middleimportance: must knowfreq 40%

basics

~20 s

An API module holds only a small, stable contract; the implementation module holds everything behind it. Depending on the API means implementation edits do not recompile other features, internals stay hidden, and the app module picks the implementation.

open as a page

In a 60-engineer mobile super-app (ride-hailing, food delivery and a wallet in one binary), a one-line change takes minutes to build incrementally: how do you diagnose the module graph, and which dependency rules do you enforce?

level: seniorimportance: must knowfreq 38%

basics

~20 s

Measure which modules rebuild for typical changes and find the hubs: a grab-bag common module, features wired to each other's implementations, re-exported dependencies. Split them, put API modules between features, and enforce acyclic, API-only edges with a failing build check.

open as a page

In a large mobile app's design, what do the app module, feature modules and core modules each hold, and which way may dependencies point?

level: juniorimportance: should knowfreq 33%

basics

~20 s

Feature modules hold one user-facing flow; core modules hold code many features reuse, such as UI components, networking and a domain's data; the app module is the entry point that assembles them. Dependencies point app to feature to core, never upward.

open as a page

In a mobile app's design, what does it mean to model navigation as state, a stack of routes, and what does it make possible?

level: juniorimportance: should knowfreq 38%

basics

~20 s

Navigation becomes an ordered stack of routes, each a destination name plus small arguments such as a listing ID, start destination at the bottom, visible screen on top. As plain data, it can be built, checked and saved by any entry point.

open as a page

In a mobile app with one-way data flow, how should a workout screen's state represent loading, stored content and a failed refresh at once?

level: middleimportance: should knowfreq 45%

basics

~20 s

Expose one immutable screen state, rebuilt from the repository's stream, with content, a refreshing flag and an error as fields that can be true together; the screen renders it and sends user actions up, never editing its own copy.

open as a page

In a layered mobile app, which layer should move store, network and heavy work off the UI thread, and why not the screen?

level: middleimportance: should knowfreq 40%

basics

~20 s

The layer that does the blocking work, data sources, repositories and any heavy use case, moves it off the UI thread itself, so every call is safe from the UI thread and screens never manage threads.

open as a page

For a mobile loan-application app, how should restoring the user's place differ after an OS kill, a user swipe-away, and a return hours later with an expired session?

level: middleimportance: should knowfreq 40%

basics

~20 s

After an OS kill, restore exactly where the user was. After a swipe-away, start fresh and offer the saved draft. After hours away, still return them to their place, but put sign-in first if the session expired and refresh time-sensitive data.

open as a page

In a second-hand marketplace mobile app, how should a tap on an 'offer received' notification become a screen stack the app can trust?

level: middleimportance: should knowfreq 40%

basics

~20 s

Treat the tap as one more entry point: the payload names a route with offer, listing and recipient-account IDs, the link resolver builds the stack, and the screen loads the offer's current state, not the notification's copy.

open as a page

In a mobile workout app where both the view model and the repository decide whether cached data is fresh, history charts stay stale after a sync; where should that decision live?

level: seniorimportance: should knowfreq 50%

basics

~20 s

In the repository. It owns the store and the server, so it alone knows what is stored and when it was fetched; screens observe its data and may ask for a forced refresh, but never judge freshness themselves.

open as a page

In a mobile workout app, when does a use-case layer between the screens and the repositories pay for itself, and when is it ceremony?

level: seniorimportance: should knowfreq 45%

basics

~20 s

A use case pays when a rule is reused by several screens, combines several repositories, or deserves its own tests, such as personal-record detection; a use case that only forwards one repository call is ceremony.

open as a page

A loan-application app is killed in the background while the user photographs their ID at step four, and they return to an empty step one. What went wrong, and what fixes it?

level: seniorimportance: should knowfreq 60%

basics

~20 s

The draft, step and pending photo lived only in memory, so process death wiped them. Persist the draft on disk, keep its identifier, the route stack and the photo's target file in saved UI state, and rebuild from them.

open as a page

A loan-application app is killed seconds after the user taps submit, before any response arrives. On relaunch, how should it decide whether to resume, resubmit or show the result?

level: seniorimportance: should knowfreq 47%

basics

~20 s

Before sending, persist a submission record holding a client-generated application identifier and a sending status. On relaunch, sending means the outcome is unknown: ask the server about that identifier, or resend reusing it, never with a new one.

open as a page

In a mobile app's dependency-injection design, how do app, session and screen scopes map onto modules, and what must happen to session-scoped objects at logout or account switch?

level: seniorimportance: should knowfreq 34%

basics

~20 s

The app module, as composition root, builds an app scope for process-wide objects, a session scope opened at sign-in for anything tied to one user, and screen scopes. Logout or account switch destroys the session scope whole.

open as a page

In a modular second-hand marketplace mobile app, how should the listing feature open checkout without importing the checkout feature's screen?

level: seniorimportance: should knowfreq 28%

basics

~20 s

Through a route contract: checkout publishes a small route type, checkout with a listing ID, in a contract module both features depend on, and the app shell maps routes to screens. Features exchange IDs, never screens or objects.

open as a page

As the lead of a mobile app growing from one team to eight, how do you decide when to modularize, how fine-grained to go, and who owns each module?

level: principalimportance: should knowfreq 26%

basics

~20 s

Modularize when build time, merge friction or unclear ownership cost more than module overhead, rarely the case for one small team on an early product. Cut where what changes together meets who changes it; give each module one owning team.

open as a page