Skip to content

Explicit cross-domain contracts via Nx tags

Cross-domain imports go through public barrel exports — Nx tags enforce who may depend on whom.

nx-isolation-nx-tag-contracts

Why it matters

Failure modes if this rule is ignored
StakeIf ignored
Agent gets lost
  • The moment one domain reaches into another's internals, rule 1 silently breaks.
Hidden coupling
  • Import from another domain's internals — their refactor becomes your production outage.
API drift
  • Every export is public — rename an internal helper, break three consumers silently.

How to fix

A domain may not import from src/ of another domain. Only via the library barrel (index.ts). Nx enforces this with tags.

Examples

Bad
ts
// apps/workspace/src/workflow-builder.ts
import { SiteModel } from '../../../libs/sites-management/data-access/src/lib/internal/models/site';
import { validateSlug } from '../../../libs/sites-management/data-access/src/lib/utils/validation';
Good
json
{
  "rules": {
    "@nx/enforce-module-boundaries": ["error", {
      "depConstraints": [
        { "sourceTag": "domain:studio",            "onlyDependOnLibsWithTags": ["domain:studio", "domain:shared"] },
        { "sourceTag": "domain:sites-management",  "onlyDependOnLibsWithTags": ["domain:sites-management", "domain:shared"] },
        { "sourceTag": "domain:shared",            "onlyDependOnLibsWithTags": ["domain:shared"] },
        { "sourceTag": "type:feature",             "onlyDependOnLibsWithTags": ["type:feature", "type:data-access", "type:ui", "type:util"] },
        { "sourceTag": "type:ui",                  "onlyDependOnLibsWithTags": ["type:ui", "type:util"] }
      ]
    }]
  }
}

Contribute

Released under the MIT License.

esc