Skip to content

    Frontend System Design

    Before Micro-Frontends: the Modular Monolith Front End

    The modular monolith front end: one deployable app made of modules with enforced boundaries, owners and contracts, and how it differs from micro-frontends.

    By Published 13 min read

    Share

    Standard lessonintermediateFrontend System Design

    Before this: Monorepos and Shared Libraries, Layered and Clean Architecture for the UI

    What you'll learn: By the end of this lesson you will be able to define a modular monolith front end and its three ingredients (modules, enforced boundaries, owners), say how modules talk to each other and to a shell, load modules on demand without a second deployment, tell a modular monolith from one that is modular only in its folder names, compare it with a plain monolith and with micro-frontends, and decide when it is the right stopping point.

    A restaurant opens its first kitchen with stations: grill, cold, pastry. Each station has a chef, its own tools and a ticket window where orders arrive. Nobody reaches across the grill to take the pastry chef's whisk. When the restaurant is busy enough to open a second site, the stations are already the units that can move. A restaurant that skipped the stations would have to untangle the kitchen first.

    A front end can follow the same order. This lesson is about the stage before Monolith vs Micro-Frontends: When to Split a Front End asks whether to split at all: one deployable application, built from modules with real walls. The running example is a storefront with a shell and four modules: catalog, cart, checkout and account.

    The core idea

    1. A modular monolith is one deployable with enforced internal boundaries. One build, one release, one version of each dependency. Inside it, each module owns a business area, exposes a small public API and is checked by tools.
    2. Much of what hurts in a monolith is missing modularity, not the single deployment. This is a design argument, not a measurement: tangled imports, unclear owners and slow builds have fixes that need no runtime composition.
    3. It is the cheaper first step, and it keeps the option open. Martin Fowler's MonolithFirst note says "even experienced architects working in familiar domains have great difficulty getting boundaries right at the beginning", and that the logical way is to "design a monolith carefully, paying attention to modularity within the software". He adds that it takes discipline, and that a system with too many dependencies between modules cannot be sensibly broken apart.

    Three illustrations run through the lesson: a minimal one (a module's contract), a realistic one (the storefront's shell and four modules) and a failure (modules in name only).

    What a module is

    Here a module is a unit someone owns, drawn along a business slice, not a technical layer. Feature-Based and Modular Folder Structure gives the layout, and Module Boundaries and Public APIs defines the public API. Feature-Sliced Design's wording is the one to keep: a public API "is a contract between a group of modules, like a slice, and the code that uses it", with the goals that the rest of the app is "protected from structural changes to the slice" and that "only the necessary parts of the slice should be exposed". Domain-driven design offers a way to find the lines: Fowler's note says DDD "deals with large models by dividing them into different Bounded Contexts", and that "different contexts may have completely different models of common concepts". In the storefront, "product" in the catalog (description, images) is not "product" in the cart (a price and a quantity), and each module keeps its own model.

    A modular monolith needs three ingredients. A folder with an index.ts has only the first.

    1. A boundary: a small public API and internals nobody else imports.
    2. Enforcement: a failing check, not a convention. Module Boundaries and Public APIs covers the tools; for example ESLint's no-restricted-imports (static imports only, not dynamic ones), dependency-cruiser's forbidden rules with circular and an error severity that makes some reporters exit non-zero, and Nx's tags and depConstraints. FSD says it directly: with an index file you "don't actually forbid anyone from not using it and importing directly".
    3. An owner: a named team or person who approves changes to the module's public API.

    Illustration 1 (minimal): a module's contract. This sketch is illustrative TypeScript, not run here. The module exposes its routes, a loader and a few typed functions, and nothing else.

    // features/cart/index.ts: the whole public API of the cart module
    export { cartModule } from "./module";   // { id, routes, load }
    export type { CartSummary } from "./types";
    export { useCartSummary } from "./useCartSummary";

    The shell imports cartModule and nothing from features/cart/internal. The cart team can reorganise its internals, swap its state library or rename files as long as these three names keep working.

    Figure 1. A shell composing modules inside one deployable

    A shell loads catalog, cart, checkout and account modules; modules use only each other's public APIs and shared packagesshell to modules (loads by route); modules to shared (imports); modules to shell (no import back)ONE BUILD, ONE DEPLOYMENTshell: routes, layout, authshellroutes, layout,authmodules: catalog, cart, checkoutmodulescatalog, cart,checkoutshared: ui, tokens, api clientsharedui, tokens, apiclientloads by routeimportsno import back

    How to read this: the zone is the deployment unit. The shell knows the modules; the modules do not know the shell. The red edge is the one the boundary rules forbid.

    How modules talk to each other

    A boundary is only useful if there is a sanctioned way across it. Three are common, in order of preference:

    • Through the public API. Checkout calls useCartSummary() from the cart module. The dependency is explicit, typed and visible in the graph.
    • Through the shell. The shell passes what a module needs, for example the signed-in user, as props, context or a small interface (see Dependency Injection and Separation of Concerns in the Front End).
    • Through events or the URL. A module announces "item added" and other modules may react. The event names and payloads are then a contract, as much as a function signature.

    What to avoid is a shared mutable store that every module reads and writes. It looks like a public API, but it is a hidden one: any module can depend on any field, and no tool sees the edge. A hand-written event bus carries the same risk if its events are free-form strings: put the event names and payload types in one typed module.

    Loading modules on demand without a second deployment

    One deployable does not mean one bundle. React's lazy "lets you defer loading component's code until it is rendered for the first time", and you wrap the component in Suspense to show a fallback; lazy is declared at the top level of a module, not inside another component, because declaring it inside "will cause all state to be reset on re-renders". Behind it is the dynamic import(), which MDN describes as returning "a promise for the module namespace object", evaluated only when needed.

    // shell/routes.tsx (illustrative, not run here)
    const CartPage = lazy(() => import("@/features/cart").then((m) => ({ default: m.CartPage })));

    The result: the shell stays small, each module's code arrives when its route is visited, and everything still ships as one release with one version of React. The split is by bundle, not by deployment; Code Splitting, Lazy Loading and Tree Shaking goes into the bundler side.

    Figure 2. One release, several chunks

    sequenceDiagram accTitle: Loading a module on demand inside one deployable accDescr: The browser loads the shell chunk from the single deployment. When the user navigates to the cart route, the shell calls a dynamic import. The browser fetches the cart chunk from the same deployment, the module registers its route, and the cart page renders inside a Suspense boundary. participant U as User participant S as Shell (initial chunk) participant C as Cart chunk U->>S: open the storefront Note over S: one deployment, one version U->>S: navigate to /cart S->>S: lazy(() => import cart) suspends S->>C: fetch chunk (same deployment) C-->>S: module namespace (CartPage) S-->>U: render CartPage, replace fallback

    How to read this: both fetches come from the same release. If the chunk fails to load, the shell's Suspense and error boundary handle it; the modules did not need their own deployment to be loaded late.

    Plain monolith, modular monolith, micro-frontends

    Fowler's micro-frontends article defines the style as "independently deliverable frontend applications are composed into a greater whole" and lists its benefits (incremental upgrades, simpler decoupled codebases, independent deployment, autonomous teams) and costs (duplication of dependencies, a "lockstep release process" when teams integrate at build time, and "more repositories, more tools, more build/deploy pipelines"). The modular monolith keeps the benefits that come from structure and gives up those that come from runtime separation.

    Plain monolith Modular monolith Micro-frontends
    Deployable One One Several, each independent
    Boundaries Convention at best Enforced by checks Enforced by deployment and runtime
    Release Whole app together Whole app together Per piece
    Dependencies One version of each One version of each May duplicate or be shared at runtime
    Teams Share everything Own modules, share the release Own pieces end to end
    Failure isolation None Error boundaries inside one page A broken piece can be isolated at runtime, if built for it
    Main cost Tangle over time Discipline and tooling Composition layer, versioning, operations

    The modular monolith gives a team the code-level benefits of ownership: smaller mental load, local changes, reviewable APIs. It does not give independent deployment: a change to cart ships when the whole app ships, which is what a release train means. Whether that matters is the question the next lessons answer: Micro-Frontends and Conway's Law and Independent Deployment and Shared Dependencies.

    Where the build lives

    A modular monolith can be one package with folders, or a workspace with a package per module. The package version buys stronger walls (exports, a manifest listing who may use whom) and per-package caching and affected builds, at the price of a workspace to maintain; see Monorepos and Shared Libraries. Turborepo's cache hashes a task's inputs and replays the result when they are unchanged; Nx's tag rules can reject a forbidden edge. Neither requires the modules to deploy separately, which is why slow builds and tangled imports are not by themselves a reason for micro-frontends.

    The failure: modules in name only

    Illustration 3 (failure): a modular monolith that is not. The folders exist: features/catalog, features/cart, features/checkout. But checkout imports features/cart/internal/pricing, cart reads a field from a global store that catalog writes, and an index.ts re-exports everything with export *. No rule fails, the build passes, and every module quietly depends on the others' internals.

    The cost appears when someone tries to use the boundaries. Moving the cart team's folder breaks checkout. A planned split of checkout into its own app finds that it needs half the cart module and the global store. This is the case Fowler warns about: a system with too many dependencies between modules cannot be sensibly broken apart. The check for it is a graph report: for each module, list the files outside the module that import something other than its public API. In a real modular monolith the list is empty or on a ratchet toward empty.

    Figure 3. Healthy and unhealthy dependencies

    A healthy module is entered through one public API; an unhealthy one is entered through its internals and a shared storecheckout to cart/index.ts (healthy); cart/index.ts to cart internals (re-exports); checkout to cart internals (deep import)FEATURES/CARTcheckout: another modulecheckoutanother modulecart/index.ts: public APIcart/index.tspublic APIcart internals: pricing, statecart internalspricing, statehealthyre-exportsdeep import

    How to read this: the top path is what the rule allows. The red edge is what makes a later split expensive; each one adds to the list of things to untangle.

    Trade-offs

    Choice Gains Costs
    Modular monolith over plain monolith Local changes, clear owners, a cheaper way to learn the right boundaries Tooling and the discipline to keep rules green
    Modular monolith over micro-frontends One build, one version of each dependency, no runtime composition layer One release train; a bad change in one module can block the release
    Package per module Stronger walls; per-package caching A workspace to maintain; versioning inside the repository
    Folder per module Least setup Walls depend on lint and graph checks only
    Events between modules Looser coupling A hidden contract unless event names and payloads are typed

    In practice: a storefront with one release and four modules

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    Illustration 2 (realistic): the storefront. A shell owns routing, layout and sign-in. Catalog, cart, checkout and account are modules with owners. Shared packages hold UI primitives, tokens and a typed API client. Everything is built and deployed together.

    The situation

    Four teams (about twenty engineers, illustrative) work in one repository. Releases happen every Thursday. A proposal says to move to micro-frontends because "the teams keep breaking each other". A look at the pull requests shows the breakage comes from imports of internals and a global store, not from the weekly release.

    Starting architecture

    Figure 4. Starting point: folders without walls

    Starting architecture: four feature folders that import each other's internals and share one global storecatalog to cart (deep import); checkout to cart (deep import); catalog to global store (writes); cart to global store (reads)catalog: team Acatalogteam Acheckout: team Ccheckoutteam Ccart: team Bcartteam Bglobal store: read and write by allglobal storeread and write byalldeep importdeep importwritesreads

    How to read this: no module can change without risk to others, but nothing about the deployment is the cause.

    Options considered

    Option Attraction Risk
    Micro-frontends Independent releases Adds composition, versioning and operations; the tangle moves with the code
    Modular monolith Fixes the cause with checks and public APIs Needs a few weeks of cleanup and rules that fail builds
    Do nothing No effort Breakage continues

    The decision

    Field Decision record
    Context Cross-team breakage is caused by deep imports and a shared global store.
    Decision Keep one deployable. Give each module a public API and an owner. Replace the global store with module state plus a typed event list. Enforce with lint and a graph check at warn, then error. Load modules by route with lazy.
    Consequences, good Teams change internals freely; the graph shows what depends on what; the option to split stays open.
    Consequences, bad One release train; the rules need upkeep; some APIs will be too small at first.
    Revisit when Teams need to ship on different days and the release train is the measured blocker.

    Rollout and verification

    1. Count first. Run the boundary rules at warn and record violations per module.
    2. Remove the global store last, after its readers have public APIs to use instead.
    3. Promote the rule to error module by module at zero violations.
    4. Check the bundle: each module's code should arrive in its own chunk, not in the shell's.

    The 2 a.m. failure

    A page loads, then a blank area appears where the cart should be. The new route-level lazy import for the cart module fails because the browser still holds a shell from the previous release and requests a chunk file the new release replaced (illustrative). The module is fine; the failure is a stale shell asking for a file that no longer exists.

    First three checks: (1) look at the failed chunk request in the network log; (2) compare the shell's release with the deployed chunk names; (3) confirm an error boundary exists around the lazy route. Mitigation: show a reload prompt in the error boundary and keep previous chunk files available for a short while. Follow-up: add a test that loads a lazy route against a newer build.

    Architect's notes

    • Draw the lines on the business, not the layers. A module is a slice with an owner.
    • Make the rule fail the build or the boundaries decay.
    • Keep one version of each dependency until you have a reason to split.
    • Measure the pain before you pay for runtime composition: a blocked release train is evidence; "the code feels messy" is not.
    • Plan the extraction seam: a module with a small, typed public API and its own state is already shaped like a future micro-frontend.

    Common mistakes

    • Calling folders modules. Without a failing check there are no walls.
    • A shared global store that every module reads and writes.
    • export * from every index file, which widens the public API by accident.
    • Reaching for micro-frontends to fix an import problem.
    • No owner per module, so nobody approves public API changes.

    Key takeaways

    • A modular monolith is one deployable with modules, enforced boundaries and owners.
    • It addresses structural pain (tangled imports, unclear ownership) without a runtime composition layer.
    • Modules talk through public APIs, the shell, and typed events, not a shared mutable store.
    • lazy and dynamic import() give per-module chunks inside one release.
    • It does not give independent deployment, and the release train remains.
    • A well-bounded module is the natural seam if a split is ever justified.

    Practice exercises

    Exercise 1 (Starter, 30 min): For an app you know, list its modules and, for each, the names another module imports. Which imports go past a public API?

    Exercise 2 (Intermediate, 2 hours): Write the typed event list for the storefront (names and payloads) so that cart and checkout can react to each other without importing each other.

    Exercise 3 (Advanced, half day): Using Monorepos and Shared Libraries as a base, sketch a workspace with a package per module, with tags and constraints. Say which edge you would forbid first and why.

    In this course:

    Official documentation

    Tools and further reading

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments