stnd.build

Foundation Imports a Feature Module

Error: [ERR_FOUNDATION_IMPORTS_FEATURE] The foundation module "core" imports feature module "<name>". Law #4: dependencies flow features -> core, never the reverse.


The Problem

A file in modules/core/ imports from a feature module (@modules/<feature>/...). The core is the shell of the app — its layouts, its landing page, its error pages — and the shell has just become dependent on one of the features it is supposed to host.

---
// modules/core/layouts/Base.astro  (illegal: the shell imports a feature)
import ManualSidebar from "@modules/manual/components/ManualSidebar.astro";
---

<ManualSidebar />

The Why

  1. The feature can no longer be removed or extracted. Delete modules/manual/ and the shell no longer builds. A feature that cannot leave is not a vertical slice.
  2. It turns the dependency graph into a loop. The feature already imports from the core (that is allowed); the core importing it back makes the two inseparable.
  3. Only dependency-cruiser was watching, and it cannot read .astro files. These imports used to pass pnpm boundaries silently; stnd check, the MCP audit and pnpm check:astro-boundaries now report them.

The Solution

The shell does not name the feature. It opens a zone; the feature fills it.

1. Open a hook zone in the core

---
// modules/core/layouts/Base.astro
import Hook from "@stnd/core/Hook";
const { headings, slug } = Astro.props;
---

<Hook zone="core:sidebar" props={{ headings, slug }} />

The zone name is <owner>:<thing> — the module that opens the zone owns the prefix. props are handed to every component registered under it.

2. Register the feature’s component in its manifest

// modules/manual/index.module.js
export default {
  id: "manual",
  hooks: {
    "core:sidebar": ["./components/ManualSidebar.astro"],
  },
};

If nothing is registered, the zone renders nothing and the core still builds — which is exactly the point.

3. Mind the styles

A component mounted through a zone comes from another module, so it carries none of the scope attribute Astro adds to the page’s own <style> rules. If the core’s page styles the injected markup (.cover-cell a { … }), write those selectors with :global() — .cover-cell :global(a) — or give the injected component its own styles.