1 of 8

MVC for JavaScript Web Applications

2 of 8

What is MVC?

MVC is a way to organize your backend code and it stands for…

Model: handles the data between the database and the server

View: handles the files used in rendering the data to the client/user

Controller: Receives the requests from the client/user through the browser and handles the core functionality in transferring data between the model(database) and the “view” files, giving this data back to the client/user.

MVC allows us to organize our backend structure to gives us great advantages as noted on the next slide…

3 of 8

Why use MVC for JS?

Pros

  • Modularity
  • Reusability
  • Organization
  • Group Programming
  • Compartmentalization
  • Targeted Testing
  • Faster Troubleshooting

Cons

  • MVC must have strict rules over methods (appropriate reactions from Controller)
  • May be complex to understand structure
  • Views may be overburdened from multiple requests and fall behind updating while rendering

4 of 8

Model

5 of 8

View

6 of 8

Controller

7 of 8

Here’s a diagram demonstrating the flow of data using MVC in JavaScript

Note: The Router is part of the Controller that further organizes the backend. It allows us to see exactly where our functions inside the Controller are located and shows us exactly what these functions do.

8 of 8

Thank you!

References: