/eng:code-structurefrom Engineering Skills
The file and folder structure of a Next.js App Router app — thin page and layout entries, components/ organised by product area, section-based pages composed by an index, a flat kind-first lib/ using the `<domain>.<kind>.ts` grammar, the server folders for each app shape (an app with its own backend, a frontend over a separate API, the API app itself), and where shared code goes in a monorepo. Use when adding or refactoring a page, building a screen, splitting UI, organising lib/ or server code, or deciding whether code belongs in a package.
Ships in Engineering Skills. 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.
Every page is built from small files in predictable places, so a path can be guessed before it is opened. Never write a page as one large inline file. The rules for pages, components and lib/ apply to every app; the server folders depend on the app's shape; the monorepo section applies only when there are packages.
Before applying this skill, read the project's root AGENTS.md, the AGENTS.md closest to the files in question, and any doc they link for this skill's topic. Names, values and choices — budgets, tiers, tokens, voice, paths — come from those files, never from this skill.
app/**/page.tsx only imports a composed …PageContent and renders it — no markup, data or logic inline. A layout.tsx is an entry too: it renders a shell from ui/layouts/ and passes this app's regions (nav items, footer) in as props. The one thing an entry may hold beyond that is a guard; what the check does and where the real check belongs are auth's.PricingHero.tsx, PricingTiers.tsx, PricingFaq.tsx), so two pages never ship a bare Hero each (naming). Named, not default, so the file name, the export and every import match.index.tsx composes. It imports the sections and stacks them into a named-exported …PageContent that owns the page's layout wrapper.index.tsx and the entry only import and stack. Section-local data and constants live with the section, never in the entry.When a file passes ~200 lines or mixes concerns, split it: one file per modal or overlay, one per section, stateful logic into a use-*.ts hook. A hook used by exactly one section may sit beside it; a shared one goes in the hooks kind. A hook that returns JSX (a provider) is a component file. The orchestrator only composes. As soon as the same UI or logic is used twice, extract one piece — how to build it is reusables.
All source sits under src/, with the path alias @/* → ./src/*.
| Folder | Holds |
|---|---|
src/app/ | the files Next.js reads by name and nothing else — no components, data or helpers |
src/proxy.ts | the request proxy, beside src/app/; src/instrumentation.ts beside it for startup and error reporting |
src/components/ | the app's pages and features, organised by product area |
src/ui/ | the app's own shared UI, in the tiers design-system defines — only what no package already provides |
src/lib/ | everything that isn't a component, kind-first (below) |
src/styles/ | one entry plus one file per layer, never a single growing stylesheet; the layers and their order are tailwind's |
src/testing/ | fixtures, fakes and render helpers shared by the app's tests; how to write them is testing |
public/ | at the app's root: files served as they are from the site root |
components/auth/, marketing/, billing/, events/. A route group that is one area (marketing, auth, legal) is one folder; a group that holds many areas, such as a dashboard or a whole admin app, gives each feature its own folder rather than nesting them under the group's name. Inside an area, one folder per page, named and nested the way its URL is, so billing/plans/ holds the sections of /billing/plans.app/ → components/ → ui/ → lib/; nothing imports from app/, and client code never from the server boundary. A lint rule (import/no-restricted-paths zones, or eslint-plugin-boundaries) enforces it, so a wrong import fails lint rather than review.components/errors/ holds the error, not-found and unauthorised views; components/guards/ holds client-side gates.components/_shared/ holds cross-feature widgets, grouped by concern (otp/, layout/). Each group has a barrel with one explicit export per file and is imported as @/components/_shared/<group>. A server-coupled component (its import chain reaches server code) stays out of its group barrel and is imported by path, so a client import of the barrel can never drag server code into the bundle. There is no root _shared/index.ts.components/<area>/_shared/ holds what one area's pages share..tsx, plus colocated stories and tests, CSS modules where a project uses them, the barrels, and a stub data.ts beside the component it feeds while the real source isn't wired. Real static content goes in lib/data/. A const whose values are React components is UI and lives in a .tsx.lib/Strictly kind-first, and flat inside each kind. Every top-level folder is a kind — exactly one folder per kind, never a domain or feature folder at the lib/ root, never a mini hooks/ or types/ rebuilt inside a feature, no loose files at the root. The domain is a filename prefix, not a subfolder: constants/auth.constant.ts, not constants/auth/index.ts.
| Kind | Grammar | Holds |
|---|---|---|
config/ | bare names | one-per-app settings: env, routes, endpoints, site |
constants/ | <domain>.constant.ts | frozen domain values; the const and its inferred type together |
data/ | <domain>.data.ts | static content records — pricing tiers, FAQs, team |
hooks/ | use-<subject>.ts | one hook per file, named for what it gives you |
schemas/ | <domain>.schema.ts | Zod schemas with their inferred types, in the same file |
seo/ | bare names | the app's metadata factory and structured-data builders; what goes in is seo-aeo-geo's |
types/ | <domain>.type.ts | shapes with no const or schema behind them |
utils/ | <domain>.utils.ts | pure helpers; a single-function file may keep a bare name (cn.ts) |
schemas/, constants/ and types/ each own their inferred type. types/ holds only what neither a schema nor a const produces; re-declaring one there is how the kinds drift. How schemas are written is schemas-and-contracts'.@/lib/<kind>), never export * from a directory — a wildcard hides what joined it.config/ barrel is server-only, because it re-exports env, which reads secrets. Client code imports the one file it needs by path (@/lib/config/routes); a lint rule or type check won't catch the barrel, the build will.config/routes.ts, API paths from config/endpoints.ts. Both are objects grouped by area, never one flat map: routes.ts by route group, endpoints.ts by the backend's own resource. A path with a parameter is a function inside its group, so no caller concatenates, and the API version is one constant the endpoints are built from. Typing the routes is typescript's.A domain that outgrows one file becomes a folder inside its kind, and the files inside carry only the concern, because the folder already names the domain. An index.ts re-exports them, so callers import the domain, never its parts:
services/
user.service.ts one concern, stays a file
event/ outgrew one file
crud.service.ts not event-crud.service.ts
publishing.service.ts
index.ts
Start flat; split past ~200 lines or when two concerns change for different reasons.
A kind whose files pile up groups them by what a reader scans for, which for some kinds is a concern rather than a domain. hooks/ groups as auth/ data/ profile/ ui/, because nobody looks for "the event hook", they look for "the hook that closes a menu". Concerns split where they change for different reasons: "are you signed in" and "may you do this" are two groups. Flat while a listing is still scannable at a glance, grouped past that.
Server-only code sits behind one boundary with its own barrel marked server-only, kind-first and flat inside, like the rest of lib/. Never share a barrel between server-only and client-safe code — a client importing a mixed barrel drags server code into the bundle or fails the build. Everything outside the boundary is client-safe; mark browser-only entry points client-only. Which kinds the boundary holds depends on where the app's data comes from.
One Next.js app that talks to its database and services itself. The boundary is lib/server/:
| Kind | Grammar | Holds |
|---|---|---|
actions/ | <domain>.action.ts | Server Actions by domain — never one giant actions.ts |
services/ | <domain>.service.ts | business logic; the only caller of data/ |
data/ | <domain>.data.ts | store access only — plus the collection-path registry and batch writer |
clients/ | <service>.client.ts | one configured SDK singleton per external service |
utils/ | <domain>.utils.ts | server-only helpers: the guard, response builders, logger, errors |
The barrel exports actions and services. clients/, data/ and utils/ are called by the layers above them, and exporting them invites a page to query the store directly.
An app that reads and writes only through an API it doesn't contain — a sibling API app, or an external backend. The boundary is lib/server/, and it holds no business logic:
| Kind | Grammar | Holds |
|---|---|---|
actions/ | <domain>.action.ts | Server Actions by domain, each calling the API |
data/ | <domain>.data.ts | the API reads, with their caching; how they cache is nextjs' |
utils/ | <domain>.utils.ts | the typed fetchers, the session helpers, the action-result builder |
The barrel exports actions and data, plus the identity helpers an entry's guard calls. The fetchers stay out: actions and reads call them, app code never does.
A Next.js app that only serves the API. The whole app is server code, so the boundary is src/server/, not lib/server/:
| Kind | Grammar | Holds |
|---|---|---|
services/ | <domain>.service.ts | business logic; the only caller of data/ |
data/ | <domain>.data.ts | store access only |
clients/ | <service>.client.ts | one configured SDK singleton per external service |
guards/ | <name>.guard.ts | the auth, permission and resource checks a route calls |
utils/ | <domain>.utils.ts | response builders, errors, logger, cookies |
The barrel exports services and guards only, so a route can never reach data/ or a client. The route order and the guards themselves are api-architecture's. The app's other kinds (config/, constants/, schemas/) sit at src/ beside server/.
clients/redis/ with client.ts, keys.ts, locks.ts).Skip this section for a single app.
packages/ui, packages/hooks, packages/utils, a shared schemas package); code one app uses stays in that app's lib/. Promote on the second consumer, never before — you can't know something is shared until a second app asks, and promoting is a file move plus an import swap. Hoisting early is the more expensive mistake: every sibling app then rebuilds for changes it doesn't care about.lib/ and its own src/ui/ for what only it uses. A package keeps the same <domain>.<kind>.ts grammar as the in-app kind.dist/. It ships TypeScript source when every consumer's bundler compiles it (UI, hooks, utils for Next.js apps). It builds to dist/ when plain Node loads it as well as bundlers, such as a schemas package that serverless workers import too; then every consumer reads the build, with NodeNext resolution. A dist/ package is rebuilt after every change, and anything running from it restarts.monorepo's.Every file Next.js reads by name — route files, metadata files, the ones beside app/ — and the house content of each, with the entry examples, is in references/next-files.md.
app/ holds no private folders. Next allows _components/ there, but the house puts route-local pieces in components/ under the page's folder, so app/ reads as the URL map and nothing more.loading, error, not-found, template — except global-error, which sits only in app/ and renders its own <html> and <body>.default.tsx.(auth)/auth/: the parentheses buy the shared layout, the inner folder buys the /auth prefix. A group that only groups ((marketing), (legal)) has no inner segment, because its pages sit at the root of the URL./dashboard/... and /admin/... for the other areas. Where each area is its own app, the app already is the area, so its pages sit at the root — the admin app's users page is /users, not /admin/users. Only an API keeps its prefix (/api/v1/...).page.tsx is ~3 lines (import + render) and each layout.tsx renders a shell; neither holds more than a guard.app/ holds only files Next.js reads by name; every parallel slot has a default.tsx.index.tsx.components/ is organised by product area, pages nested as their URLs are, and holds only .tsx (plus colocated stories, tests and an approved stub).lib/ is kind-first and flat inside each kind, files named <domain>.<kind>.ts, every kind barrel one explicit export per file.types/ re-declares a type a schema or constant already infers.config/ barrel.naming.design-system; building one reusable → reusables."use client" boundary, data fetching and caching → nextjs.auth.conventions-audit.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub timonwa/engineering-skills --plugin eng20 skills in this plugin
/agents-mdWrites or updates a project's AGENTS.md and the short AGENTS.md notes in each app and package — what an agent can't work out from the code: commands, structure, conventions that differ from the defaults, workflow, recorded deviations from the house standards and hard constraints, under 200 lines. Use when starting a project, setting up AGENTS.md or CLAUDE.md, or bringing a project's agent instructions up to date./audit-allManually invoked. Runs the house audit suite across the eng, fe and be sets — detects what the repo has, runs every installed audit that applies (codebase, conventions, dependencies, env, security, accessibility, frontend, performance, SEO/AEO/GEO, Storybook, content, API, access control, Firestore, Redis), and rolls their reports into one health report with an overall score and cross-cutting priorities. Each audit still writes its own report./codebase-auditManually invoked. Broad repo-health triage that routes to the deep audits and covers the hygiene no other audit owns — tech debt, dead code, TypeScript strictness and the options TypeScript 6 deprecates, error handling, tests (boundary-only mocks, determinism, no skipped or flaky tests), CI hygiene, branch protection, releases and deploys, and git hygiene. Verifies each finding and writes a prioritized report with an overall health score./conventions-auditManually invoked. Audits an app or monorepo against the house naming and code-structure standards — identifier, file, test-file, field and error naming; thin route entries and app/ holding only Next's files; components by product area; kind-first lib/ and barrels; server boundaries; typed routes; promotion on the second consumer; duplicated helpers, oversized files, hardcoded values and cross-app config drift. Verifies each finding and writes a prioritised report./dependency-auditManually invoked. Dependency-health audit of a monorepo — one version per dependency through the pnpm catalog with recorded exceptions, workspace protocol and dependency direction, peer dependencies for singletons, unused, missing, duplicate and misplaced packages, build-script allowlists, release-age holds, advisories, automated updates, and lockfile integrity. Verifies each finding and writes a prioritised report./devopsA repo's format, check, release and ship automation — Prettier and shared ESLint presets, fast git hooks, GitHub Actions with parallel jobs and hardening against workflow injection, tier branches protected by rulesets with merge-commit promotions, release-drafter releases, deploys kept out of CI with a rollback runbook, and opt-in gates. Use when setting up or reviewing CI/CD, hooks, branches, releases or deployment.