Fundamentals6 min readLast updated: Thu Apr 04 2024 00:00:00 GMT+0000 (Coordinated Universal Time)

The MVC Pattern (Model-View-Controller)

MVC is a design pattern used in frameworks like Ruby on Rails, Django, and Laravel. It separates concerns into three boxes.

1. Model (The Data)

The Model manages the data and logic. It talks to the database.

  • "Get user with ID 5."
  • "Calculate total price."
  • It does not know about HTML or buttons.

2. View (The Interface)

The View is what the user sees (HTML/CSS).

  • It displays data given to it.
  • It is "dumb." It contains no business logic.

3. Controller (The Brain)

The Controller sits in the middle.

  1. It receives the user's click.
  2. It asks the Model for data.
  3. It passes that data to the View.

The Flow

User clicks "Profile" -> Controller receives request -> Asks Model for "User Data" -> Sends data to "Profile View" -> User sees page.