So I was thinking how I explained this in the past to my colleagues and I though that perhaps this was a good explanation to write it down.
It's about splitting an application up into dedicated parts:
- router
- controller
- service
- repository
A customer walks through the front door of the restaurant. The Floor Manager (Router) greets them with a smile, glances at the reservation list and the current seating chart, and decides where they should go.
“Welcome. I have a nice table for you in the main dining section, table 14. Waiter Maria will take care of you.”
The Floor Manager leads them to the table and walks away.
A little later the customer is ready to order and raises a hand. The Floor Manager notices, confirms this table belongs to Waiter Maria, and simply directs her over. Again, pure routing and no taking of orders, no cooking.
Waiter Maria (Controller) arrives at the table.
“Good evening, what can I get for you tonight?”
The customer orders a medium-rare ribeye with peppercorn sauce and roasted vegetables from the menu. Maria carefully notes the request, double-checks a couple of details, and carries the clean order ticket into the kitchen. She never decides how the food should be prepared and never opens the storeroom.
In the kitchen the Chef (Service) receives the ticket. He applies the restaurant’s recipes and rules: the correct cut of meat, the exact timing for medium-rare, the proper way to make the peppercorn sauce, and the coordination with the vegetable station. His focus is entirely on turning the order into a finished dish. When ingredients are needed, the Chef calls the Pantry Keeper (Repository).
“One 12-ounce ribeye, the peppercorn base, and a portion of prepped root vegetables, please.”
The Pantry Keeper retrieves the items from their precise locations in the storeroom and hands them over. He doesn’t know or care why they are needed. He only manages access to the stock.
Soon the Chef prepares and plates the dish.
Waiter Maria picks it up and brings it to table 14. The customer enjoys the meal, and every role stayed cleanly separated from the moment the guest first stepped through the door:
Floor Manager only routed
Waiter only handled the customer and the request
Chef only applied the cooking logic
Pantry only fetched the ingredients
This clean separation is to me a schoolbook example and how thing should be done.
Top comments (0)