Module Scaffolder
This skill runs after placement is decided. If ownership, spine layer and extend-versus-create are still open, stop and use system-architect first. Building files is the cheap part; building them in the wrong place is the expensive part.
A module is bounded when you can state what it owns, what it reads, what it emits, and what breaks if it is deleted — before any file exists.
Hard rules
- One module, one owner, one purpose. Written down, in the module itself.
- No duplicated truth. The module holds references to facts other modules own.
- The export surface is deliberate. Everything else is internal.
- Every module has tests that would fail if its core behaviour broke.
- The view is minimal. A module is its domain logic; the screen is a window.
- Registration is explicit where the architecture has a module registry — an unregistered module is an orphan.
Shape
src/modules/<module-name>/
OWNERSHIP.md owns / knows / emits / relates — four headings, no prose padding
types.ts the module's own types; imported types come from their owner
<domain>.ts domain logic, framework-free
events.ts event type definitions this module produces
index.ts the deliberate export surface
__tests__/ behaviour tests
references/ only when domain rules need explaining beyond the codeAdapt names to the project's existing convention — consistency with the codebase beats consistency with this list. What must survive adaptation: the ownership declaration, the framework-free domain layer, the deliberate export surface, and the tests.
Procedure
- Write `OWNERSHIP.md` first, before any code:
- Owns — the facts this module is the single source of truth for.
- Knows — what it reads from elsewhere, and from which owner.
- Emits — the events it publishes, with their consumers named.
- Relates — its foreign relationships, by reference. If any section reads "same as an existing module", stop and extend that module.
- Define types. Own only your own. Import the rest from their owner; a local copy of another module's type is duplicated truth in slow motion.
- Write the domain logic framework-free. No React, no router, no ORM in the domain layer. It should be testable without booting anything.
- Define events per
event-spine-designer: past-tense, attributed, with named consumers. - Curate `index.ts`. Export what other modules legitimately need. Everything else stays internal. A module that exports its whole directory has no boundary.
- Write the tests against behaviour: the invariant it protects, the boundary it refuses to cross, the event it emits. Not the getters.
- Add the minimal view. One route, reading through the module's public surface only. Framework specifics:
references/tanstack-route-surface.md. - Register the module wherever the architecture expects it.
- Delete-test it. If this module were removed, what breaks? "Nothing" means it should not exist. "Everything" means it is not bounded.
Route surface
Absorbed capability: the proposed route-surface-builder. It is a reference, not a skill, because framework conventions change faster than architecture and must not make a general skill framework-specific. See references/tanstack-route-surface.md for TanStack Start specifics. In another framework, the principles hold and the reference does not apply: routes are thin, they call the module's public surface, and they never contain domain logic.
Worked example
Task: a `compliance` module tracking certificate validity per property.
- OWNERSHIP.md. Owns: certificate records, validity assertions. Knows: properties (owner:
property), documents (owner:provenance-intake). Emits:compliance.certificate_recorded,compliance.lapsed— consumed by scheduling and notifications. Relates: certificate → property, certificate → source document. - Types.
Certificate,ValidityWindow.Propertyis imported, not redefined. Noproperty_addressfield — that is the property module's fact. - Domain.
isLapsedAt(certificate, instant)— a pure function, tested without a database. - Events.
compliance.lapsedis emitted by a scheduled evaluation, actorsystem:compliance-evaluator, carrying the certificate reference. - Surface.
index.tsexports the types,isLapsedAt, and a query for a property's certificates. The storage adapter stays internal. - Tests. Lapse boundary at exactly the expiry instant; a certificate superseded by a renewal does not report lapsed; an unknown expiry returns
unknown, notfalse. - View. One route showing certificates for a property, reading only the public surface.
- Delete test. Removing it loses compliance tracking and two event consumers degrade — bounded, and it earns its place.
Pressure tests
- Does
OWNERSHIP.mdname any fact another module also claims? - Can the domain layer be tested without a framework, a database or a network?
- Does any type here duplicate a type another module owns?
- Does
index.tsexport anything no other module actually imports? - Does any event have no consumer, or any consumer no producer?
- Is there domain logic inside a route or component?
- If deleted, does anything break — and does anyone find out?
Stop conditions
- Placement is unsettled — use
system-architectfirst. OWNERSHIP.mdcannot be written without claiming a fact someone else owns.- The module would need a copy of another module's data to function.
- The module has no events and no owned facts — it is a utility, not a module; put it where utilities live.