In web development, there is no rule to organize your work, you could do whatever you want. Many web frameworks give you only necessary tools to create routes and a template engine to design and insert data into HTML page. If you want to completely have the control on your web application, micro web framework is a good choice for you.

 

However, traditionally, there is a design pattern that web developers like to follow; it is the MVC Design Pattern. MVC stands for Model, View, and Controller. It represents the flow of control in web application. We have to bare in mind that MVC is not a rule, it is only a preference.

 

 

According to the MVC Design Pattern, when a visitor makes a request through an url or a route, web developer needs to create a callable object that is a function or a class in the “Controller” section to response to this request. But, before responding to the request, the callable object in the controller section calls another callable object in the “Model” section to pull or put data into the database following the request. Very often, there are two kinds of request - the request to pull data from the database is called get request, and the request to put data into the database is called post request.

 

After the callable object in the model section finished putting/pulling data into/from the database, the callable object in the controller section will send necessary data to the “View” section to use template engine to design and insert that data into an HTML page in order to send it as a response to the visitor.

 

In practice, we can create three different folders to represent Controller, Model, and View sections.