Client App Architecture

Topics Covered

Layered Architecture

Why layers at all

The four layers

Rules between layers

Mapping a screen onto the layers

Where platform specifics appear

Sharing layers across platforms

What the interviewer is checking

Common layering mistakes

Step 2 of the framework is the client architecture. This is where you draw the boxes inside the app and explain how data moves between them. Interviewers are not looking for a specific pattern name. They are looking for clear responsibilities, a direction of data flow they can follow, a single place where each piece of data lives, and seams that make the app testable and easy to change by many engineers at once. This lesson covers the patterns that deliver those properties on both platforms: layers, unidirectional data flow, repositories and a single source of truth, modules, dependency injection, navigation, concurrency and testing.

Why layers at all

A small app can live in a handful of screens that fetch data and draw it. That stops working once the app has offline support, several screens showing the same data, background sync, many engineers and years of changes. Layers separate code that changes for different reasons. Screens change when the design changes. Business rules change when the product changes. Data access changes when the API or storage changes. Keeping them apart means a redesign does not touch sync logic and a new API version does not touch screens.

Both platforms' official guidance converges on roughly the same shape, and it is a safe default to draw in an interview.

The four layers

The UI layer renders state and captures user input. On Android this is usually Jetpack Compose; on iOS it is usually SwiftUI, with UIKit on iOS and the View system on Android still present in older code and for some complex components. The UI layer should contain no business logic and no data access. It reads a state object and sends events.

The presentation layer holds the state for a screen and turns user events into actions. On Android this is a ViewModel exposing a StateFlow. On iOS it is commonly an Observable class, often called a view model or a store, marked to run on the main actor. It survives configuration changes on Android and outlives individual view redraws on both platforms.

The domain layer is optional. It holds use cases: small classes that encode a business rule that spans repositories or is reused by several screens, such as follow a user, which might check the account is not blocked, write the follow, update counts and schedule a sync. Many apps skip this layer for simple screens and let the view model talk to repositories directly. Say in the interview that you would add use cases where logic is shared or complex, not everywhere by default.

The data layer holds repositories and the data sources beneath them: the local database, the network client, key value preferences, files and platform services such as location. Repositories expose data to the layers above and hide where it comes from.

Events flow down through the layers and state flows back up, each layer talking only to its neighbour.

Rules between layers

Three rules make the layering pay off.

Dependencies point downward. The UI knows about the presentation layer; the presentation layer knows about the domain or data layer; the data layer knows nothing about screens. A repository never imports a view.

Each layer talks to its neighbour. A screen never calls the network client directly, even for something small, because that one shortcut bypasses the cache, the error handling and the offline story.

Data crosses boundaries as plain models. The network layer has its own response types, the database has its own entity types and the UI may have display models. Mapping between them costs a little code but means a renamed API field changes one mapper, not twenty screens. It also protects the UI from optional and unknown fields that exist for old versions.

Mapping a screen onto the layers

Take a profile screen that shows a user's details, their recent posts and a follow button.

The UI layer draws the header, the grid and the button from a ProfileState. It sends events: follow tapped, post tapped, pull to refresh.

The view model holds ProfileState, which contains the user, the posts, the follow status and whether a refresh is running. On init it observes the user and posts from repositories. On follow tapped it calls the follow use case and lets the observed data update the state.

The follow use case checks rules and calls the relationship repository, which writes to the local database and adds a pending operation to the outbox. A sync worker sends it later.

The user repository and the post repository read from the local database and refresh from the network when asked.

That mapping takes about a minute to describe, and every later question, such as what happens if the follow fails or how the posts page in, has an obvious home.

Where platform specifics appear

The layers are platform neutral, but the tools differ. On Android, Room provides the local database with observable queries, Retrofit or Ktor over OkHttp provides the network client, DataStore holds small preferences and WorkManager runs the sync worker. On iOS, SwiftData or Core Data or a SQLite library such as GRDB provides the local database, URLSession provides the network client, UserDefaults holds small preferences and BGTaskScheduler plus background URLSession handle background work. Naming one or two of these after you describe the responsibility is enough; the interviewer wants the shape first.

Sharing layers across platforms

If the company builds both apps, the interviewer may ask whether to share code. Kotlin Multiplatform is now a mainstream choice for sharing the data and domain layers, sometimes the presentation layer too, while keeping native UI on each platform; Compose Multiplatform can also share UI, including on iOS. React Native and Flutter share almost everything, including UI, at the cost of a separate rendering or bridging layer and a dependency on that framework's ecosystem. A balanced answer: sharing the data and domain layers gives most of the benefit for logic heavy apps, such as sync rules and validation, while native UI keeps each platform's feel and accessibility behaviour. The layered architecture is what makes that split possible at all, because the shared layers have no knowledge of screens.

What the interviewer is checking

When you draw the layers, the interviewer checks whether each box has one clear job, whether you can say where a given piece of logic would go, and whether the layering serves the requirements rather than being decoration. Tie it back: the data layer owns the local database because the app must work offline; the presentation layer holds state because screens are recreated on rotation and on process restore; use cases exist only for follow and post creation because those rules are shared.

Common layering mistakes

A few mistakes show up again and again, both in interviews and in real apps. The first is the god view model: one view model per screen that also fetches from the network, parses JSON, writes to the database and formats strings, so the layers exist only as file names. The fix is to push data access into repositories and keep the view model to state and event handling.

The second is leaking platform types downward. A repository that takes an Android Context or a UIKit view controller as a parameter is tied to the UI and cannot be tested or shared across platforms. Data layer code should depend only on abstractions it owns, such as a clock, a file store or a network client interface.

The third is an anaemic domain layer: a use case for every single repository call, each one a one line pass through. It adds files and indirection without adding rules. Use cases should earn their place by holding logic.

The fourth is letting the layers be bypassed for convenience, such as a widget extension or a notification handler that reads the network directly because it was quicker to write. Those entry points then show different data from the app. Widgets, notification extensions, watch apps and background workers should go through the same data layer, or read from the same shared database, so the whole product agrees on what is true.

Describe responsibilities, then name tools

Draw boxes for UI, presentation, an optional domain layer and data, describe what each owns, and only then name the platform tools such as Compose and Room or SwiftUI and SwiftData. The interviewer is grading the shape first.