Dependency Violations: Two Harmless-Looking Imports
A shared enum pulled from a tool and a tool that calls another tool: two one-line imports that quietly break the dependency rules of LVD.
The pull request is eleven lines long. A late-fee function in the utilities folder needs a due date, so its author imports the loan store and fetches one. Tests pass, the reviewer is busy, and it merges. That small import has just reversed the direction in which your whole architecture is supposed to lean.
Axiom A2 says dependencies run one way: from layers that change often towards layers that change rarely. Tools may use Resources, Resources may use Utils, and nothing flows back up. An upward import means a stable layer now leans on a more volatile one, so it inherits that volatility and the gradient the model depends on is inverted.
The book treats dependency violations as the most damaging class of anti-pattern. They rarely come from carelessness about architecture. They come from convenience: the data is right there, so the code reaches for it.
Here is the mistake in a library-lending system:
// L2 Utils: the violation
import { loanStore } from "../../resources/loanStore";
export async function lateFee(loanId: string, today: Date) {
const loan = await loanStore.find(loanId); // I/O inside Utils
const daysLate = daysBetween(loan.dueDate, today);
return daysLate > 0 ? Math.min(daysLate * 0.25, 10) : 0;
}
Utils (ν 0.4) is home to pure, deterministic functions: inputs in, answer out, nothing else. This one now performs I/O, depends on whatever state the database is in, and can fail for reasons unrelated to fee arithmetic, such as a timeout or an exhausted connection pool. Everything that imports lateFee inherits a dependency on Resources (ν 0.6) whether it wanted one or not.
None of these shows up in the pull request. They show up months later, spread across teams who never saw the original change.
Push the fetching up to the caller, and hand the function only the facts it needs:
// L2 Utils: pure again
export function lateFee(dueDate: Date, today: Date): number {
const daysLate = daysBetween(dueDate, today);
return daysLate > 0 ? Math.min(daysLate * 0.25, 10) : 0;
}
// L4 Tool: loads through a Resource, then calls the pure function
const loan = await loanStore.find(loanId);
return lateFee(loan.dueDate, new Date());
The job of loading the record belongs to a Tool, which reaches data through a Resource. The utility becomes synchronous and deterministic, and you can test it with a plain function call and a handful of dates.
A cheap smell test is to search the Utils folder for async, await and any import path that mentions Resources. Each hit deserves a question. The book's review checklist asks the purity question directly (no side effects, no I/O, no asynchronous operations), and a lint rule can forbid upward imports outright; see lvd-lint for how that is wired in.
An upward import is never expensive at the moment you write it. It is expensive because a layer that was meant to be stable becomes exactly as fragile as the thing it imported. If you want the full list of rules this one belongs to, start with the rules of LVD and the Utils layer. Then look at the subtler variants, where the import is even smaller and easier to wave through.