/engineering-paved-path:frontend-ui-architecturefrom engineering-paved-path
Architecture and code-organization rules for a React / Next.js (App Router) frontend: where components, hooks, constants, helpers, styles, types, tests and business logic live, how to split a component, which layers may import which, and where the server/client boundary goes. Use whenever creating, moving, splitting or reviewing UI code — a new page, feature or _components/<Name> folder, a component that keeps growing, 'where should this constant/helper/hook/type go', restructuring, or a structure-focused PR review — even if the user never says 'architecture'. Not for effects/memoization/keys/a11y (react-best-practices), Next.js APIs (next-best-practices), test technique (react-testing-library), or Zod.
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.
How UI code is organized in a React frontend (examples: Next.js App Router, React 19, TanStack Query against a separate HTTP API): where each kind of code lives, when to split, and which way dependencies point.
The principles are general. The paths below use a neutral sample application — an admin UI
for a commerce API with routes such as app/orders/, app/orders/[orderId]/ and app/customers/,
shared UI in src/components/, non-visual shared code in src/lib/, and the design-system and
contracts packages vendored or installed as @acme/ui and @acme/contracts (placeholders for your
own). Map them onto your project's folders before applying a rule — see
project-mapping.
Version 2.0.0 — sources, rationale and history are in README.md.
Restating rules that another skill already owns creates two sources of truth that drift apart. Link instead.
| Question | Owner |
|---|---|
Where does this file / constant / helper / hook / type / test live? How do I split it? Which layer may import which? Where does 'use client' go? | this skill |
| Effects, derived state, memoization, keys, conditional rendering, a11y, error boundaries, size limits | react-best-practices |
Next.js APIs: async params, metadata, route handlers, RSC serialization errors, image/font | next-best-practices |
| How to write component tests | react-testing-library |
| Schemas and contracts | zod, your shared contracts package |
| How your app is wired end to end | your project's UI architecture doc / agent guide, if it has one |
Precedence when guidance conflicts: your project's own written frontend rules > this skill > generic advice.
shared/ folder created "just in case"
becomes a dumping ground. Start inside the file, then the component folder, then
the route, then src/components / src/lib. If two uses look alike but the shared
shape isn't obvious yet, tolerate the duplicate — a wrong abstraction costs more
than a copy.lib ← components ← app. A route
never imports another route's _components; if two routes need it, promote it.
This is what keeps a feature deletable and a refactor local.format-money.ts and order-urls.ts tell you
what is inside; utils.ts, misc.ts, common/ do not, and they grow forever.index.ts; nothing
outside imports its internals. Do not add barrels that aggregate many folders.| You have… | It goes in… |
|---|---|
| JSX used by one route | app/<route>/_components/<Name>/ |
| JSX used by 2+ routes, no route knowledge | src/components/<group>/<Name>/ |
| Primitive UI (button, badge, toggle) | your design-system package (@acme/ui) — if it is vendored, edit at the source package |
| Constant used by one component | <Name>/constants.ts (UPPER_SNAKE) |
| Constant shared across features | a purpose-named module in src/lib/ |
| Pure function (format, map, group, pick a colour) | <Name>/helpers.ts; shared → src/lib/<purpose>.ts |
| Style objects (or class-name maps) | <Name>/styles.ts (exported as s) |
| Server data (fetch / mutate / invalidate) | src/lib/hooks/<domain>.ts over src/lib/api.ts — never in a component |
| View logic that needs React (form state, shortcuts, filtering pipeline) | a use<Thing> hook beside the component (<Name>/hooks/ or <Name>/use<Thing>.ts) |
| Complex local state transitions | reducer.ts beside that hook (pure, tested alone) |
| App-wide cross-cutting state (theme, toast, current store/tenant) | provider in src/lib/*.tsx, mounted in providers.tsx |
| Contract / DTO type | your shared contracts package (@acme/contracts); never redeclare it |
| Component-local types | inline props; types.ts only when 2+ files in the folder need it |
| User-visible string (localised app) | your i18n message files (e.g. messages/<locale>/<namespace>.json + useTranslations) |
| Test | <Name>.test.tsx next to the component |
Details and reasoning: references/folder-structure.md, references/component-anatomy.md.
_components/OrderCard/
OrderCard.tsx # the component; the only file that renders the main JSX
constants.ts # values, maps, option lists
helpers.ts # pure functions: no React, no I/O
styles.ts # style objects
hooks/ | useX.ts # optional: view logic that uses React
types.ts # optional
_components/ # optional: pieces used only by this component
OrderCard.test.tsx # optional
index.ts # export { OrderCard } from "./OrderCard"
Create files on demand. An empty helpers.ts is noise, and the point of the
taxonomy is that each file present has a reason to exist.
Split by reason to change, not by line count (size limits live in
react-best-practices):
_components/. Keep nesting to two levels; deeper means promote or
flatten.Each layer only calls downward; a component never calls fetch or api directly.
shared contracts → src/lib/api.ts → src/lib/hooks/<domain>.ts
(query key + fn + invalidation) → pure helpers → view hook → view → page.
State escalates in this order: local useState → nearest common parent → URL search
params (shareable filters) → provider (only for cross-cutting) — and server data stays
in the server-state cache (TanStack Query, SWR), never copied into useState. Full guide:
references/business-logic-layers.md.
page.tsx and layout.tsx stay thin; they wire, they don't hold logic.'use client' on the entry file of each interactive subtree (anything using
hooks, state, or window); modules it imports inherit it, so do not sprinkle it on
every file.children slots; mount providers as
deep as possible.Next-specific rules and the version caveat: references/nextjs-app-router-architecture.md. Without Next.js (Vite SPA, Remix, React Router) the boundary section does not apply; every other rule does.
Creating UI — 1) find the route and check src/components / src/lib for an
existing piece before writing one; 2) scaffold only the files you need; 3) put each
kind of code in its home; 4) run the checklist below.
Refactoring / reviewing — read the file top to bottom and ask the checklist questions; report a violation with the target location, not just "move this".
src/lib/hooks/* (or your equivalent).constants.ts, helpers.ts, styles.ts)._components or a component's internals.@/); relative paths only within the same
component folder.utils.ts / common/.| File | Read it when |
|---|---|
| references/folder-structure.md | Deciding where a new file or module belongs; promotion; imports; barrels; naming |
| references/component-anatomy.md | Creating or splitting a component; what belongs in each file |
| references/business-logic-layers.md | Moving logic out of JSX; designing hooks, reducers, view models |
| references/nextjs-app-router-architecture.md | Routes, layouts, private folders, 'use client' placement, providers |
| references/project-mapping.md | Mapping the rules onto your folders; recording drift, settled decisions and open items |
README.md (opens in a new tab)references/business-logic-layers.md (opens in a new tab)references/component-anatomy.md (opens in a new tab)references/folder-structure.md (opens in a new tab)references/nextjs-app-router-architecture.md (opens in a new tab)references/project-mapping.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
12 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./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./mermaid-diagramCreate Mermaid diagrams in markdown. Use when the user wants to visualize workflows, architectures, API flows, data models, state machines, or system designs. Covers flowcharts, sequence diagrams, class diagrams, ER diagrams, state diagrams, and more./next-best-practicesNext.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling/onion-architectureOnion-architecture rules for a TypeScript backend (written for Fastify + Drizzle/Postgres, applicable to any Node HTTP framework and ORM): which ring a file belongs to (domain, application, infrastructure, presentation), which way imports may point, and where ports, services, repositories, routes, mappers, adapters and DI wiring live; optionally enforced in CI with dependency-cruiser. Use whenever creating, moving, splitting or reviewing backend code — a new feature module, a route that queries the database, a service that keeps growing, 'where should this live', adding an SDK/adapter/port, wiring the DI container, transactions, or a structure-focused PR review — even if the user never says 'architecture' or 'onion'. Not for Fastify API usage (fastify-best-practices), Drizzle query syntax (drizzle-orm-patterns), table design (postgresql-table-design), schemas (zod), or vulnerabilities (security)./postgresql-table-designUse this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced featuresnpx claudepluginhub humen-dev/dev-digest-ai-marketplace --plugin engineering-paved-path