/engineering-paved-path:onion-architecturefrom Engineering Paved Path
Onion / ports-and-adapters / layered architecture for a TypeScript/Node backend (Fastify modules plus a pure domain core) — deciding WHICH ring backend code belongs in and WHICH WAY its dependencies may point. Use this skill WHENEVER working server-side: adding or changing a route/service/repository, adding an adapter or port, wiring something into the DI Container, deciding whether a route or service may import Drizzle / an SDK / another module, or reviewing the backend's layering — even when the user does not say 'onion' or 'architecture'. It enforces the inward dependency rule, the ports-in-shared / implementations-in-adapters split, the Container as the single composition root, Drizzle-queries-only-in-the-repository, and the Zod contracts in your shared package as the shared domain + boundary type. Backend structure and boundaries only — not Drizzle query syntax (use engineering-paved-path:drizzle-orm-patterns), Fastify route mechanics (use engineering-paved-path:fastify-best-practices), Postgres schema design (use engineering-paved-path:postgresql-table-design), Zod syntax (use engineering-paved-path:zod), or frontend layout (use engineering-paved-path:frontend-ui-architecture).
Trending skills
7-day visitors to each skill page
Ships in Engineering Paved Path. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Decisions about which ring backend code lives in and which way its dependencies may point for your Fastify modules and the pure domain core. A well-structured backend is onion-shaped (ports-and-adapters behind a DI Container) — this skill makes that structure explicit and enforces it on every new or changed module so the layering does not erode.
This skill is about boundaries and placement, not syntax. For Drizzle queries use engineering-paved-path:drizzle-orm-patterns; for Fastify route mechanics use engineering-paved-path:fastify-best-practices; for Postgres schema design use engineering-paved-path:postgresql-table-design; for Zod syntax use engineering-paved-path:zod.
The calls this paved path settles for you. When tempted to answer "it depends," default to these.
routes → service → repository → db, and service → Container → adapter (via a port). The domain core depends on nothing outer; the pure core is the proof — it
runs with no Fastify and no DB.shared/adapters.ts); concrete adapters live in adapters/*.
To add a capability, define the interface first, implement it outside, then wire it in the Container.platform/container.ts) is the only composition root. Services receive
Container and pull adapters off it (await container.llm(id), container.git,
container.secrets.get(...)). Never new a concrete adapter in a service or route, and never
read process.env for a key — go through container.secrets.drizzle-orm / db/schema imports and query
building stay in repository.ts (and the colocated repository/<aggregate>.repo.ts), every query
scoped by your tenant key (e.g. workspace_id). Routes and services never build a query. (Row
types from db/rows.ts may flow up as the persistence model — see persistence-and-contracts.md.)safeParse on untrusted input); map persistence rows to a contract DTO before
returning over HTTP.routes.ts → service.ts → repository.ts + helpers.ts /
constants.ts), registered once in your module registration barrel (e.g. modules/index.ts). No
sibling-module imports — share cross-cutting data access via a repository on the Container (e.g.
container.<x>Repo).Load on demand — keep this file in context, open a reference only when the task needs that depth.
| Ring (outer → inner) | What | Where |
|---|---|---|
| Presentation | Fastify route plugins — thin HTTP glue | modules/<name>/routes.ts (registered in modules/index.ts) |
| Infrastructure | adapter implementations + DI wiring + DB access | adapters/*, platform/* (Container, jobs, sse, errors, config), db/* |
| Application | use-cases / orchestration + the data-access facade | modules/<name>/service.ts, repository.ts (+ repository/*.repo.ts) |
| Domain core | Zod contracts + adapter interfaces (ports); the pure engine | your shared package's contracts/* and adapters.ts (ports); the pure domain core |
The inversion that makes it an onion: the port (adapters.ts in your shared package) sits in the
innermost ring, its implementation in adapters/ in the outer ring. Inner defines the interface;
outer implements it; the Container injects the concrete at the edge.
Apply in order; each answers a "where does this belong?" question.
adapters.ts), implement it in adapters/<kind>/, resolve it via the Container.
Never make the call inline.repository.ts (or a repository/<aggregate>.repo.ts), scoped by your
tenant key (e.g. workspace_id). Nowhere else.service.ts, depending on Container + the
repository, not on concrete adapters.contracts/*),
used schema-first in routes.ts (declare it in the route schema; do not hand-roll .parse).fs); its only side effects come through injected
ports.platform/container.ts, the composition root — the one place allowed to import concrete adapters
and module repositories.The inward rule, made concrete. Full table with rationale in references/dependency-rules.md.
routes.ts → its own service.ts, your shared contracts, platform/errors, the
request-context helper. Not drizzle-orm/db/schema, an adapter implementation, or another
module's internals.service.ts → Container (type), its repository.ts, your shared contracts + ports, the domain
core, platform/errors, its own helpers/constants. Not drizzle-orm/db/schema (no
queries), a concrete adapter class (get it off the Container), Fastify types, or a sibling module's
service/repository (use container.<x>Repo).repository.ts → db/client, db/schema, db/rows, drizzle-orm, your shared contracts. The
only ring that imports Drizzle.adapters/* → its SDK, the port interface from your shared package, platform/errors. It
implements the port. Not a module's service/repository, not Fastify.zod and other shared contracts. Nothing else — no
Drizzle, no Fastify, no adapters, no SDKs.zod + its own internals. Never imports from an
outer ring (routes, adapters, db, platform) — that would make the core depend on an outer ring.platform/container.ts → everything concrete. The composition root wires it all.modules/<name>/ with routes.ts, service.ts, repository.ts (add helpers.ts /
constants.ts as needed). ESM relative imports carry the .js extension.contracts/*) (or reuse
existing).repository.ts owns all Drizzle for the module; scope every query by your tenant key (e.g.
workspace_id).service.ts takes Container in its constructor; call the repository and pull adapters off the
Container. No new Adapter(...), no process.env.routes.ts is a Fastify plugin: schema-first validation, resolve getContext() for
{ workspaceId, userId }, throw AppError/NotFoundError/ValidationError/ConfigError,
delegate to the service, and map rows → a contract DTO before returning.modules/index.ts) — one import
app.register.adapters.ts) — the port, a plain TS interface.adapters/<kind>/<impl>.ts.ContainerOverrides + a lazy getter in platform/container.ts (resolve secrets there,
not in callers).adapters/mocks.ts so tests inject it via your test-app bootstrap
(buildApp({ overrides })).import ... from 'drizzle-orm' or db/schema in a routes.ts or service.ts → a query
escaped the repository. Move it into repository.ts.new <ConcreteAdapter>(...) (any adapter class) in a service/route → bypasses the Container.
Resolve it via container.<x>.process.env.<KEY> for a secret in a handler/service → must go through
container.secrets.get(...); secrets are never logged.import { ... } from '../<other>/service.js' → a cross-module reach. Use a repository on the
Container, or lift the shared piece to the Container.$inferSelect from a route → map to a Zod-contract DTO (e.g.
helpers.ts) at the HTTP seam.import ... from 'fastify' (or any outer-ring import) inside the domain core or a shared
contract → framework/outer ring leaked into the core.fetch / axios / SDK call in a service or route → wrap it behind a port in
adapters.ts instead.Schema.parse(req.body) in a handler → declare the schema in the route schema
(fastify-type-provider-zod 422s invalid input before the handler).adapters.ts and a mock
in mocks.ts, or it cannot be unit-tested.What SKILL.md sets; muted values are Claude Code's defaults
Trigger phrases: 'where does this backend logic / query go', 'can a route or service import the db / Drizzle', 'add a new server module', 'add an adapter / external integration', 'wire this into the container', 'should the service know about Fastify', 'is this module's layering right', 'review the backend architecture', 'how do I keep the core pure', 'where do the Zod contracts go'.
npx claudepluginhub rostk/my-monkeys --plugin engineering-paved-path13 skills in this plugin
/drizzle-orm-patternsProvides comprehensive Drizzle ORM patterns for schema definition, CRUD operations, relations, queries, transactions, and migrations. Proactively use for any Drizzle ORM development including defining database schemas, writing type-safe queries, implementing relations, managing transactions, and setting up migrations with Drizzle Kit. Supports PostgreSQL, MySQL, SQLite, MSSQL, and CockroachDB./engineering-insightsCaptures durable engineering learnings to the touched module's learnings file (LEARNINGS.md by default, configurable). Use at the end of a substantive session (>30 min with a real problem, decision, or discovery) as a wrap-up, or mid-session when something non-obvious surfaces. Re-reads the target file first, then appends actionable-cold notes; never overwrites and never duplicates./fastify-best-practicesGuides development of Fastify Node.js backend servers and REST APIs using TypeScript or JavaScript. Use when building, configuring, or debugging a Fastify application — including defining routes, implementing plugins, setting up JSON Schema validation, handling errors, optimising performance, managing authentication, configuring CORS and security headers, integrating databases, working with WebSockets, and deploying to production. Covers the full Fastify request lifecycle (hooks, serialization, logging with Pino) and TypeScript integration via strip types. Trigger terms: Fastify, Node.js server, REST API, API routes, backend framework, fastify.config, server.ts, app.ts./frontend-ui-architectureFrontend UI architecture and code organization for React & Next.js — deciding WHERE code should live (folder/file structure, feature- vs type-based layout, colocation, where components / hooks / business logic / utils / constants / types / Server Actions belong, module boundaries and imports, and organizing the Server/Client boundary). Use this skill WHENEVER the user asks how to structure or organize a React/Next.js project, where a file/component/hook/type should go, how to split a large component, where to put business logic or data access, utils-vs-lib-vs-helpers, or barrel files — or asks for an architecture/structure review — even if they don't say the word 'architecture' and even though such questions can look answerable directly. Structure & organization only — not in-component coding rules (use react-best-practices) or Next.js API/feature mechanics (use next-best-practices)./next-best-practicesNext.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling/postgresql-table-designUse this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced featuresOther plugins' skills for the same job