component-gen-next
Skill2 starsChanged 8 months agoUnlicenseView on GitHub
Generate production-ready Next.js App Router component. RSC-first with Suspense, Server Actions, generateMetadata. Supports --quick (fast single-file), --path (custom dir), --into (inject markup), --design, --type [ui|feature]. Do not use for React SPA or Vue — use /component-gen instead.
In this repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/00-project-context.mdcCursor rule
- .cursor/rules/01b-component-gen-next.mdcCursor rule
- .cursor/rules/01-component-gen.mdcCursor rule
- .cursor/rules/02-component-tests.mdcCursor rule
- .cursor/rules/03b-vue-doctor.mdcCursor rule
- .cursor/rules/03-react-doctor.mdcCursor rule
- .cursor/rules/04-ui-tweak.mdcCursor rule
- .cursor/rules/05-refactor.mdcCursor rule
- .cursor/rules/06-frontend-code-review.mdcCursor rule
- .cursor/rules/07-fe-repo-scout.mdcCursor rule
- .cursor/rules/08-be-repo-scout.mdcCursor rule
- .cursor/rules/09-web-vitals.mdcCursor rule
- .cursor/rules/10-browser-check.mdcCursor rule
- .cursor/rules/11-api-bind.mdcCursor rule
- .cursor/rules/12-e2e-tests.mdcCursor rule
- .cursor/rules/13-api-mocks.mdcCursor rule
- agents-checkerSkill
- api-bindSkill
- api-mocksSkill
- be-repo-scoutSkill
- browser-checkSkill
- component-gen-nextSkill
- component-genSkill
- component-testsSkill
- curate-lessonsSkill
- e2e-testsSkill
- fe-repo-scoutSkill
- fix-markdownSkill
- frontend-code-reviewSkill
- init-agentSkill
- init-projectSkill
- init-skillSkill
- prSkill
- react-doctorSkill
- refactorSkill
- setup-configsSkill
- skill-auditSkill
- spec-auditSkill
- ui-tweakSkill
- update-ai-setupSkill
- vue-doctorSkill
- web-vitalsSkill
- agents-checkerSkill
- api-bindSkill
- api-mocksSkill
- be-repo-scoutSkill
- browser-checkSkill
- component-genSkill
- component-testsSkill
- curate-lessonsSkill
- e2e-testsSkill
- fe-repo-scoutSkill
- fix-markdownSkill
- frontend-code-reviewSkill
- init-agentSkill
- init-projectSkill
- init-skillSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 1 is distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Before execution the agent MUST load: .claude/protocols/gardener.md
- Very specific: line 45
Add --design when visual quality matters: landing pages, hero sections, marketing UI, editorial layouts
- Very specific: line 55
If invoked with react or vue framework param:
- Very specific: line 81
If --quick is present → skip to § Quick Mode Workflow below (same as component-gen --quick but React-only).
- Very specific: line 85
If --into <file> is present → skip to § Inline Mode Workflow below (same as component-gen --into but React-only).
- Very specific: line 116
If --design flag present → also load .claude/fe-antipatterns/design/no-generic-ai-aesthetics.md
- Distinctive: line 118
If component description contains streaming, realtime, SSE, Server-Sent Events,
- Very specific: line 163
If the component contains a write action (POST/PUT/DELETE, form submit, like/follow/save/delete):
- Very specific: line 239
Page Detection (AUTO): if name ends with Page/View/Route/Screen OR layer is pages/ → activate SEO Protocol.
- Very specific: line 287
If --design flag was used, also run:
- Very specific: line 296
Every interactive element (<button>, <input>, <a>, <form>) needs data-testid
- Very specific: line 338
Gardener Protocol: Call .claude/protocols/gardener.md before SKILL COMPLETE.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Recommended Flow
/component-gen-next ComponentName → /api-bind react → /component-tests react
For UI-heavy work: /component-gen-next ComponentName --design
For simple presentational components: /component-gen-next ComponentName --type ui
For quick simple elements: /component-gen-next Badge --quick
For custom output path: /component-gen-next Button --type ui --path src/components/ui
For injecting markup: /component-gen-next --into src/app/page.tsx "hero section with CTA"
Note: /component-tests auto-detects --type from the generated component's imports.
SYSTEM REQUIREMENTS
Before execution the agent MUST load: .claude/protocols/gardener.md
Next.js App Router Component Generator
<purpose>
Generates a production-ready TypeScript component for Next.js App Router (15+).--type feature (default): RSC async component. Loading via <Suspense> + skeleton. Errors via error.tsx boundary or re-throw. Empty via null-check after await. Mutations via Server Actions + useActionState.
--type ui: Presentational component. RSC by default (no directive), or 'use client' if interactive. Props-driven only.
With --design flag: activates Design Thinking (Purpose/Tone/Constraints/Differentiation) and enforces
aesthetic quality — committed font stack, named palette, intentional spatial composition, motion budget.
</purpose>
When to Use
--type feature(default): Component that fetches data server-side (RSCawait) or has mutations (Server Actions)--type ui: Pure presentational component — Button, Badge, Avatar, Card, HeroSection, layout primitives- Add
--designwhen visual quality matters: landing pages, hero sections, marketing UI, editorial layouts
Input Validation (MANDATORY)
CRITICAL: This skill is for Next.js App Router only.
Expected invocation: /component-gen-next ComponentName [--type ui|feature] [--design] [--quick] [--path <dir>] [--into <file>]If invoked with react or vue framework param:
ERROR: /component-gen-next is for Next.js App Router only.
For React SPA or Vue, use: /component-gen [react|vue] ComponentName--type defaults to feature if omitted.
Flag compatibility rules: Same as /component-gen — see .claude/skills/component-gen/SKILL.md § Input Validation.
--quickimplies--type ui. Incompatible with--type featureand--design.--intoinjects markup into existing file. Incompatible with--type featureand--quick.--pathoverrides architecture-based path resolution.
Input Context (Process Isolation)
context: fork — you cannot see chat history before your invocation.
Allowed inputs: Component name, --type flag, --design flag, --quick flag, --path dir, --into file path, optional description, CLAUDE.md, existing source files.
Forbidden: Assumptions from chat history, inventing API contracts.
Protocol
0. Quick Mode [--quick only]
If --quick is present → skip to § Quick Mode Workflow below (same as component-gen --quick but React-only).
0b. Inline Mode [--into only]
If --into <file> is present → skip to § Inline Mode Workflow below (same as component-gen --into but React-only).
1. Architecture Resolution
Resolve output path BEFORE generating any files. Load .claude/skills/component-gen/references/architecture-paths.md.
Priority order:
--path <dir>— explicit overrideaudit/fe-repo-scout-report_*.md→ §2 Architecture → PatternCLAUDE.md→## Project Structure→architecture:value- Auto-detect:
ls src/→ match against known directory signatures - Fallback: FSD
Next.js-specific path mapping:
| Architecture | --type feature | --type ui |
| FSD | src/{layer}/{slice}/ui/{Name}/ | src/shared/ui/{Name}/ |
| App Router | src/components/{Name}/ | src/components/ui/{Name}/ |
| Custom (--path) | {path}/{Name}/ | {path}/{Name}/ |
2. Framework Routing
Always load:
references/next-patterns.mdreferences/react-patterns-client.md(client island subset).claude/skills/component-gen/references/common-states.mdreferences/quality-gates-next.md
If --design flag present → also load .claude/fe-antipatterns/design/no-generic-ai-aesthetics.md
If component description contains streaming, realtime, SSE, Server-Sent Events,
webhook, live, progress, build log, AI generation, long-running task,
import job → also load .claude/skills/component-gen/references/streaming-patterns.md
3. Phase 0: Design Thinking [--design only]
Load .claude/skills/component-gen/references/design-thinking.md — execute the design brief template (palette scan, Purpose/Tone/Constraints/Differentiation).
4. Motion & Composition Directives [--design only]
Load .claude/skills/component-gen/references/motion-composition.md — enforce motion budget and spatial composition rules.
5. Banned Patterns
Top violations: : any / as any, console.log, style={{}} for layout, <div onClick> / <span onClick>.
Full list: .claude/skills/component-gen/references/banned-patterns.md
6. RSC Boundary Decision
Default: Server Component (no directive). Add 'use client' only when needed:
useState,useEffect,useRef, or React state/lifecycle hooks- Browser APIs (
window,document,navigator,localStorage) - Event handlers (
onClick,onChange,onSubmit) - Next.js client hooks:
useRouter,usePathname,useSearchParams
Isolation rule: Push 'use client' as deep as possible — small interactive islands, RSC outer shell.
Component Structure Requirements
--type feature (default — RSC Async)
4 states handled differently than SPA:
| State | Next.js Implementation |
| Loading | <Suspense fallback={<Skeleton />}> at call site + {ComponentName}.loading.tsx |
| Error | error.tsx boundary catches thrown errors from RSC |
| Empty | Null-check after await → inline empty UI or notFound() |
| Success | Direct await in async RSC body — no TanStack Query |
With --design: success state MUST reflect committed aesthetic from Phase 0.
Mutation Handling — Server Actions
If the component contains a write action (POST/PUT/DELETE, form submit, like/follow/save/delete):
- Generate
actions.tswith'use server'directive - Client island uses
useActionStatefor pending/error feedback - Pass action to
<form action={serverAction}>— NEVERonSubmit+fetch() - Note: if a
use{Feature}hook exists from/api-bind, import it for client-side data needs only
SEO Protocol [page-level components only]
Activated when component name ends with Page / View / Route / Screen OR target FSD layer is pages/.
| Method | Usage |
generateMetadata() | Export async function for title/description/og tags |
notFound() | Call from next/navigation when entity not found |
redirect() | Server-side redirect from RSC |
JSON-LD: generate ONLY when component semantics match a schema.org type AND all required fields exist in props/API response.
--type ui (Presentational)
- RSC by default (no directive) — add
'use client'only if interactive - Props-driven render only — NO data fetching
- Quality gate: "Props-driven render only" replaces "All 4 states present"
File Structure
Output paths depend on detected architecture. See
.claude/skills/component-gen/references/architecture-paths.md. Below are FSD examples (default). For App Router layout, substitute paths per architecture resolution.
--type feature — Next.js App Router (FSD)
src/{layer}/{feature}/
├── ui/{ComponentName}/
│ ├── {ComponentName}.tsx # RSC (async) or Client Component ('use client')
│ ├── {ComponentName}.types.ts # Props interface + data types
│ ├── {ComponentName}.loading.tsx # Skeleton for <Suspense fallback>
│ └── index.ts # Barrel export
├── model/ # Client state only (if 'use client' island needed)
└── actions.ts # Server Actions ('use server') — replaces api/--type ui — Next.js App Router (FSD)
src/shared/ui/{ComponentName}/
├── {ComponentName}.tsx # RSC by default or 'use client' if interactive
├── {ComponentName}.types.ts # Props interface
└── index.ts # Barrel export--quick — Single file output
{resolved-path}/{ComponentName}.tsx # RSC by default, inline props interfaceNo types.ts, no index.ts, no .loading.tsx.
--into — No new files
Modifies the target file in-place. No types.ts, no index.ts, no new directories.
Workflow (Standard Mode)
If
--quick→ skip to § Quick Mode Workflow. If--into→ skip to § Inline Mode Workflow.
- Validate — check invocation (no
react/vueframework param). Check flag compatibility. BLOCKER if wrong. - Resolve architecture — follow
references/architecture-paths.mdpriority (--path > scout report > CLAUDE.md > auto-detect > FSD fallback). - [
--design] Design Thinking — scan palette tokens, answer Purpose/Tone/Constraints/Differentiation. - [
--design+ complex primitives] UI-kit scaffolding — check forcomponents.json(shadcn/ui) →npx shadcn add. - Scaffold structure — branch on
--type+ architecture:--type ui: resolved UI path from architecture-paths.md.--type feature: resolved feature path. FSD: createui/,model/(if client island),actions.ts(if mutation). Non-FSD: co-locate.
- Page Detection (AUTO): if name ends with Page/View/Route/Screen OR layer is
pages/→ activate SEO Protocol. - Discover — read
CLAUDE.md, globsrc/**/*.tsxfor style reference, scansrc/shared/ui/for reusable primitives. - Load references — Next.js patterns + client island patterns + common-states.
- Generate types —
{ComponentName}.types.tsfirst.strictNullChecks+noUncheckedIndexedAccesssafe. - Generate component — RSC async for feature, props-driven for UI. Generate
.loading.tsxskeleton. Generateactions.tsif mutation detected. - Generate barrel —
index.tswith named export. - Type check —
npx tsc --noEmit 2>&1 | grep -E "{ComponentName}|{output-path}" | head -30 - Lint — detect linter (biome/eslint) and run.
- Post-Check — run BANNED pattern grep + data-testid coverage check.
- Gardener —
.claude/protocols/gardener.md - SKILL COMPLETE
Quick Mode Workflow (--quick)
Same as /component-gen --quick (see .claude/skills/component-gen/SKILL.md § Quick Mode Workflow) with Next.js additions: RSC by default (no 'use client' unless interactive), no .loading.tsx.
✅ SKILL COMPLETE: /component-gen-next --quick
├─ Framework: next
├─ RSC Boundary: [Server Component | Client Component]
├─ Artifact: {single file path}
└─ Gates: 5/5 PASSInline Mode Workflow (--into)
Same as /component-gen --into (see .claude/skills/component-gen/SKILL.md § Inline Mode Workflow) with RSC boundary awareness: respect existing 'use client' directive, match RSC/client patterns.
✅ SKILL COMPLETE: /component-gen-next --into
├─ Framework: next
├─ Modified: {file path}
├─ Injected: {description of added section}
└─ Lint: [PASS | FAIL]Post-Check (Mandatory)
# BANNED patterns
grep -rn ": any\b\|as any\b\|console\.log\|document\.querySelector\|style={{\|div.*onClick\|span.*onClick" {output-path}/
# Next.js-specific
grep -rn "from 'next/router'" {output-path}/
grep -rn "export const revalidate" {output-path}/
# Render performance
grep -rn "addEventListener.*['\"]scroll['\"]" {output-path}/If --design flag was used, also run:
grep -rn "font-family.*Inter\|font-family.*Arial\|font-family.*Roboto\|font-family.*system-ui" {output-path}/data-testid coverage:
--type feature:data-testidon empty state container and success state root (loading-skeletonlives in.loading.tsx, error inerror.tsx)- Every interactive element (
<button>,<input>,<a>,<form>) needsdata-testid - Convention:
{component-name}-{element-role}in kebab-case
Quality Gates
- No
react/vueframework param accepted (Next.js only) --typeparam resolved (default:feature)- [
--type feature] RSC async withawait— no TanStack Query for data fetching - [
--type feature].loading.tsxskeleton created for Suspense fallback - [
--type feature] Error handling: thrown toerror.tsxboundary (not swallowed) - [
--type feature] Empty state: null-check after await - [
--type ui] Props-driven render only (no async) - [
--type ui] RSC by default;'use client'only if interactive - Defaulted to Server Component unless client strictly needed
'use client'at very top of file (if used)- Uses
next/linkandnext/image(not<a>or<img>) - No
useRouterfromnext/router(must usenext/navigation) - Mutations use Server Actions in
actions.ts(notfetch()in client handler) - No
export const revalidate = N(use'use cache'directive) - No
: anyoras any(auto-fixed or BLOCKER) - No
console.log(auto-fixed) - No hardcoded URLs
tsc --noEmitPASS (isolated)- Linter PASS
- Barrel export (
index.ts) created src/shared/ui/scanned — no re-implemented primitives- All interactive elements have
data-testid - [
--designonly] → see.claude/skills/component-gen/references/quality-gates-design.md - [page-level] → see
.claude/skills/component-gen/references/quality-gates-page.md
References
- Next.js patterns:
references/next-patterns.md - Client island patterns:
references/react-patterns-client.md - State structure:
.claude/skills/component-gen/references/common-states.md - Quality rules:
references/quality-gates-next.md - Banned patterns:
.claude/skills/component-gen/references/banned-patterns.md - Design anti-patterns [
--design]:.claude/fe-antipatterns/design/no-generic-ai-aesthetics.md - Streaming patterns [trigger keywords]:
.claude/skills/component-gen/references/streaming-patterns.md - Quality gates
--design:.claude/skills/component-gen/references/quality-gates-design.md - Quality gates page-level:
.claude/skills/component-gen/references/quality-gates-page.md
Gardener Protocol: Call .claude/protocols/gardener.md before SKILL COMPLETE.
Completion Contract
✅ SKILL COMPLETE: /component-gen-next
├─ Type: [UI (Presentational) | Feature (RSC Async)]
├─ Framework: next
├─ RSC Boundary: [Server Component | Client Component | Mixed (RSC + client island)]
├─ Artifacts: [list of created files]
├─ Type Check: [PASS (isolated) | FAIL: {error}]
├─ Lint: [PASS (biome) | PASS (eslint) | PASS (npm run lint) | FAIL: {error}]
├─ States: [4/4 (Suspense + error.tsx + empty + success) | N/A (Presentational)]
├─ A11y: [PASS | FAIL: {violation}]
├─ Auto-Corrected: [console.log ×N | any ×N | none]
├─ Server Actions: [Yes (actions.ts) | No | N/A]
├─ SEO: [generateMetadata | N/A]
├─ Type Hint: [/component-tests can auto-detect type via import scan]
└─ Aesthetic: [Project defaults | {Named direction} (--design)]⚠️ SKILL PARTIAL: /component-gen-next
├─ Type: [UI (Presentational) | Feature (RSC Async)]
├─ Framework: next
├─ Artifacts: [list (✅/❌)]
├─ Type Check: [PARTIAL]
├─ Coverage: [X/Y states | N/A (Presentational)]
└─ Blockers: [description]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.

