A Beginner’s Explanation of MVC Architecture

Kelsey Creehan
3 min readFeb 16, 2021

--

Analogies are hard…and stage (view), backstage crew (controller), and director (model) might be the best I can do here!

MVC is a software architectural design pattern that was introduced in the 70’s. Websites were starting to evolve into much more complex applications, and to simplify working with these apps, developers started following various design patterns. MVC is one of the most utilized patterns today. Popular frameworks that use MVC concepts include Ruby on Rails, Express.js, and Django, just to name a few.

There are various ways to implement the MVC concepts, and since interpretation of the pattern can vary slightly, they don’t all look exactly the same. The main idea behind following an MVC pattern, however, is to organize the code in a way that emphasizes a separation of concerns or functionality.

MVC stands for Model-View-Controller, which are the three distinct parts of the app organization. Here’s the important role that each of the three parts play within an application.

  • Model: The model is responsible for managing the data’s structure as well as the rules or methods for how to access or manipulate it. The model is the brain of the application, and it interacts with the database if the application uses one, or something more simple like a json file. It’s in charge of queries and interacts with the controller, which requests data through the model. In some frameworks, the model can update the view directly, but in others, the controller is in charge of that aspect.
  • View: The view manages the presentation of the data it gets from the controller. It’s the user interface — what someone sees when they use the application. The view is usually a template file that dynamically renders HTML based on the information it gets from the controller. and communicates with the controller as well as the model.
  • Controller: The controller is in charge of interactions. It takes in user input from the view or an HTTP request and acts as a middleman between the model and the view. It never interacts directly with the database. The controller will ask the model to retrieve some data from a database, and then the controller passes the data to the view to render the data to the user.
A diagram is particularly useful in understanding this concept. Thanks, wikipedia!

An important note to keep in mind — the model and view don’t interact. Any interactions are done through the controller, separating the presentation of data and the logic data, which is ultimately meant to make working on complex applications much easier.

Thanks for reading! At the very least, I hope your understanding of MVC is not any worse than when you first started this two-minute read.

--

--