Modellen

Model-View-Controller

Model-View-Controller: user loop on the left, data loop on the right Two loops share the Controller at the top centre. Left, the user loop: 1 the user sends a request to the Controller, 4 the Controller delivers an update to the View, 5 the View shows the result to the user. The user has a mental model of how the application works; the View should match it. Right, the data loop: 2 the Controller contacts the Model, 3 the Model returns data to the Controller. The Model connects to the database and is the abstraction layer over how and where data is stored. The Controller is highlighted as the coordinator. Responsibilities: the Controller handles input and change, the View does rendering, the Model holds state, data and rules. User Mental model Controller input / change View rendering Model state / data / rules Database User loop 1 Request 4 Delivers 5 Shows Data loop 2 Contacts 3 Returns Abstraction layer
Model-View-Controller: user loop on the left, data loop on the right Two loops share the Controller at the top centre. Left, the user loop: 1 the user sends a request to the Controller, 4 the Controller delivers an update to the View, 5 the View shows the result to the user. The user has a mental model of how the application works; the View should match it. Right, the data loop: 2 the Controller contacts the Model, 3 the Model returns data to the Controller. The Model connects to the database and is the abstraction layer over how and where data is stored. The Controller is highlighted as the coordinator. Responsibilities: the Controller handles input and change, the View does rendering, the Model holds state, data and rules. Controller User Mental model View Model Database 1 Request 4 Delivers 5 Shows User loop 2 Contacts 3 Returns Data loop Abstraction layer

Model-View-Controller wordt meestal teruggevoerd op Trygve Reenskaug, die het patroon in 1979 beschreef voor Smalltalk.

Eigen samenvatting en weergave.

Model-View-Controller (MVC) deelt een applicatie op in drie rollen, elk met een eigen verantwoordelijkheid: scheiding van zorgen. Het model bevat de state, de data en de bedrijfsregels; de view doet alleen de weergave (rendering); de controller handelt invoer en verandering af. De controller is het "brein" en de brug tussen beide: hij coördineert, maar de regels blijven in het model. In het diagram zie je links de gebruikerslus en rechts de gegevenslus.

Zo loopt een verzoek

  1. Request — de gebruiker stuurt een verzoek (een klik, een formulier); de controller vangt de invoer op.
  2. Contacts — de controller benadert het model om gegevens op te halen of te wijzigen. Het model is de abstraction layer: het verbergt hoe en waar de gegevens zijn opgeslagen.
  3. Returns — het model geeft de gegevens terug aan de controller.
  4. Delivers — de controller werkt de view bij.
  5. Shows — de view toont het resultaat aan de gebruiker. Die weergave zou moeten aansluiten bij het mental model van de gebruiker: het beeld dat de gebruiker zelf heeft van hoe de applicatie werkt.

Wil je weten of jouw app zich aan deze regels houdt? Kopieer de Engelstalige prompt hieronder en geef die aan je coding agent: die checkt of de rollen kloppen en in welke valkuilen je app is gestapt.

Check je app

Kopieer de prompt en geef die aan je coding agent (Claude Code, Cursor of vergelijkbaar).

You are auditing this codebase for how well it follows the Model-View-Controller (MVC) pattern. Work READ-ONLY: do not change, create, move or delete any files, do not run migrations, and do not install anything. Only read code and report.

Background (so you do not need any other source):
- Model = application state, data and business rules. It knows nothing about screens, HTML or UI frameworks.
- View = rendering only. It turns data it is given into what the user sees. No business rules, no data access.
- Controller = thin coordinator. It receives user input (a request, click, form submit), asks the model to read or change data, and passes the result to the view. No SQL, no business rules.
- Data / abstraction layer = the repository, ORM, data mapper or storage service the model uses. It hides how and where data is stored (database, file, external API).
- The request cycle is: 1 the user sends a request to the controller; 2 the controller contacts the model; 3 the model returns data; 4 the controller delivers it to the view; 5 the view shows the result to the user. That result should match the user's mental model: what the user expects the application to do and show.

Step 1 - Map the codebase
Identify which concrete files, folders, classes or modules play each role: Model, View, Controller, and the data / abstraction layer. Name them with paths. If the application uses a different pattern (MVVM, MVP, component-based UI, server actions, etc.), say so and map the closest equivalents. If a role is missing or mixed into another, say that explicitly.

Step 2 - Check responsibilities
- Model: holds state, data and business rules; contains no UI, rendering, HTML, formatting for display, or framework view imports.
- View: renders only; contains no business rules, no calculations that decide outcomes, and no data access (no queries, no direct API or database calls).
- Controller: thin; handles input and change, delegates decisions to the model; contains no SQL or raw queries and no business rules.

Step 3 - Check dependency direction
- The view never talks to the database or storage directly.
- The model does not import view, template or UI code.
- Controllers depend on models (or services), not the other way round.
- Look for import cycles between layers.

Step 4 - Check the abstraction layer
- Data access sits behind a clear boundary (repository, ORM, data service or equivalent).
- No raw queries or storage calls in views or controllers.
- Swapping the storage (for example a database for a file or an API) would only touch the data layer.

Step 5 - Check known pitfalls. For each one, search for concrete evidence:
1. Fat controller: controllers containing business rules, long methods, or query building.
2. Anemic vs fat model confusion: models that are only data bags while rules live elsewhere, or models that have absorbed UI, HTTP or unrelated concerns.
3. Business logic in templates: conditions, pricing, permissions or calculations inside views/templates.
4. View that fetches data itself: components or templates that call the database, ORM or backend API directly instead of receiving data.
5. Duplicated validation: the same rule implemented in several places (view, controller, model) that can drift apart.
6. Tight coupling to a framework or database: business rules that cannot run without the web framework, ORM session or a specific database.
7. State scattered over view components: the same piece of application state held and mutated in several UI components instead of one source of truth.
8. Circular dependencies between model, view and controller modules.
9. Untestable controllers: controllers that cannot be tested without a real database, network or UI, or that have no tests at all where logic exists.

Step 6 - Check the view against the user's mental model
- Do names, labels and screens use the user's words for things, or internal/technical names?
- After an action (for example adding an item to a cart, completing a to-do, borrowing a library book), does the user see the result they would expect, where they would expect it?
- Are flows consistent: does the same action behave the same way on different screens?

Rules for findings
- Every finding must cite evidence: file path and line numbers (or a function/class name if line numbers are not available).
- Give each finding a severity: High (breaks the separation or causes real bugs), Medium (makes change or testing noticeably harder), Low (style or minor drift).
- Give a short, concrete fix suggestion.
- If you find no evidence for a check, write "not applicable / no evidence". Do not guess and do not invent findings.
- Prefer a few well-evidenced findings over many vague ones.

Output format
1. Role map: a short table with columns Role | Files / modules | Notes.
2. Findings table with columns: # | Check / pitfall | Evidence (file:line) | Severity | Fix suggestion. Include a row for every pitfall in Step 5, using "not applicable / no evidence" where relevant.
3. Top 3 fixes: the three changes with the best impact for the effort, each with one or two sentences on why and where to start.
4. One-paragraph overall verdict: how closely this application follows MVC today.