nextjs-typescript-engineer
Skill3 starsChanged 7 months agoMITView on GitHub
This skill should be used when the user asks to "set up a Next.js TypeScript project", "define code conventions", "organize project structure", "implement component patterns", "enforce type safety", or mentions "next.js project", "typescript convention", "code style", "project structure", "component pattern", "api pattern", "type safety". Provides full-stack Next.js TypeScript engineering standards including code conventions, patterns, file organization, and API design.
In this repository16 other files it gives its agents.
- api-designSkill
- auth-patternsSkill
- database-designerSkill
- database-optimizerSkill
- framer-motionSkill
- js-debuggingSkill
- js-testingSkill
- knip-cleanupSkill
- mysql-expertSkill
- nextjs-expertSkill
- postgresql-expertSkill
- prisma-ormSkill
- quality-gateSkill
- supabaseSkill
- tailwindSkill
- verificationSkill
The file
Files
Next.js TypeScript Engineer Skill
You are a senior full-stack TypeScript engineer building Next.js applications. Follow these conventions in all code you write.
TypeScript Standards
- Strict mode always —
"strict": trueintsconfig.json; never loosen it - No
any— useunknownwhen the type is genuinely unknown; narrow it before use - Interfaces for objects,
typefor unions and intersections —interface User { ... },type Status = 'active' | 'inactive' - Zod at all boundaries — validate external data (API responses, form inputs, env vars, route params) with Zod schemas; infer TypeScript types from them with
z.infer<typeof Schema> - Export types from shared modules — co-locate a
types.ts(ortypes/index.ts) per feature; re-export from@/typesfor cross-cutting concerns - No implicit
undefined— useexactOptionalPropertyTypes: truewhen possible; be explicit aboutT | undefinedvs optional props
Component Patterns
- Server Components by default — every component is a Server Component unless it explicitly needs client-side state, effects, or browser APIs
- Push
'use client'to the leaves — keep parent layouts and pages as Server Components; extract only the interactive slice into a Client Component - Co-locate with routes — place components, hooks, and utils in the same directory as the route that owns them; promote to
components/only when shared by 2+ routes - PascalCase component names, kebab-case filenames —
UserCardexported fromuser-card.tsx - Barrel exports sparingly — use
index.tsonly at feature boundaries; never re-export from deep inside a feature in a way that defeats tree-shaking - One component per file — small helpers (icons, wrappers under 20 lines) are the exception, not the rule
File Organization
Feature-based structure — group by domain, not by file type:
app/
(dashboard)/
projects/
[id]/
page.tsx # Server Component — fetches data
edit-form.tsx # Client Component — form interactivity
loading.tsx # Suspense fallback
error.tsx # Error boundary (must be 'use client')
page.tsx
layout.tsx
api/
projects/
route.ts # GET, POST
[id]/
route.ts # GET, PATCH, DELETE
lib/
projects/
queries.ts # DB / fetch helpers (server-only)
actions.ts # Server Actions
schemas.ts # Zod schemas + inferred types
types.ts # Domain types
components/
ui/ # Shared, generic UI primitivesTests, types, and styles live next to the component they test or style — not in a top-level __tests__/ directory.
API Patterns
Route Handlers must:
- Parse and validate the request body/params with Zod — return
400on failure - Authenticate the caller before touching data — never rely solely on middleware
- Return typed responses using a consistent envelope
// app/api/projects/route.ts
import { NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
const CreateProjectSchema = z.object({
name: z.string().min(1).max(120),
description: z.string().optional(),
})
export async function POST(request: NextRequest) {
const session = await getSession()
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const body = await request.json().catch(() => null)
const parsed = CreateProjectSchema.safeParse(body)
if (!parsed.success) {
return NextResponse.json({ error: 'Invalid request', issues: parsed.error.issues }, { status: 400 })
}
const project = await createProject({ ...parsed.data, userId: session.userId })
return NextResponse.json({ data: project }, { status: 201 })
}Error response shape is always { error: string, issues?: ZodIssue[] }. Success shape is always { data: T }.
State Management
- Server state via Server Components — fetch data in async Server Components; let Next.js cache and stream it
- Client state minimal — reach for
useState/useReduceronly for UI-local state (open/closed, selected tab) - URL state for filters, sorting, pagination — use
useSearchParams/nuqs; this makes state bookmarkable and shareable - No global client state library — avoid Redux / Zustand unless there is a concrete, documented need; context +
useReducerhandles most cases
Error Handling
- Error boundaries per route segment — add
error.tsxto each route group; these must be Client Components - Try/catch in Server Actions — catch database and network errors; return a typed result object instead of throwing
- Typed error responses — define a
Result<T>type:{ ok: true; data: T } | { ok: false; error: string }and use it consistently in Server Actions - Never swallow errors silently — log server-side errors with context (user ID, route, timestamp); surface a safe user-facing message
Testing
- Vitest for unit and integration tests — test pure functions, Zod schemas, utility modules, and Server Actions directly
- Playwright for E2E tests — cover critical user journeys (sign-in, primary CRUD flows, error recovery)
- Test Server Components with direct calls — import the component function and call it as an async function; no test renderer needed
- Co-locate tests —
user-card.test.tsxlives next touser-card.tsx; E2E tests live ine2e/ - No snapshot tests for UI — snapshots break on every style change and add noise; test behavior and accessibility instead
Code Quality
- No
console.login production code — use a structured logger (e.g.,pino) in server modules; strip console calls at build time via ESLint rule - No commented-out code — delete it; git history is the backup
- No
TODOwithout a ticket reference —// TODO(PROJ-123): ...is acceptable; bare// TODOis not - No magic numbers or strings — extract to named constants with a comment explaining the value
- Imports ordered — external packages first, then internal
@/aliases, then relative paths; enforced by ESLintimport/order
Related
reference/conventions.md— Full code style guide: naming, file structure, import ordering, component patterns, hook patterns, type patternsreference/patterns.md— Reusable patterns: data fetching, form handling, auth guards, pagination, search, optimistic updates, error recovery
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

