stnd.build

Multiple Foundation Modules

Error: [ERR_MULTIPLE_FOUNDATION_MODULES] Application declares multiple foundation modules. An application must have exactly one foundation spine.


The Problem

An application has declared more than one module with role: "foundation" in its manifest, or defines a custom foundation module while modules/core already exists:

// modules/core/index.module.js (Default foundation)
export default {
  id: "core",
  role: "foundation"
};

// modules/spine/index.module.js (Conflicting second foundation!)
export default {
  id: "spine",
  role: "foundation"
};

The Why

In Standard’s Vertical Slice Architecture (Law #4), the Foundation Spine is the single shared kernel of the application. It hosts core domain models (models/), root layouts, and session state that any feature module may freely import.

Allowing multiple foundation modules breaks the architectural contract:

  1. Ambiguous Dependency Authority: When two modules claim to be the foundation, other feature modules do not know which spine to rely on.
  2. Spine-to-Spine Cross-Import Loops: If modules/core and modules/spine both act as foundations, they risk cross-importing each other, reintroducing circular dependencies and tightly coupled spaghetti code.
  3. Loss of Convention: An engineer or agent entering the codebase cannot determine the single source of truth for core models.

The Solution

An application must designate exactly one module as its foundation spine (by convention modules/core/).

Ensure all other modules in your modules/ directory are declared as feature modules (which is the default if role is omitted):

// modules/core/index.module.js (The ONE foundation spine)
export default {
  id: "core",
  role: "foundation",
  name: "Application Spine"
};

// modules/spine/index.module.js (Refactored to a feature module)
export default {
  id: "spine",
  role: "feature", // or omit role entirely
  name: "Spine Feature"
};