MVC (Model-View-Controller) is an architectural pattern that splits an application into three parts: the model, which holds data and business rules; the view, which presents data to the user; and the controller, which receives input and coordinates the other two.
Why it matters
Separating these responsibilities makes code easier to test and change. A designer can rework a view without touching business logic, and the same model can serve a web page, an API and a command-line tool. MVC is the basis of frameworks such as Ruby on Rails, Django (which calls it MVT), ASP.NET MVC and Laravel. Variants like MVP and MVVM adapt the idea to user interface frameworks.
Example
A request to /sites/42 in a typical web framework:
- The router sends it to
SitesController.show. - The controller asks the
Sitemodel for record 42. - The controller passes the record to the
showview template. - The view renders HTML, which is returned to the browser.
Common mistakes
- Putting business logic in controllers ("fat controller") or in views.
- Letting the view query the database directly.
- Assuming every framework defines MVC the same way; the exact roles differ.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.