Concept
Model-View-Controller (MVC) Pattern
In backend APIs, the MVC pattern organizes code by separating concerns into distinct layers:
┌────────────────────────────────────────────────────────┐
│ Client Request ──▶ Route ──▶ Controller ──▶ Model │
│ (HTTP GET) (Validates) (Database) │
└────────────────────────────────────────────────────────┘- Model: Manages data structures and database operations (e.g. Mongoose schema or Prisma Client).
- View (or Presenter): Formats the response returned to the client (in JSON APIs, this is the structured JSON return shape).
- Controller: Handles request validation, calls Model methods, and sends response payloads back to views.
API Versioning Strategies
When releasing breaking changes to a public API, existing clients must not crash. Versioning ensures backward compatibility: