Three-Tier Hoisting
Default to local. Earn each tier upward.
Not the JavaScript kind. The refactoring kind: a helper starts in the module that needs it and is lifted to a higher tier as it earns broader reuse. Default to local. Earn each tier upward.
Opinion
I've spent enough years watching utils/ folders become the codebase's attic to know what a missing middle tier costs. Feature-Sliced Design and Bulletproof React both nail the bottom of the stack (a shared/ drawer for product-agnostic code) and both stop there.1 Everything domain-specific lands in feature folders, which means a helper used by three features either gets duplicated three times, or sneaks into one feature folder and gets imported sideways from the other two. The first option lies about DRY. The second lies about coupling.
The fix is the named middle tier. lib/product/ holds get-tenet-data and build-tenet-page-metadata: domain-aware, reused across modules, not so generic that the helpers would survive being shipped to another product. Robert C. Martin's Common Reuse Principle supplies the reasoning: classes used together are packaged together.2 No published architecture I've found turns CRP into a named folder. The unnamed middle tier is the bug. Three-Tier Hoisting is my fix and I've worked with it for years.
The second sharp edge is the metric. lib/generic/ and lib/product/ can only grow through deliberate hoisting. Nobody accidentally writes lib/generic/array/sort-by.ts; the file appears because a contributor noticed three call sites and lifted it. Six files in lib/generic/ after a year of work does not mean the codebase is lean. It means duplication is hiding in modules.
Copy a note and link
Grab this short comment and drop it into a PR comment or an LLM chat to prompt the right change.
Default to local. Earn each tier upward. A helper starts next to its consumer. On the third use it hoists: to `lib/product/` if it names a domain term, to `lib/generic/` if it would compile after `npm publish`. Imports flow upward only. /tenet/three-tier-hoisting/A2
AI eyes only
Rule: default to module-local. Hoist to lib/product/ on the third caller. Hoist to lib/generic/ only when the use is product-agnostic.
Reject: dropping new helpers into the file you happen to be editing. Reject: imports from sibling features. Reject: re-emitting a utility you could find via grep.
Generate: place new helpers next to the only caller. Promote to lib/product/<domain>/ on the third caller. Promote to lib/generic/ when the function names no product concept.
Diagnostic: imports flow upward only. Sibling-feature imports are the signal to hoist. Generic imports of product types are the signal to demote.
Why?
- Defaulting to module-local removes the “where do I put this?” tax on every new helper. The decision is made: it lives next to the consumer until a second consumer earns the move.
- The lift-to-npm test is binary. If the file would compile after
npm publishwith no edits, it belongs inlib/generic/. Reviewers stop arguing taste. They ask the test. - Imports flow upward only, module to
product/togeneric/. The graph direction is the design, lint-enforced viaimport/no-restricted-paths. No cycles, no surprise reverse couplings. - The size of
lib/generic/andlib/product/is a leading DRY indicator. Nobody accidentally writes a hoisted helper. If those folders are thin after a year, the codebase is hiding duplication. - Pairs with F1 Single Responsibility: when a function is extracted for SRP, the tier it lands in falls out of the lift-to-npm test, not a coin flip.
- Operationalises the Rule of Three. First write: keep it local. Second use: copy or hoist (your call). Third use: hoisting is forced. The rule is no longer a vibe.
- Coding agents pick targets badly without structure, they dump shared logic in whichever module they edited last. Three named tiers and an upward-only import rule give an agent a decision tree it can't fudge.
Origins
The instinct is older than any of its names. The Rails community has used lib/ since the early 2000s for code that is not specific to the domain of the application: Code Climate's 2012 litmus test was whether you would still use the class if you were building a social network for pet turtles. That is the lift-to-npm test, expressed fourteen years earlier and never given a name beyond folk knowledge.7 Three-Tier Hoisting names what was tribal and adds the middle tier Rails never formalised.
The first published cousin is Martin Fowler's Pull Up Method from Refactoring (1999, 2nd edition 2018): the OOP-inheritance form of the same action, code shared by subclasses moves to the superclass.8 Three-Tier Hoisting is the file-organisation form of the same metaphor: duplicated logic moves to a higher folder. React's “lifting state up” doctrine is the same instinct expressed at runtime: when two components need the same state, the state is lifted to their common ancestor.9
Robert C. Martin's Common Reuse Principle is the load-bearing reason lib/product/ needs to exist as a tier: classes used together are packaged together.2 When several modules import the same product helper, the helper graduates out of any one module into the tier they all already depend on. Without a product/ tier, CRP pushes the helper into one arbitrary module which then becomes an implicit dependency of all the others. Martin's Stable Dependencies Principle supplies the direction: the generic/ → product/ → module gradient is naturally a stability gradient (generic/ changes least, modules change most), so the one-way import rule falls out automatically.10
Feature-Sliced Design (~2018) and Bulletproof React (Alickovic, 2021) are the closest published parallels. FSD's shared/ layer is described as “reusable functionality, especially when it's detached from the specifics of the project / business”, which is lib/generic/ exactly.1 Bulletproof React's rule that “the code should flow in one direction, from shared parts of the code to the application”, lint-enforced via import/no-restricted-paths, is the upward-only import rule under a different name. Three-Tier Hoisting borrows from both, names the middle tier, and adds the growth-as-DRY observation neither has. Every piece (three named tiers, one-way imports, rule of three at the boundary, the lift-to-npm and ubiquitous-language tests) has a precedent. The assembly does not. The shape, the metric and the discipline around the middle tier are mine.
Quotes
Classes that are used together are packaged together.
Duplication is far cheaper than the wrong abstraction.
Slices are intended to divide the layer into business domains, but business domains do not exist in Shared.
You have a method that's identical on subclasses. Move it to the superclass.
Evidence
18 external sources, ranked by author authority. The first five are the canon; expand to see the rest, including the qualifiers and the named opposers. Each links out to its primary source.
- 01Defines `shared/` as reusable functionality detached from project specifics: the closest published equivalent of `lib/generic/`. FSD has no middle tier between `shared/` and the feature folders, which is the gap Three-Tier Hoisting fills.
- 02“The code should flow in one direction, from shared parts of the code to the application”: lint-enforced via `import/no-restricted-paths`. Same upward-only direction. Same gap as FSD on the middle tier.
- 03“Classes that are used together are packaged together.” The reasoning the middle tier is built on: when several modules import the same product helper, the helper graduates out of any one module into the tier they all share.
- 04Dependencies must flow toward more-stable components. The `generic/` → `product/` → module gradient is a stability gradient by construction, so the upward-only import rule falls out for free.
- 05Code shared by subclasses moves to the superclass: the inheritance form of the same metaphor. The vocabulary “pull up” descends from here; Three-Tier Hoisting is the file-system form of the same refactor.
- 06“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” The trigger Three-Tier Hoisting operationalises: once the same knowledge appears in three modules, the rule says hoist.
- 07XP's simplicity rule: every idea is expressed once. The XP camp removes duplication as soon as it appears, a stricter trigger than the third use this tenet waits for. Qualifies the principle from the other side.
- 08“The Wrong Abstraction”Qualifies“Duplication is far cheaper than the wrong abstraction.” The reply Three-Tier Hoisting has to answer: a folder structure that encourages lifting can encourage lifting too soon. Carved out via the rule-of-three trigger.
- 09“AHA Programming”QualifiesAvoid Hasty Abstractions. Restates Metz operationally: prefer duplication until the shape of the abstraction is taught by the duplication itself. Same carve-out as the rule of three. Same effect on the hoisting trigger.
- 10Fowler publishing Don Roberts's rule: refactor on the third occurrence. The single sharpest trigger for hoisting. The rule that prevents premature lifting without giving up on DRY.
- 11Argues that folder hierarchies are a brittle proxy for what counts: interface depth and cognitive load. The reply: the proxy is sound when import direction is lint-enforced and the tier test is operational, not vibes.
- 12The runtime parallel: when two components need the same state, the state is lifted to their common ancestor. Three-Tier Hoisting is the build-time, file-system form of the same instinct.
- 13Distinguishes essential complexity (rooted in the problem) from accidental complexity (introduced by tools). `lib/generic/` houses the accidental; `lib/product/` and the modules house the essential. Brooks names the distinction; Three-Tier Hoisting makes it operational.
- 14The Rails-community lift-to-npm test stated fourteen years before this dossier: code that is “not specific to the domain of the application” belongs in `lib/`. The folk ancestor of `lib/generic/`.
- 15The test for what makes code “product” rather than “generic”: does it name a domain term? Evans is cited for Ubiquitous Language only, not for Generic Subdomain, which is a strategic-design category, not a folder.
- 16Holds the strategic-design context that distinguishes Generic Subdomain (a category in domain modelling) from a utility folder. Useful for the disambiguation: the word “generic” is overloaded. This principle uses the file-system meaning.
- 17Learning Domain-Driven DesignQualifiesModern restatement of the strategic-design vocabulary. Useful for the same disambiguation. Khononov is explicit that Generic Subdomain is a business-modelling category, which is exactly what Three-Tier Hoisting is not.
- 18“Shared Kernel in DDD”QualifiesClarifies that Shared Kernel is a cross-team integration pattern, not a utility-folder convention. Earlier drafts of `code-organisation.md` mislabelled `lib/generic/` as Shared Kernel. The citation has been removed.
Eighteen sources across supports, qualifiers and opposers. The supporters cluster on the upward-only direction: Feature-Sliced Design, Bulletproof React, Martin's component-cohesion canon (CRP + SDP), and Fowler's Pull Up Method. The qualifiers further down hold the steelman the reply has to address: premature hoisting is the wrong abstraction. The one opposer holds that folders are a brittle proxy for coupling; the novelty challenge (“FSD already does this”) rests on the supporters. Both are answered below.
Examples
Before lib/utils/ mixes Tenet-aware and string-only helpers. No tier, no direction.
lib/ utils/ to-slug.tsexport function toSlug(value: string): string { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ utils/ is-tenet-implemented.tssame folder!import { Tenet } from "@/lib/utils/tenet"; export function isTenetImplemented(tenet: Tenet): boolean { return tenet.implementedAt !== null; }
After generic stays generic, product stays product. Imports flow upward only.
lib/ generic/ string/ to-slug.tszero domainexport function toSlug(value: string): string { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ product/ tenet/ get-tenet-slug.tsTenet-awareimport { toSlug } from "@/lib/generic/string/to-slug"; export const getTenetSlug = (tenet: Tenet): string => toSlug(tenet.title);
Before lib/utils/ mixes Tenet-aware and string-only helpers. No tier, no direction.
lib/ utils/ to-slug.tsexport function toSlug(value: string): string { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ utils/ is-tenet-implemented.tssame folder!import { Tenet } from "@/lib/utils/tenet"; export function isTenetImplemented(tenet: Tenet): boolean { return tenet.implementedAt !== null; }
After generic stays generic, product stays product. Imports flow upward only.
lib/ generic/ string/ to-slug.tszero domainexport function toSlug(value: string): string { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ product/ tenet/ get-tenet-slug.tsTenet-awareimport { toSlug } from "@/lib/generic/string/to-slug"; export const getTenetSlug = (tenet: Tenet): string => toSlug(tenet.title);
Before lib/utils/ mixes Tenet-aware and string-only helpers. No tier, no direction.
lib/ utils/ to-slug.jsexport function toSlug(value) { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ utils/ is-tenet-implemented.jssame folder!export function isTenetImplemented(tenet) { return tenet.implementedAt !== null; }
After generic stays generic, product stays product. Imports flow upward only.
lib/ generic/ string/ to-slug.jszero domainexport function toSlug(value) { return value.toLowerCase().replace(/\s+/g, "-"); }
lib/ product/ tenet/ get-tenet-slug.jsTenet-awareimport { toSlug } from "@/lib/generic/string/to-slug"; export const getTenetSlug = (tenet) => toSlug(tenet.title);
Before prickles/utils/ mixes Tenet-aware and string-only helpers. No tier, no direction.
prickles/ utils/ to_slug.pydef to_slug(value: str) -> str: return re.sub(r"\s+", "-", value.lower())
prickles/ utils/ is_tenet_implemented.pysame package!from prickles.utils.tenet import Tenet def is_tenet_implemented(tenet: Tenet) -> bool: return tenet.implemented_at is not None
After generic stays generic, product stays product. Imports flow upward only.
prickles/ generic/ string/ to_slug.pyzero domaindef to_slug(value: str) -> str: return re.sub(r"\s+", "-", value.lower())
prickles/ product/ tenet/ get_tenet_slug.pyTenet-awarefrom prickles.generic.string.to_slug import to_slug def get_tenet_slug(tenet: Tenet) -> str: return to_slug(tenet.title)
Before com.prickles.utils mixes Tenet-aware and string-only helpers. No tier, no direction.
com/ prickles/ utils/ ToSlug.javapackage com.prickles.utils; public class ToSlug { public static String run(String value) { return value.toLowerCase().replaceAll("\\s+", "-"); } }
com/ prickles/ utils/ IsTenetImplemented.javasame package!import com.prickles.utils.Tenet;
After generic stays generic, product stays product. Imports flow upward only.
com/ prickles/ generic/ string/ ToSlug.javazero domainpackage com.prickles.generic.string; public class ToSlug { public static String run(String value) { return value.toLowerCase().replaceAll("\\s+", "-"); } }
com/ prickles/ product/ tenet/ GetTenetSlug.javaTenet-awareimport com.prickles.generic.string.ToSlug;
Before Prickles\Utils mixes Tenet-aware and string-only helpers. No tier, no direction.
src/ Utils/ ToSlug.phpnamespace Prickles\Utils; class ToSlug { public static function run(string $value): string { return preg_replace('/\s+/', '-', strtolower($value)); } }
src/ Utils/ IsTenetImplemented.phpsame namespace!use Prickles\Utils\Tenet;
After generic stays generic, product stays product. Imports flow upward only.
src/ Generic/ StringHelpers/ ToSlug.phpzero domainnamespace Prickles\Generic\StringHelpers; class ToSlug { public static function run(string $value): string { return preg_replace('/\s+/', '-', strtolower($value)); } }
src/ Product/ Tenet/ GetTenetSlug.phpTenet-awareuse Prickles\Generic\StringHelpers\ToSlug;
Enforcement
Apply these rules in eslint.config.mjs. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| import/no-restricted-paths | eslint-plugin-import | any import that crosses a tier boundary in the wrong direction: generic importing product or local code, or product importing local code. |
| import/no-cycle | eslint-plugin-import | import cycles inside any tier: the symptom of a missing extraction or an SRP failure that hoisting has not yet caught. |
| import/no-self-import | eslint-plugin-import | a file importing itself, which usually means a barrel file is being abused. |
| import/no-internal-modules | eslint-plugin-import | deep imports into a module's internals when only the module's barrel was meant to be public: the inverse problem to direct imports, configurable per tier. |
eslint.config.mjsconfiguration snippet
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
export default defineConfig({
files: ['**/*.{ts,tsx}'],
plugins: { import: importPlugin },
settings: {
'import/resolver': { typescript: { project: './tsconfig.json' } },
},
rules: {
'import/no-restricted-paths': ['error', {
zones: [
{
target: './src/lib/generic',
from: './src',
except: ['./lib/generic'],
message: 'lib/generic imports only from lib/generic, generic is portable.',
},
{
target: './src/lib/product',
from: './src',
except: ['./lib/generic', './lib/product'],
message: 'lib/product imports only from lib/generic and lib/product, product is shared, not consumer-coupled.',
},
],
}],
'import/no-cycle': ['error', { maxDepth: 10 }],
'import/no-self-import': 'error',
}
});Apply these rules in eslint.config.mjs. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| import/no-restricted-paths | eslint-plugin-import | any import that crosses a tier boundary in the wrong direction: generic importing product or local code, or product importing local code. |
| import/no-cycle | eslint-plugin-import | import cycles inside any tier: the symptom of a missing extraction or an SRP failure that hoisting has not yet caught. |
| import/no-self-import | eslint-plugin-import | a file importing itself, which usually means a barrel file is being abused. |
| import/no-internal-modules | eslint-plugin-import | deep imports into a module's internals when only the module's barrel was meant to be public: the inverse problem to direct imports, configurable per tier. |
eslint.config.mjsconfiguration snippet
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
export default defineConfig({
files: ['**/*.{ts,tsx}'],
plugins: { import: importPlugin },
settings: {
'import/resolver': { typescript: { project: './tsconfig.json' } },
},
rules: {
'import/no-restricted-paths': ['error', {
zones: [
{
target: './src/lib/generic',
from: './src',
except: ['./lib/generic'],
message: 'lib/generic imports only from lib/generic, generic is portable.',
},
{
target: './src/lib/product',
from: './src',
except: ['./lib/generic', './lib/product'],
message: 'lib/product imports only from lib/generic and lib/product, product is shared, not consumer-coupled.',
},
],
}],
'import/no-cycle': ['error', { maxDepth: 10 }],
'import/no-self-import': 'error',
}
});Apply these rules in eslint.config.mjs. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| import/no-restricted-paths | eslint-plugin-import | tier-boundary violations between lib/generic, lib/product and module folders. |
| import/no-cycle | eslint-plugin-import | import cycles within a tier. |
| forbidden / required dependency rules | dependency-cruiser | the same upward-only flow as a standalone CI step: useful when ESLint isn't the right surface (build scripts, scaffolds, monorepo boundary checks). |
eslint.config.mjsconfiguration snippet
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
export default defineConfig({
files: ['**/*.{ts,tsx}'],
plugins: { import: importPlugin },
settings: {
'import/resolver': { typescript: { project: './tsconfig.json' } },
},
rules: {
'import/no-restricted-paths': ['error', {
zones: [
{
target: './src/lib/generic',
from: './src',
except: ['./lib/generic'],
message: 'lib/generic imports only from lib/generic, generic is portable.',
},
{
target: './src/lib/product',
from: './src',
except: ['./lib/generic', './lib/product'],
message: 'lib/product imports only from lib/generic and lib/product, product is shared, not consumer-coupled.',
},
],
}],
'import/no-cycle': ['error', { maxDepth: 10 }],
'import/no-self-import': 'error',
}
});Apply these rules in .importlinter. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| forbidden contract | import-linter | any import from a forbidden source-to-target combination: the rule that says lib/generic must not import lib/product. |
| layers contract | import-linter | the upward-only stack: generic at the bottom, product in the middle, app on top. Reverse imports become contract failures. |
| independence contract | import-linter | modules that should not know about each other (e.g., two product subdomains) accidentally importing across the boundary. |
| grimp graph queries | grimp | ad-hoc questions about the import graph: what depends on what, where the cycles are, which modules a refactor will touch. |
.importlinterconfiguration snippet
[importlinter]
root_packages =
myapp
[importlinter:contract:generic-imports-nothing-local]
name = lib/generic must not import from product, app, or components
type = forbidden
source_modules =
myapp.lib.generic
forbidden_modules =
myapp.lib.product
myapp.app
myapp.components
[importlinter:contract:product-only-imports-generic]
name = lib/product must not import from app or components
type = forbidden
source_modules =
myapp.lib.product
forbidden_modules =
myapp.app
myapp.components
[importlinter:contract:no-cycles]
name = No import cycles anywhere in the tree
type = layers
layers =
app
components
lib.product
lib.generic
containers =
myappApply these rules in src/test/java/com/example/archtests/ThreeTierHoistingTest.java. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| layeredArchitecture() | ArchUnit | any class that depends on a layer above it in the stack: generic depending on product, product depending on app. |
| noClasses().that().resideInAPackage(...).should().dependOnClassesThat() | ArchUnit | more granular per-package rules: useful when a single layer has internal sub-tiers (e.g., product/domain vs product/application). |
| slices().matching(...).should().beFreeOfCycles() | ArchUnit | import cycles between sub-packages of any tier: the SRP smell hoisting should fix. |
| ImportOption.DoNotIncludeTests | ArchUnit | test code that legitimately reaches across boundaries: excluded so contracts apply to production code only. |
src/test/java/com/example/archtests/ThreeTierHoistingTest.javaconfiguration snippet
package com.example.archtests;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.Architectures.layeredArchitecture;
@AnalyzeClasses(
packages = "com.example",
importOptions = ImportOption.DoNotIncludeTests.class
)
public class ThreeTierHoistingTest {
@ArchTest
static final ArchRule generic_imports_nothing_local =
noClasses().that().resideInAPackage("com.example.generic..")
.should().dependOnClassesThat()
.resideInAnyPackage("com.example.product..", "com.example.app..");
@ArchTest
static final ArchRule product_does_not_depend_on_app =
noClasses().that().resideInAPackage("com.example.product..")
.should().dependOnClassesThat()
.resideInAPackage("com.example.app..");
@ArchTest
static final ArchRule layers_flow_upward =
layeredArchitecture().consideringAllDependencies()
.layer("Generic").definedBy("com.example.generic..")
.layer("Product").definedBy("com.example.product..")
.layer("App").definedBy("com.example.app..")
.whereLayer("App").mayNotBeAccessedByAnyLayer()
.whereLayer("Product").mayOnlyBeAccessedByLayers("App")
.whereLayer("Generic").mayOnlyBeAccessedByLayers("Product", "App");
}Apply these rules in deptrac.yaml. The full enforcement across every tenet lives on the implementation page.
| Rule | Tool | Catches |
|---|---|---|
| layers + ruleset | Deptrac | any class in one layer that depends on a layer above it: the upward-only rule expressed as a graph. |
| directory collector | Deptrac | namespaces that drift out of their assigned tier: useful when the file path is the source of truth, not the namespace. |
| should-not-depend-on rules | PHPArkitect | the same upward-only rule expressed in PHP rather than YAML: useful for repos that already lean fluent. |
| ruleset (one direction only) | Deptrac | circular dependencies between any two namespaces in the project: usually a sign that two modules need a shared piece in lib/product/. |
deptrac.yamlconfiguration snippet
deptrac:
paths:
- ./src
layers:
- name: Generic
collectors:
- type: directory
value: src/Lib/Generic/.*
- name: Product
collectors:
- type: directory
value: src/Lib/Product/.*
- name: App
collectors:
- type: directory
value: src/(App|Controller|Component)/.*
ruleset:
Generic: ~
Product:
- Generic
App:
- Product
- GenericAI rules
.cursor/rules/a2-three-tier-hoisting.mdc--- alwaysApply: true --- ## Prickles A2: Three-Tier Hoisting Default to local. A new helper lives next to the consumer until a second consumer earns the move. On the third repeat, hoist. To `lib/generic/` if the file would compile after `npm publish` with no edits. To `lib/product/` if it still names a Tenet, a Pillar, or any other word from the product's ubiquitous language. Imports flow upward only. A module may import from `product/` and `generic/`; `product/` may import from `generic/`; `generic/` imports neither. Reverse the direction and the build fails. If the abstraction's shape is unclear after two uses, leave it duplicated for one more iteration. Premature hoisting costs more than the duplication it would eliminate.
Repo layout, CI, and ESLint wiring for these paths live on /implementation, not repeated on every tenet.
Counter-argument
The strongest steelman is Sandi Metz's.3 Premature hoisting is more expensive than duplication: two functions that look alike today often diverge in different directions tomorrow. The abstraction extracted from today's overlap becomes a cage that distorts both callers. Hoist too early and the cost is paid twice: once to build the wrong abstraction, once to dismantle it. Kent C. Dodds makes the same point as “AHA programming”: avoid hasty abstractions. Let the duplication surface the shape.4 The implication for Three-Tier Hoisting is sharp: a folder structure that encourages lifting can encourage lifting too soon.
Counter-argument retort
Metz is right about premature abstraction. The rule of three is the carve-out. Every helper starts inside the module that needs it. The first time a second module reaches for the same helper, the decision is open: copy (rule of three says fine, the same helper has been seen twice) or hoist. By the third repeat the answer is forced. Where the shape is genuinely unclear (two callers using the same helper for visibly different reasons) the dossier's explicit instruction is to leave it duplicated for one more iteration. The wrong abstraction costs more than the duplication it was eliminating. This rule agrees and refuses to reach for the tier before the duplication has surfaced which tier is right.3
The Ousterhout-style objection (folder hierarchies are a brittle proxy for coupling) is sharper.5 Folders can lie. Two files in the same folder may be loosely coupled. Two files in opposite corners of the tree may share state through a singleton. The reply is that the proxy is sound when two things are true: the import-direction rule is lint-enforced (so reverse couplings show up as build errors, not vibes) and the tier test is operational (the lift-to-npm test for generic/, the ubiquitous-language test for product/). Both are concrete, both are checkable. The proxy is no longer brittle when the test it stands on is a script.
The novelty challenge (“Feature-Sliced Design and Bulletproof React already do this, this is just renaming”) is the challenge I take most seriously, because both projects are excellent and explicitly cited as influences. The honest answer is that neither has the middle tier. FSD's shared/ is generic/ exactly. Its upper layers ( entities/, features/, widgets/) are a UI composition hierarchy rather than a cross-module hoisting tier. Bulletproof React has the same gap: shared/ and features/, nothing in between. Martin's CRP supplies the reasoning a middle tier needs;2 no published architecture I've seen turns it into a named folder. The growth-as-DRY observation is not in either either.
The genuine residue is the Evans confusion. Earlier drafts of this rule cited Generic Subdomain from Domain-Driven Design; that citation was wrong. Evans's Generic Subdomain is a category in strategic domain modelling: capabilities every business needs but is not its specialty.6 Three-Tier Hoisting is not domain modelling. It is file-and-import organisation by domain awareness. The word “generic” matched. The concept beneath it did not. The Evans citation has been removed. See A6 Bounded Contexts for the DDD overlap that does exist.
Notes
- [1]Feature-Sliced Design / Bulletproof React: FSD: “Reusable functionality, especially when it's detached from the specifics of the project / business — business domains do not exist in Shared.” Bulletproof React: “The code should flow in one direction, from shared parts of the code to the application.” Both define `shared/`; neither defines a middle tier.
- [2]Robert C. Martin: Clean Architecture (Prentice Hall, 2017), Ch. 13: Common Reuse Principle, “Classes that are used together are packaged together.” The reasoning behind `lib/product/` as a named tier.
- [3]Sandi Metz: “The Wrong Abstraction” (2016): “Duplication is far cheaper than the wrong abstraction.” The strongest steelman against any rule that encourages lifting. Carved out via the rule of three.
- [4]Kent C. Dodds: “AHA Programming” (2019): “Avoid Hasty Abstractions.” Restates Metz operationally. Argues for prefer-duplication-until-the-shape-is-clear, which is exactly the rule-of-three trigger.
- [5]John Ousterhout: A Philosophy of Software Design (2018, 2nd ed. 2021). Argues folder hierarchies are weak proxies for the concern that counts (interface depth, cognitive load). The reply: the proxy is sound when the import-direction rule is lint-enforced and the tier test is operational.
- [6]Eric Evans: Domain-Driven Design (Addison-Wesley, 2003), Ch. 15: Generic Subdomain. A strategic-design category: capabilities every business needs but isn't its specialty (money, time zones, identity, accounting). Cited only to disambiguate. This is not what Three-Tier Hoisting is.
- [7]Code Climate Blog (Rails community): “What Code Goes in the Lib/ Directory?” (2012). The Rails-community lift-to-npm test, expressed fourteen years before this dossier and never given a name beyond folk knowledge.
- [8]Martin Fowler: Refactoring, 2nd ed. (Addison-Wesley, 2018). Pull Up Method / Pull Up Field: code shared by subclasses moves to the superclass. The OOP-inheritance form of the same metaphor. Canonical source for the word “pull up” in this sense.
- [9]React core team: “Sharing State Between Components” (formerly “Lifting State Up”). The runtime parallel: when two components need the same state, the state is lifted to their common ancestor.
- [10]Robert C. Martin: Clean Architecture (2017), Ch. 14: Stable Dependencies Principle. Dependencies must flow toward more-stable components: the import-direction rule for `generic/` → `product/` → module.