MVC (Model–View–Controller) is a design pattern that splits an application into three connected parts: the Model (data and business logic), the View (what the user sees) and the Controller (handles input and connects the two).
Diagram (flow):
User
| request / action
v
Controller ---- updates ----> Model
| |
| selects view | data
v v
View <-------- reads data ----
|
v response shown to user
- Model: holds the data and rules, talks to the database (e.g. a
Student model that saves and fetches students).
- View: the user interface (HTML page, template, React component) that displays data from the model.
- Controller: receives the user's request (e.g. a route in Express), calls the model to get or change data, and chooses which view to send back.
Advantages
- Separation of concerns: each part has one job, so code is cleaner.
- Parallel development: designers work on views while developers work on models and controllers.
- Reusability: one model can serve many views (web page, mobile app, API).
- Easier to test, debug and maintain, since changes in one layer rarely affect the others.
- Supports multiple views of the same data and scales well for large applications.