This section zooms in from the whole application to the inside of a single frontend feature. It focuses on separating display code, interaction state and the code that works with application data, so changes are safer and logic can be tested on its own.
The problem
When data, business rules and screen code are tangled together, a small display change can affect request handling or calculations, and testing one responsibility in isolation becomes harder. Separation of concerns groups code by its reasons to change rather than merely putting it in different files.
Presentation architectural patterns
Presentation architectural patterns organize the responsibilities behind a user interface:
- Displaying information
- Managing screen state and user actions
- Working with data and business rules
The three patterns below offer different ways to divide and connect those responsibilities so they can be changed and tested separately. They are not stages of maturity, and none is automatically better than the others.
Application data includes information such as products or account details. UI state describes the current screen interaction, such as a selected tab, an open menu or a loading indicator. These patterns help separate those responsibilities, but do not prescribe where every piece of state must live.
The examples below show each pattern within the frontend. The model represents the feature's application data and rules, not a database or backend service. It can work with a separate data-access module to call an API, but rules that require server authority still belong on the server. In the diagrams, arrows show which parts communicate, not code dependencies.
Model-View-Controller (MVC)
MVC became popular in server frameworks like Rails, Django and Spring MVC, then moved into the browser. On the server, a controller handles each request and returns a response. The browser can run the same roles too: the view stays on screen, and the controller handles each user action as it happens.
Splits code into three parts:
- Model: the feature's application data and rules, separate from its display code; it notifies observing views when its data changes
- View: what's shown on screen; it updates itself when the model notifies it
- Controller: the code that handles user actions and updates the model
The view forwards user input to the controller. The controller updates the model. When data changes, the model notifies any observing views, and each view updates itself. Where UI state lives varies by implementation.
Model-View-Presenter (MVP)
Splits code into three parts:
- Model: the feature's application data and rules, separate from its display code; it notifies the presenter when its data changes
- View: a passive view that forwards user actions and shows what it is told by the presenter
- Presenter: the code that coordinates screen behavior and decides what the view shows
The view forwards user actions to the presenter. The presenter coordinates screen behavior, changes or requests data from the model, receives results or change notifications, and decides what the view shows and tells it through the view's interface, instead of the view updating itself from model notifications. The passive view shown here does not communicate directly with the model.
Domain rules can remain outside the presenter, making them and the coordination logic easier to test without rendering a whole screen.
Model-View-View Model (MVVM)
Splits code into three parts:
- Model: the feature's application data and rules, separate from its display code; it notifies the view model when its data changes
- View: what's shown on screen; it sends commands and input to the view model and displays the state it is bound to
- View model: the code that exposes the screen's state and commands, without referencing a concrete view
The view model exposes screen state and commands. Views invoke those commands or send input updates; the view model works with the model and receives results or change notifications.
Data binding connects observable view model state to the display, so the screen stays in sync without the view model explicitly calling a view interface as a presenter does. Because that code lives in the framework, the view model stays free of view references. It only exposes state, and the framework's binding does the rest. In MVP, the presenter calls the view to update it. In MVVM, the view model exposes state, and binding implicitly updates the view.
Multiple views can use a view model, as illustrated here, but this is optional. Binding need not be two-way and does not decide which responsibility should own a rule. In all three patterns, views can still handle local presentation details such as focus and animation, even though another part owns the screen's logic.
Where these patterns live in modern frameworks
Today's frameworks are often built around components, and each provides the binding that MVVM relies on in its own way:
- Angular: change detection checks bound values and updates the template
- Vue: reactivity tracks the values a template reads and re-renders when they change
- Knockout: observables notify the bound DOM elements directly
Teams can separate request handling, interaction state and display using components and supporting modules; hooks or composables are framework mechanisms for extracting reusable logic. They do not automatically enforce that separation. A framework does not make the whole application one pattern; each feature can use whichever roles fit it.
You may encounter controller-like action handling, presenter-like screen coordination or view-model-like state and binding without the application formally adopting MVC, MVP or MVVM.
Trade-offs
| Architecture | What you gain | What it costs | When the distinction helps |
|---|---|---|---|
| MVC | Widely known from server frameworks; clear split between data, user actions and display | In the browser, controllers can reach into the view directly, and that coupling is hard to undo as features grow | Teams already familiar with MVC; features where these roles make change ownership clearer |
| MVP | Coordination logic can be tested without a screen through a view interface; the view stays passive and easy to swap | The presenter must update the view by hand, repeating that code across screens; shared update helpers then need maintaining across every presenter | Screens with substantial coordination logic, where testability matters most |
| MVVM | State-to-display binding reduces manual view updates and glue code; view model logic can be tested without a screen; maps well to modern frameworks | Binding makes updates harder to trace and debug in large screens | Form-heavy and interactive UIs with a useful screen-state model; Angular, and React or Vue with hooks or composables |
What this means for delivery
Clear responsibilities mean fewer regressions, business-rule changes without UI rework, and easier testing, which together make releases more predictable. A changed server contract may still require coordinated UI changes; separation does not remove that dependency.
Check your understanding
Quiz
Which MVC role handles user actions?
In MVC, a user clicks 'Add to cart'. Which role decides what that click changes?
Review questions and explanations (text alternative)
-
Which MVC role handles user actions?
In MVC, a user clicks 'Add to cart'. Which role decides what that click changes?
- Model
- View
- Controller
- None of the above
Suggested answer: Controller
The view forwards the user's input to the controller, which updates the model and coordinates view updates. The model holds application data and rules; the view displays them.
-
What tells an MVP screen to update?
In MVP, the model's data changes. What tells the screen to update?
- The model notifies the view directly, and the view updates itself without a separate layer.
- The view checks the model for changes on a timer, so its updates can arrive late.
- The model notifies the presenter, which tells the view what to show.
- The controller updates the view after each user action, so every input refreshes the screen.
Suggested answer: The model notifies the presenter, which tells the view what to show.
In MVP, the model notifies the presenter, which decides what the view shows and calls the view's interface. The view does not update itself from model notifications, and MVP has no controller.
-
Which pattern has views update themselves from model notifications?
When the data changes, the model notifies each observing view, and each view updates itself. Which pattern is this?
- MVC
- MVP
- MVVM
- None of the above
Suggested answer: MVC
In the observer variant of MVC, the model notifies observing views, and each view updates itself. MVP sends updates through the presenter, which calls the view's interface. MVVM exposes view model state for binding, so the framework updates the view rather than the view observing the model directly.
-
Which pattern lets binding update the view without the middle layer calling it?
A team wants the middle layer to expose screen state and have the view update automatically from it, so the middle layer never calls the view. Which pattern is this?
- MVC
- MVP
- MVVM
- None of the above
Suggested answer: MVVM
In MVVM, the view model exposes observable state and commands, and binding updates the view. In MVP, the presenter calls the view's interface to update it. MVC has no separate middle layer for the view to be bound to, so the view observes the model.
-
Who should coordinate the badge's loading and retry states?
In an MVVM frontend, a discount badge gets eligibility from a server policy and formats the result for display. It must now show pending, retrying and failed states as requests run. The team wants to test these transitions without drawing the badge. Where should that coordination live?
- In the badge template, alongside markup and currency formatting.
- In a view model that exposes state and commands to the view.
- In the server's discount policy, alongside authoritative eligibility rules.
- In the generic HTTP client, alongside request serialization and connection handling.
Suggested answer: In a view model that exposes state and commands to the view.
A view model exposes UI state and commands that can be tested without rendering. Putting coordination in the template ties its tests to rendering. The HTTP client handles transport. The server decides eligibility, but pending, retrying and failed states only exist in the browser while a request is in progress, so the server can't own them.
-
Which test isolates presenter coordination?
A presenter requests an account balance and tells a view interface to show a loading indicator, then a balance or an error. The team already tests the API separately. Which additional test checks the presenter's decisions without depending on page markup or a live server?
- Compare screenshots of the balance page against approved reference images, so any visual change is flagged.
- Send requests to the deployed balance endpoint and inspect its responses.
- Supply a fake data service and recording view; assert updates on success and failure.
- Compile the view's type declarations and check that every required method exists, so mismatches are caught early.
Suggested answer: Supply a fake data service and recording view; assert updates on success and failure.
A fake service and recording view interface test the presenter's loading, success and error decisions directly. Screenshots check appearance, API tests check the service, and compilation checks types rather than coordination behavior. Rendered behavior still needs separate coverage.
-
What does automatic data binding leave for the team to design?
An MVVM form uses data binding so changes in screen state appear in the view. A developer proposes putting request handling, eligibility rules and display formatting into that state object because binding will keep everything synchronized. What should the architecture review focus on?
- Rename the object to ViewModel; the pattern name establishes the separation between request handling, rules and display.
- Assign responsibilities and test their boundaries; binding only connects state to display.
- Bind every field before reviewing structure; synchronization will remove the coupling between request handling, rules and display.
- Switch to a component framework; components automatically isolate each kind of logic.
Suggested answer: Assign responsibilities and test their boundaries; binding only connects state to display.
Binding updates the view but does not assign ownership of rules or requests. Separate responsibilities by why they change and whether they can be tested independently. Renaming objects, adding bindings or switching to components does not automatically untangle dependencies.