Architectural Layers Should Change the Abstraction, Not Just the Filename
A checkout screen has to show a price or tell the shopper that their quote has expired. Somewhere between the button and the server, the application must turn a remote response into that decision.
Now suppose you are the engineer tracing this path in an unfamiliar codebase. You open the checkout service. It calls a repository. The repository calls a client. Each method is named getQuote, takes the same arguments, and returns the same object. After three files, you are still looking for the code that explains what checkout should do.
This illustrative request exposes a cost that a folder diagram can hide: a layer can add another place to navigate without giving its caller a simpler problem.
Layering is useful when it divides responsibilities. A network client can understand the remote protocol, an adapter can interpret the response in checkout terms, and the screen can decide what to show. Those are meaningful boundaries because each reader can stop thinking about work assigned to another owner.
We will trace the forwarding chain in TypeScript, replace it with a checkout boundary that answers the screen's question, and examine a short dispatcher that deserves to stay. The aim is to judge a layer by the responsibility it accepts, including cases where its signature barely changes.
On this page
Follow the Operation Through the Layers
Start at the bottom of the trace. The checkout client communicates with a remote API and returns a validated transport representation:
type RequestOptions = { signal: AbortSignal }
type QuoteWire = {
quote_id: string
total_minor: number
currency: string
state: 'OPEN' | 'EXPIRED'
expires_at: string
}
type CheckoutClient = {
getQuote(cartId: string, options: RequestOptions): Promise<QuoteWire>
}
function createCheckoutRepository(client: CheckoutClient) {
return {
getQuote(cartId: string, options: RequestOptions) {
return client.getQuote(cartId, options)
},
}
}
function createCheckoutService(
repository: ReturnType<typeof createCheckoutRepository>,
) {
return {
getQuote(cartId: string, options: RequestOptions) {
return repository.getQuote(cartId, options)
},
}
}
The client's implementation is omitted; we need its contract to evaluate the layers above it. Here it owns HTTP handling, decoding, and runtime validation: total_minor is a nonnegative safe integer, the currency is accepted by the application, and expires_at is a valid timestamp. A TypeScript annotation alone does not establish those properties.
The client contributes real work. The repository and service, as shown, contribute no additional behavior or interpretation. A caller reaching either still receives API field names, a transport state, and a timestamp string.
That leaves the engineer tracing checkout with two bills to pay. Understanding the operation requires following each forwarding hop. Changing its signature requires synchronized edits through the same chain. Tests can confirm that each hop passes arguments correctly while leaving the reason for those hops unanswered.
These pass-through methods duplicate a responsibility rather than dividing it clearly. It is a reason to investigate the design, not an instruction to delete every short function.
The names service and repository do not supply the missing responsibilities. If this application needs neither domain orchestration nor persistence abstraction at this boundary, both layers may be unnecessary.
Give the Checkout Boundary Its Own Meaning
Return to the screen's original decision: show a usable quote or explain that it has expired. That is more specific than “what JSON did the API return?” It gives the missing application boundary a job.
That gives a possible application interface:
type CheckoutQuote = {
id: string
total: { minorUnits: number; currency: string }
expiresAt: Date
}
type QuoteResult = { kind: 'ready'; quote: CheckoutQuote } | { kind: 'expired' }
type CheckoutQuotes = {
forCart(cartId: string, options: RequestOptions): Promise<QuoteResult>
}
function createCheckoutQuotes(client: CheckoutClient): CheckoutQuotes {
return {
async forCart(cartId, options) {
const wire = await client.getQuote(cartId, options)
if (wire.state === 'EXPIRED') {
return { kind: 'expired' }
}
return {
kind: 'ready',
quote: {
id: wire.quote_id,
total: {
minorUnits: wire.total_minor,
currency: wire.currency,
},
expiresAt: new Date(wire.expires_at),
},
}
},
}
}
This adapter accepts a coherent responsibility: interpreting the transport representation as the application's checkout result. It preserves monetary values in minor units, translates the remote state into an explicit result, and presents a timestamp in the representation this application has chosen.
The example keeps transport failures as rejected promises and forwards cancellation unchanged. Those are deliberate parts of the boundary's contract. It does not implement caching, retries, payment submission, or a complete checkout workflow.
It also does not promise that a quote remains usable indefinitely. A ready result describes the state returned by the server; time can pass, and the server must enforce validity when an order is submitted. Translation cannot remove that product constraint.
Now the request has meaningful steps. The checkout boundary answers a domain question. The client carries out the remote protocol. The HTTP mechanism underneath transfers requests and responses. Each can explain its job without borrowing the neighboring layer's description.
Adding another class that simply forwards forCart would require another justification. The useful abstraction is already available.
A Matching Signature Can Still Do Important Work
It would be easy to turn this repair into a rule that deletes every one-line forwarding method. The next short function shows why that would be a mistake.
Dispatchers provide an important counterexample. A dispatcher may accept the same arguments as its destinations while contributing the decision about which destination should handle the operation.
Suppose an application has several configured quote providers. An existing selection mechanism determines which provider owns a cart:
function routeCheckoutQuotes(
selectProvider: (cartId: string) => CheckoutQuotes,
): CheckoutQuotes {
return {
forCart(cartId, options) {
return selectProvider(cartId).forCart(cartId, options)
},
}
}
This function is intentionally short. Its responsibility is selection, while a provider's responsibility is producing the quote. Removing the dispatcher would move selection into its callers or another owner; the decision would still need to happen.
The callback represents an already defined routing policy, not permission to guess a provider from a convenient string convention. A real application must establish how cart ownership and provider configuration are resolved.
Likewise, multiple implementations of one interface can reduce what callers need to learn. Two providers exposing forCart are alternatives at one boundary. That differs from stacking several providers that merely call one another without contributing anything.
Evaluate the responsibility, including behavior absent from the signature. A type-level difference is neither required nor sufficient to prove that a layer is useful.
Distinguish Adapters From Collections of Wrappers
An adapter translates between interfaces or representations. A decorator generally retains an existing interface while adding behavior. Both can be implemented with objects or ordinary functions.
The checkout adapter is useful because the application and remote system speak in different terms. Its value is not that snake case becomes camel case; it establishes the meaning of a checkout result and the representation consumers can depend on.
An object that returns { wire: response } while every screen still interprets wire.state has accomplished much less. The application's question still has to be answered elsewhere.
Decorators can produce many shallow classes, each adding a small feature and forwarding everything else. Before introducing another wrapper, consider whether its behavior naturally belongs in the existing implementation, in its particular caller, or in a useful existing wrapper.
For example, behavior needed by nearly every consumer may fit the underlying operation. Behavior specific to one screen may fit that screen. A fixed external API may justify a separate adapter because the application cannot change that external interface.
The request is still our guide. Combining everything into one client would make transport mechanics depend on unrelated product behavior. Giving every tiny behavior its own wrapper can make the real operation hard to locate again. After either change, retrace checkout and see whether each stop answers a question the caller actually had.
Let the Public Abstraction Differ From the Storage Mechanism
The same reasoning applies inside a module. Its interface should express useful operations, rather than merely expose the units in which its implementation happens to work.
A text editor makes the distinction concrete. Text stored internally as lines need not force callers to split and join lines whenever they insert a character or delete a range. The implementation can manage lines while its interface provides operations in the terms callers need.
In the checkout example, a transport timestamp string is convenient for a remote representation. That does not require every screen to parse it. Conversely, choosing Date for the application is a decision to document and reconsider if consumers need different time semantics.
The goal is a useful translation, not cosmetic distance between types. An interface with different names can still require callers to reconstruct the implementation's logic.
Put Dependencies Where They Are Used
Arguments can also pass through layers that have no use for them. A client may need a base URL, while a screen and several intermediate functions merely relay it.
One option is to configure the client where the application is assembled and inject that configured dependency into the checkout adapter. The screen then supplies information belonging to its current operation, such as the cart and cancellation signal.
This distinction matters. A base URL configured for a client instance and a signal representing one interaction have different owners and lifetimes. Removing both from method signatures indiscriminately would conceal information that callers still need to control.
Per-system context objects can avoid repeatedly threading shared information through methods. They also have drawbacks: a context can accumulate unrelated data and create dependencies that are hard to discover.
A TypeScript ApplicationContext containing database access, configuration, logging, feature flags, and every client can shorten constructors while leaving a module able to depend on almost anything. A narrower dependency such as CheckoutClient makes the relationship easier to inspect and replace.
Use a context deliberately when there is a coherent shared lifetime and a clear ownership model. Keep request-specific information scoped to its request. A context object in a design discussion is not automatically a recommendation to use a particular UI framework's context mechanism.
Explicit parameters remain appropriate when the receiving operation actually needs the decision they represent. Constructor injection remains useful for dependencies stable across many calls. Neither technique earns its place simply by reducing the number of arguments visible in one function.
Review One Real Path
Choose a request in the application and write a sentence describing each layer it crosses. Describe the responsibility without using its class or folder name as the explanation.
Then ask:
- What does this layer decide, translate, coordinate, or guarantee?
- What knowledge would return to callers if the layer disappeared?
- Does it expose an operation in caller terms, or repeat its dependency's interface?
- Are matching signatures supporting distinct behavior or merely relaying a call?
- Do its dependencies reveal the information it uses and the lifetime it assumes?
Some layers will have clear answers. Others may be removed, combined, or given a more coherent division of work. A warning about forwarding does not dictate one universal repair.
For our checkout trace, keep the validated client, the adapter that produces ready or expired, and a dispatcher if provider selection is required. Remove the empty forwarding hops unless another real responsibility justifies them.
An engineer arriving to change the expired-quote behavior now has a place to start. They can read the checkout contract without opening every transport detail, and follow further only when the change actually concerns the protocol. That reduction in required navigation is the benefit the extra boundary should earn.
