MVC stands for Model–View–Controller, a software architecture pattern that separates an application into three main components.
Model
What it is
The Model represents the data and the business logic of the application.
Responsibilities
Defines how data is structured (for example, database tables or classes).
Manages data access, storage, and validation.
Contains rules for how data can be created, updated, or deleted.
Example
In a blog app, the Post model defines what a post is — title, body, author, timestamps — and how it interacts with the database.
View
What it is
The View handles the presentation layer — what the user actually sees and interacts with in the browser.
Responsibilities
Displays data from the Model in a user-friendly way.
Contains HTML, CSS, and sometimes templating logic.
Should avoid business logic — just show the data.
Example
In the blog app, a PostView might be an HTML template that loops through all posts and displays their titles and bodies.
Controller
What it is
The Controller acts as the middleman between the Model and the View.
Responsibilities
Handles user input (like form submissions, button clicks, or URL requests).
Calls the appropriate Model methods to fetch or update data.
Chooses which View to render and sends it the needed data.
Example
In the blog app, a PostController might handle:
/posts → get all posts from the Post model and show them in the view.
/posts/new → render a form for creating a post.
/posts/create → save a new post to the database.
The flow looks like this:
[User] → [Controller] → [Model] → [View] → [User]
The user requests a page (clicks or submits a form).
The controller decides what to do and fetches data from the model.
The controller passes the data to the view.
The view renders HTML and sends it back to the user.