EasyMonorepo📖 Theory Question

What are module boundary rules in Nx and why do they matter?

💡

Hint

ESLint rules enforced via project tags — prevents forbidden imports between domains (e.g., feature libs importing from other features)

Full Answer

Nx lets you tag each project (e.g., scope:checkout, type:feature, type:util) and then write ESLint rules that restrict which tags can import from which.

// .eslintrc.json
"@nx/enforce-module-boundaries": ["error", {
  "depConstraints": [
    { "sourceTag": "type:feature", "onlyDependOnLibsWithTags": ["type:ui", "type:util", "type:data-access"] },
    { "sourceTag": "scope:checkout", "notDependOnLibsWithTags": ["scope:profile"] }
  ]
}]

Why this matters:

  • Prevents accidental coupling between business domains (checkout code importing profile internals).
  • Keeps the dependency graph a DAG — no cycles between feature libraries.
  • Catches violations at lint time (CI) before they become architectural debt.
  • Makes it safe to eventually extract a domain into its own repo or microfrontend — no hidden cross-domain dependencies.

More Monorepo Questions

EasyWhat is a monorepo and what are its advantages over a polyrepo setup?EasyHow does Turborepo's caching work and what makes it fast?EasyHow does Nx differ from Turborepo?EasyWhat are pnpm workspaces and why are they preferred in monorepos?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint