Skip to content

No shared global state

No module-level mutable singletons — state injects at app entry so domains can run standalone.

nx-isolation-deps-no-global-state

Why it matters

Failure modes if this rule is ignored
StakeIf ignored
Hidden coupling
  • Global state is the fastest way to destroy a platform — untraceable dependencies.
Can't run alone
  • Without this, "run the app standalone" becomes an illusion — it waits for someone to populate state.

How to fix

No singletons holding cross-domain state. No global store every app writes to. If two domains need the same data, one owns it and the other receives it via the public contract.

Examples

Bad
ts
// libs/shared/state/src/lib/global-store.ts
export const globalStore = {
  currentUser: null,
  currentSite: null,
  activeWorkflow: null,
  isDevMode: false,
};
Good
ts
// libs/workspace/feature-workflow-builder/src/lib/workflow-runner.ts
type RunWorkflowOptions = { workflow: Workflow; devMode: boolean };

export function runWorkflow({ workflow, devMode }: RunWorkflowOptions) {
  if (devMode) { /* ... */ }
  return workflow.run();
}

// apps/workspace/src/main.tsx — composing layer
const user = await usersApi.getCurrent();
const site = await sitesApi.get(siteId);
runWorkflow({ workflow: site.workflow, devMode: user.preferences.devMode });

Contribute

Released under the MIT License.

esc