How the Bottom Layers Interact
Trace three kinds of change through a tool that uses Schema, Utils and Resources, and see why the two bottom layers earn the heaviest testing.
A function that decides whether ticket sales are open looks harmless: compare the opening time with new Date() and return the answer. But it quietly reads a clock nobody can see, so a test that passes at noon fails at midnight and no one can say why. The Utils layer collects the opposite kind of function, one whose signature tells you everything it depends on.
Utils is layer two, with a volatility of 0.4, and the book defines its residents strictly. A function is pure when the same inputs always produce the same output and when it has no side effects. It does not modify its arguments, perform I/O, touch global state, or generate random numbers without a seed. A pleasant consequence is that chaining pure functions gives you another pure function, so large calculations can be assembled from small ones without losing the guarantee.
The payoffs are ordinary and they add up. Tests become plain assertions, calls are safe to run in parallel, results can be cached, and a reader can understand a function without hunting for whatever else it touches.
In practice, purity mostly means pushing hidden inputs into the parameter list. Time, rates, configuration and randomness arrive as arguments instead of being fetched from somewhere:
// Hidden input: the system clock
export const isOnSaleNow = (opensAt: Date, closesAt: Date) =>
new Date() >= opensAt && new Date() < closesAt;
// Everything it needs is in the signature
export const isOnSale = (now: Date, opensAt: Date, closesAt: Date) =>
now >= opensAt && now < closesAt;
The second version can be tested with three literal dates and no setup. It can also be reused by a server, a browser and a batch job without any of them agreeing on what "now" means.
The layer's other constraint is about direction. Utils may depend only on Schema, which means a utility can take a domain type as an argument but cannot reach into a repository or a tool. That keeps it foundational: Resources, Tools and the UI can all call it without dragging anything else along. The book sorts the usual residents into four families, namely formatters, validators, transformers and calculators.
Sort a utilities folder by technical kind and you get math.ts, strings.ts, dates.ts and validators.ts. It sounds tidy and quickly turns into a drawer of unrelated things. The book groups by business domain instead: pricing, inventory, orders and so on. It names three benefits. Related functions stay together, you know where to look, and each domain has an obvious owner.
There is one practical wrinkle. The UI layer imports Utils directly, so anything that relies on a server-only runtime API, such as Node's file system or crypto modules, is not portable. The book keeps those functions apart under their own path and uses lvd-lint to deny that path to the UI.
Foundations should be easy to read, so the book caps cyclomatic complexity at six per function. For scale, a function that just adds two numbers scores one, and every extra if, else if or loop adds a point. Cyclomatic complexity counts the independent paths through a function, and a quick estimate is one plus the number of decision points. When a function goes over, you split its branches into smaller named functions, each of which is still pure.
The layer also carries a strict testing target: 100% statement, branch and function coverage. Property-based testing, where you state a rule that must hold across many generated inputs, is the book's suggested complement for functions that are better described by a rule than by examples.
A utility library tends to rot when nobody can say what belongs in it. The purity rule, the domain folders and the complexity cap are three concrete answers to that question.
If a function can be called twice with the same arguments and surprise you, it does not belong in Utils. Keep the layer pure, group it by the business it serves, and keep each function small enough to read at a glance. Then follow the layer into practice in how the bottom layers interact, or see its place in the stack on the layer page.