Skip to content
Stack Builder

Ports and adapters

The ports a stack's slots expose, the adapters that fill them, and why a switch leaves the pages alone.

Ports

A port is the promise a slot makes to the files that use it: the names it exports and the shape they take. The page, the API client and the feature routers only ever use that promise, never the file behind it.

The layout gives each port its path, and every stack places the same ports. Only the files inside them differ.

Adapters

An adapter is the code one choice writes into the ports. Drizzle and Prisma each write the database client, the schema and the migrations their own way; oRPC, tRPC and Hono each write the router and the client that calls it.

An adapter keeps the port's shape. That is why a page or a router reads the same whichever adapter fills the layer below it, and why the figure below can show one API style against another.

The registry

The registry is the catalog of choices: every option, the note that says why you would pick it, and the rules that guard it. The builder offers only the options the rules allow.

The Options and Compatibility pages read the same catalog and rules, so the docs cannot drift from what the builder does.

Switching an adapter

The rule: switching an adapter never edits a page or a router. Switching the ORM rewrites the database files and leaves the rest of the stack as it was.

The figure generates the stack once for each ORM, in the browser, and shows the port and its adapter side by side. The files marked as the same in both are the ones that never move.

When to add a port

The rule: add a port only when two implementations warrant it. A second ORM, a second API style or a second storage provider is a reason; a port with one implementation is only a layer to read through.

The Add a feature page shows where a port sits among the files a feature adds.

What a port is not

A port is not a wrapper named after a vendor. Its names say what the feature needs, such as TodoRepo; a name such as DrizzleClient or PrismaTodo describes a vendor, and a vendor's own calls belong in its adapter.