Overview
MVC is a software design pattern, which separates an application into three components: Model, View and Controller. It also describes the interactions between them.
Each component can be divided into smaller counterparts. In this case, they may be referred as Models, Views and Controllers.
MVC traditionally used for desktop graphical user interfaces (desktop GUIs). However, it is become pretty popular for developing web applications.
Most of the modern back-end web frameworks are built in MVC pattern.
Here's an illustration of an MVC web application:
- User uses a browser to send a request to the Controller.
-
Controller receives and processes the request.
- If the response doesn't need data from the database, it commands the View to show a proper response based on the request.
-
Else if the request needs data from the database, it sends a CRUD request to the Model.
- Model receives the request, and queries the database and sends back the result to the Controller.
- Controller processes the query result, and commands the View to show a proper response based on the query result.
- View receives the Controller's command, and sends an updated/rendered HTML file to the browser as the response.
- Browser shows the response to the user.
MVT Pattern
Some frameworks (such as Django or Flask), use a built-in Templating Engine to render the HTML view files. In such cases sometimes the MVC pattern may be referred as MVT.
The MVT (Model View Template) pattern is slightly different from MVC.
In MVT architecture, the framework itself takes care of the Controller component, the logic that controls the Model and the View and the interaction between them.
The Template which consists of HTML syntax plus a special templating syntax, describes how dynamic content would be inserted and pure HTML will be outputted.
Model
Model is the lowest part of the pattern, which is responsible for managing the data of the application. It receives the user request as a command (a CRUD request) via the controller.
It is the application's dynamic data structure, independent from the user interface.
Model can store data to the database. (Create)
Model can retrieve data from the database. (Read)
Model can modify the database. (Update and Delete)
View
View is the data which is meant to be shown to the end user.
It can be, any type of information such as texts, graphics, charts, diagrams, tables etc.
The view renders presentation of the model in a particular format.
Controller
Controller is the core component of the pattern. It is the application logic which accepts the user inputs and converts them into commands for the model and view.
The controller responds to the user input and performs interactions on the data model objects.
The controller may validate the user input, before passing it to the model.
Aurora MVC
Aurora framework is built on Flask. It means that you can use not only the built-in template engine comes with Flask, but also use MVC structure.
Using Aurora framework, you are able to use the MVC structure plus a templating engine, which will be discussed at the following.