AR2: Architecture styles: monoliths, modular monoliths, microservices and events

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

The modular monolith

🎯You'll be able to

Explain how a modular monolith keeps one deployable while giving each part clear boundaries, and how those boundaries are enforced.

🏠The everyday picture

The growing restaurant keeps one building but divides the kitchen into stations: tandoor, curries, desserts. Each station has its own tools and passes finished dishes through one counter. A mess at one station stays there.

📘What it really is

📝A worked example

Input: the starter's reports/index.js requires ../orders/store and ../payments/ledger.

Steps:

  1. Add public functions: orders.listOrders() and payments.captured().
  2. Change reports to use them, so it no longer knows how orders and payments keep their records.
  3. Run npm run deps: the two internal reaches from reports are gone.
  4. Switch on module-boundaries so a new reach fails the build.

Expected output: reports depends on orders and payments only through their front doors, and the checker keeps it that way.

🌍Where it's used

📝Case scenario

A school platform split its code into modules for fees, students and timetables, but didn't check the rules. Within a year, timetables read fee records "just once" for a report, then twice. Adding a checker to the build found 23 reaches; fixing them took a month, which a checker from the start would have avoided.

🖱️Try it

In the starter, find one internal reach with npm run deps and write the public function that would replace it. Success: the function's name says what it gives, not how the data is stored.

⚠️Common mistakes

🛠️For your project

Project 2's test 4 checks notifications' boundaries with the kit's dependency tool. Project 3 switches module-boundaries on for all.

✅Quick check

What does a modular monolith keep from a monolith?

Show the answer

One deployable and one process, with its simplicity.

Why must module boundaries be enforced by a tool?

Show the answer

Without a check, reaches creep in under deadline pressure and the boundaries erode.

← PreviousThe monolith
ProLearners Assist