Controllers, Services, and Repositories

Module:Core concept

Controllers handle HTTP; services implement use cases; repositories encapsulate persistence; adapters integrate external providers.

How to apply it

Use a request flow of middleware, authentication, authorization, validation, controller, service, repository/transaction, and response. Inject dependencies explicitly and normalize errors centrally.

Worked example

A project controller validates request shape and calls a project service; the service enforces domain invariants before persistence.

Common mistakes to avoid

Database calls scattered across controllers or hidden business rules in middleware.

Practice task

Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.

Key Takeaways
  • Controllers handle HTTP; services implement use cases; repositories encapsulate persistence; adapters integrate external providers.
  • Use a request flow of middleware, authentication, authorization, validation, controller, service, repository/transaction, and response.
Knowledge Check

What is the strongest production practice for Controllers, Services, and Repositories?