Hurja Solutions Oy MVC-blogi kansikuva.

MVC for Dummies: Model, View and Controller architecture in web applications

An application developed by professionals is not just a random jumble of code, but is built around selected architectural patterns. Architecture helps to keep the application’s internal structure logical and facilitates its maintainability and further development.

Model-View-Controller (MVC) is a traditional software development design pattern, the primary purpose of which is to separate the application’s presentation and logic layers from one another and to delegate the application’s internal responsibilities to different components.

The original MVC architecture is over 40 years old, so over the years it has been joined by a wide variety of variations and other architectural patterns. Many web frameworks (e.g. Laravel, Django and Ruby on Rails) use either the MVC architecture directly or some variation of it. MVC is well suited to building REST interfaces, for example.

However, MVC – or any other internal application architecture – is not directly visible to the end user of the application, nor even to the service provider. In this blog post, we’ll explain in more detail what goes on beneath the surface of web applications.

The MVC architecture consists of three parts

The core principle of MVC has remained the same over the years: the software architecture is organized into three components, namely the Model, the View and the Controller. 

The Model, View and Controller interact with one another and are often interdependent, even though their functions are designed and implemented to some extent separately. The interdependence between these components means that, for example, a change in the Model may also require changes to the View. 

MVC in practice

MVC diagram.

The diagram shows a simple MVC model, which provides a natural basis for designing and building the system’s functionalities. The diagram omits the user interface layer’s own functions in order to illustrate the MVC architecture as simply as possible.

The core function of the application is data retrieval: the user retrieves all stored contact details from the database.

  • The model contains a description, written in a programming language, of what data relates to individuals (e.g. ID number, name) and how this data is retrieved from the database.
  • This view shows a list of people.  
  • The controller acts as a data conduit: it receives a request from the user, passes the request to the model, and ensures that the data returned by the model is passed on to the view. The controller does not make any changes to the database or the view, but acts solely as an intermediary. 

A model is an entity representing the system’s data content

A model is a dynamic data structure within the system that processes and stores data flowing through the software. Models that manage data are often linked to a data store that is essential to the software’s operation, such as a relational database.

A view provides a way of presenting data

A view presents data in a specified format, which may be, for example, an application’s user interface (HTML) or some other data representation format (e.g. JSON or XML). 

The concept of a view is used in web development on both the back-end and front-end sides. Traditionally, views have been HTML documents presented directly to the user, but nowadays views are mostly data intended to be processed by user interfaces.

The controller acts as an intermediary between the model and the view

The controller’s role is to receive commands and act in accordance with them, acting as a data transfer mechanism between the model and the view. In practice, this means that the controller retrieves, writes or deletes data via the model and finally returns a new view.

For example, in the back-end of web applications, the commands received by the controller are usually HTTP requests. Once the request has been processed, the controller returns the view as an HTTP response.

Software built using the MVC architecture forms a coherent whole

Although in MVC architecture the responsibilities of the software’s internal components are separated from one another and can also be built independently, the dependencies between the model, view and controller are always taken into account in software development. 

Further development of a well-designed and well-built application is subsequently easier, more efficient and faster. By taking the application’s architecture into account from the outset, resources are saved for the development of the actual features.

If you need expert application development services, please get in touch!

Shall we get started?

"*" indicates required fields

Name*
Hurja Solutions: Petteri Karppinen.