# Modular monolith and monorepo

One app and one deploy, split into team-owned modules. Boundary rules checked in CI keep teams out of each other's code, with most of the ownership benefits and little of the runtime cost.

## How it works

1. **Modules per team.** Each team owns a module or package in one repository, tagged with its scope.
2. **Rules on imports.** Lint or workspace checks allow only the dependencies the rules permit, for example a team module may use shared libraries but not another team's internals.
3. **One build.** The app builds as one unit, so shared code is bundled once.
4. **One deploy.** Everything ships together; a boundary violation fails CI before it merges.

## Pros

- One app and one deploy, with no runtime composition to run.
- Ownership is clear and checked automatically.
- Refactoring across modules stays a normal code change.

## Cons

- Teams still share one release.
- One slow build or test suite can slow every team.
- Boundaries erode if the rules are not enforced in CI.

## Best when

- One to three teams.
- Teams that need clear ownership but not independent deploys.
- Any team considering micro frontends, as the baseline to compare against.

## Avoid when

- Teams are regularly blocked by a shared release.
- Parts of the product must run different frameworks.
- Separate organizations own separate parts.

## In code

`eslint.config.mjs (Nx)`

```js
import nx from "@nx/eslint-plugin";

export default [
  ...nx.configs["flat/base"],
  {
    files: ["**/*.ts", "**/*.tsx"],
    rules: {
      "@nx/enforce-module-boundaries": ["error", {
        depConstraints: [
          { sourceTag: "scope:checkout", onlyDependOnLibsWithTags: ["scope:checkout", "scope:shared"] },
          { sourceTag: "scope:search", onlyDependOnLibsWithTags: ["scope:search", "scope:shared"] },
          { sourceTag: "scope:shared", onlyDependOnLibsWithTags: ["scope:shared"] },
        ],
      }],
    },
  },
];
```

## Ratings

_Editorial judgement for a typical team, from 1 to 5._

- **Team independence: 2/5** (higher is better). Teams own their modules, but everything still ships in one release.
- **Runtime performance: 5/5** (higher is better). One app, built once, with no runtime composition cost.
- **Complexity: 2/5** (lower is simpler). A normal app plus boundary rules to define and keep in CI.
- **SSR / SEO support: 5/5** (higher is better). It is one ordinary app, so any server rendering setup works as usual.
- **Tech-agnostic: 1/5** (higher is better). One build means one framework for the whole app.
- **Isolation: 1/5** (higher is better). Boundaries apply to code at build time; at runtime everything shares one page.
- **UX consistency: 5/5** (higher is better). One app and one design system make a consistent experience the default.
- **Tooling maturity: 4/5** (higher is better). Monorepo tools ship boundary checks; some of them, such as Turborepo's, are still experimental.

## Tooling and ecosystem

This is not a lesser option. Natalia Venditto calls **modularization** a valid and efficient way to decouple a monolith, and more often than not the most suitable one. What sets it apart from micro frontends is that the modules are still deployed together.

In Nx, the `@nx/enforce-module-boundaries` lint rule checks imports and `package.json` dependencies against tags you give each project, and fails linting when a project depends on one its tags don't allow. Untagged projects can't depend on anything unless a rule allows `*`, and neither can a project whose tags match no rule, so every tag you use needs one. Turborepo's `turbo boundaries` command checks for imports outside a package's directory and for dependencies missing from its `package.json`, and supports tag-based rules; it is marked experimental.

## Sources

- [Enforce Module Boundaries](https://nx.dev/docs/features/enforce-module-boundaries), Nx documentation
- [boundaries](https://turborepo.dev/docs/reference/boundaries), Turborepo documentation
- [Micro Frontends](https://martinfowler.com/articles/micro-frontends.html), Cam Jackson · martinfowler.com
- [Modularization of a Monolith](https://microfrontend.dev/architecture/monolith-modularization/), Natalia Venditto · microfrontend.dev

https://microfrontends.dev/approaches/alternatives