MVC - 3 Tier Architecture
August 11, 2012
MVC is a popular software architecture pattern that uniquely suits web applications but has been used in other types of software systems as well.
MVC (Model, View, Controller) is an architecture pattern. it is a guideline for how a software system's architecture can be designed. The basic idea is that the whole application should be divided into 3 layers. The first layer (Model) should contain the data-storage and data processing i.e. algorithms. The third (View) layer should be the UI through which users will interact with the system. The middle or the second layer (Controller) should do data translation between the first and the third layer.
The MVC architecture is uniquely suited to web applications. Several web development frameworks including Ruby on Rails have adopted MVC architecture. In web applications, the three layers map to:
Model - Database or Models containing business logic.
Controller - handles incoming web request, queries model and renders the appropriate view.
Views - contain the HTML, CSS and Javascript for rendering the pages for the user.
Note that, end users interact using only views which get rendered on the browser. User data resides only in the model layer. The main advantage of such a set up is:
The MVC architecture is uniquely suited to web applications. Several web development frameworks including Ruby on Rails have adopted MVC architecture. In web applications, the three layers map to:
Model - Database or Models containing business logic.
Controller - handles incoming web request, queries model and renders the appropriate view.
Views - contain the HTML, CSS and Javascript for rendering the pages for the user.
Note that, end users interact using only views which get rendered on the browser. User data resides only in the model layer. The main advantage of such a set up is:
- Since the data is only stored in the model layer, it is straightforward to scale the application by deploying multiple application servers. Scaling the system is then reduced to scaling the database which is a much more contained and a better understood problem.
- It is possible for different programs, other than the web applications, to talk to the same model. For example, you can have a mobile application or data analysis or batch processing program running over the same model layer without breaking the web application.
- Since all the business logic is concentrated in the model, it is simpler to test them since no UI need to be involved. Rails even has a specific mantra called "Fat model, skinny controller" to emphasis the fact that business logic should be concentrated in the model layer.