nextjs-typescript
Skill0 starsChanged 26 days agoMITView on GitHub
Provides expert knowledge for building Next.js 15+ applications with the App Router, TypeScript, Server Components, Server Actions, and TanStack Query.
In this repository219 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/behavioral-discipline.mdcCursor rule
- .cursor/rules/context-budget.mdcCursor rule
- .cursor/rules/orchestration.mdcCursor rule
- .cursor/rules/yagni-stdlib.mdcCursor rule
- androidSkill
- android-ui-designSkill
- api-versioningSkill
- astroSkill
- auth-token-inspectorSkill
- backlogSkill
- cc-api-contractSkill
- cc-db-migrationSkill
- cc-featureSkill
- cc-fixSkill
- cc-pagespeedSkill
- cc-refactorSkill
- cc-reviewSkill
- cc-spec-mutationSkill
- cc-tdd-cycleSkill
- cc-test-planSkill
- code-reviewSkill
- commitSkill
- conductor-setupSkill
- councilSkill
- database-migrationsSkill
- django-ormSkill
- django-testingSkill
- django-uvSkill
- drizzle-schema-architectSkill
- evaluationSkill
- fastapi-pydantic-strictSkill
- find-skillsSkill
- jpa-nplusone-detectorSkill
- jpa-postgresSkill
- laravel-specialistSkill
- livewire-alpine-bridgeSkill
- multi-agent-orchestrationSkill
- openspecSkill
- pagespeed-insightsSkill
- pagespeed-perfSkill
- php-proSkill
- python-django-stackSkill
- python-fastapi-stackSkill
- pythonSkill
- rust-asyncSkill
- rust-engineeringSkill
- rust-sqlxSkill
- security-ai-llmSkill
- security-blue-teamSkill
- security-cloudSkill
- security-cryptoSkill
- security-exploit-devSkill
- security-grcSkill
- security-incident-responseSkill
- security-log-analysisSkill
- security-malware-analysisSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 57
Keep the "use client" boundary as far down the component tree as possible.
- Distinctive: line 155
Never use them for reads.
- Very specific: line 205
Always validate input with Zod — do not trust FormData values
- Very specific: line 207
Call revalidatePath() or revalidateTag() after mutations that affect cached data
- Distinctive: line 209
Never put secrets or auth logic in Client Components — keep it in actions
- Distinctive: line 213
Use TanStack Query for data that must stay fresh on the client: real-time feeds, user-specific data after mutations, optimistic updates.
- Distinctive: line 245
Do not use TanStack Query for data that a Server Component can fetch directly.
- Very specific: line 251
Use route handlers for: webhooks, third-party OAuth callbacks, or endpoints consumed by non-Next.js clients.
- Very specific: line 311
Never hardcode metadata in <head> tags — use the Metadata API.
- Distinctive: line 335
Do not wrap the entire page — that defeats streaming.
- Very specific: line 356
Never use any — use unknown and narrow with type guards
- Very specific: line 357
Use satisfies to validate objects against a type without widening
- Very specific: line 360
Use next/navigation hooks (useRouter, usePathname) not next/router — the latter is Pages Router only
≈ “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
Next.js + TypeScript
Server vs Client Components
The App Router defaults to Server Components. Every component is a Server Component unless it explicitly opts in to the client.
Decision Rule
Does the component need any of the following?
- useState / useReducer
- useEffect / lifecycle methods
- Browser APIs (window, document, localStorage)
- Event listeners (onClick, onChange, onSubmit)
- Third-party libraries that require the DOM
YES → Client Component (`"use client"` directive)
NO → Server Component (default, no directive needed)Keep the "use client" boundary as far down the component tree as possible.
Wrap only the interactive leaf node, not the entire page.
Server Component (default)
// app/users/page.tsx — no directive needed
import { db } from '@/lib/db';
export default async function UsersPage() {
// Direct database access — no API round-trip needed
const users = await db.user.findMany({ orderBy: { createdAt: 'desc' } });
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.email}</li>
))}
</ul>
);
}Client Component
// components/ui/counter.tsx
'use client';
import { useState } from 'react';
interface Props {
initialCount?: number;
}
export function Counter({ initialCount = 0 }: Props) {
const [count, setCount] = useState(initialCount);
return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>;
}Composing Server and Client
// app/dashboard/page.tsx — Server Component
import { Counter } from '@/components/ui/counter'; // Client
import { getUser } from '@/lib/queries'; // Server-only function
export default async function DashboardPage() {
const user = await getUser(); // runs on the server
return (
<div>
<h1>Welcome, {user.name}</h1>
<Counter initialCount={user.loginCount} /> {/* client island */}
</div>
);
}Passing server data to client components as props is correct. The server renders the Server Component tree first, serializes the props, and sends them to the client.
Data Fetching
Server Component Fetching (recommended for initial data)
// app/posts/[id]/page.tsx
interface Props {
params: Promise<{ id: string }>;
}
export default async function PostPage({ params }: Props) {
const { id } = await params;
const post = await fetch(`https://api.example.com/posts/${id}`, {
next: { revalidate: 3600 }, // ISR: revalidate every hour
}).then(r => r.json());
if (!post) notFound();
return <article>{post.title}</article>;
}Cache strategies:
cache option | Behavior |
force-cache | Cache indefinitely (default for fetch in RSC) |
no-store | Never cache — fresh on every request |
next: { revalidate: N } | ISR — revalidate after N seconds |
next: { tags: ['posts'] } | On-demand revalidation via tag |
Server Actions (mutations)
Server Actions run on the server. Use them for form submissions and mutations. Never use them for reads.
// app/posts/create/actions.ts
'use server';
import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';
import { z } from 'zod';
import { db } from '@/lib/db';
const CreatePostSchema = z.object({
title: z.string().min(1).max(200),
content: z.string().min(1),
});
export async function createPost(formData: FormData) {
const parsed = CreatePostSchema.safeParse({
title: formData.get('title'),
content: formData.get('content'),
});
if (!parsed.success) {
return { error: parsed.error.flatten().fieldErrors };
}
await db.post.create({ data: parsed.data });
revalidatePath('/posts');
redirect('/posts');
}// app/posts/create/page.tsx
import { createPost } from './actions';
export default function CreatePostPage() {
return (
<form action={createPost}>
<input name="title" type="text" required />
<textarea name="content" required />
<button type="submit">Create</button>
</form>
);
}Rules for Server Actions:
- Always validate input with Zod — do not trust
FormDatavalues - Return error objects for validation failures; use
redirect()for success - Call
revalidatePath()orrevalidateTag()after mutations that affect cached data - Never put secrets or auth logic in Client Components — keep it in actions
TanStack Query (client-side data)
Use TanStack Query for data that must stay fresh on the client: real-time feeds, user-specific data after mutations, optimistic updates.
// components/posts/post-list.tsx
'use client';
import { useQuery } from '@tanstack/react-query';
interface Post {
id: string;
title: string;
}
export function PostList() {
const { data, isLoading, error } = useQuery<Post[]>({
queryKey: ['posts'],
queryFn: () => fetch('/api/posts').then(r => r.json()),
staleTime: 60_000, // treat data as fresh for 60 seconds
});
if (isLoading) return <p>Loading...</p>;
if (error) return <p>Failed to load posts.</p>;
return (
<ul>
{data?.map(post => <li key={post.id}>{post.title}</li>)}
</ul>
);
}Do not use TanStack Query for data that a Server Component can fetch directly. The extra client-side fetch is unnecessary when the data can be fetched at render time on the server.
Route Handlers
Use route handlers for: webhooks, third-party OAuth callbacks, or endpoints consumed by non-Next.js clients.
// app/api/posts/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
import { db } from '@/lib/db';
const CreatePostBody = z.object({
title: z.string().min(1),
content: z.string().min(1),
});
export async function GET() {
const posts = await db.post.findMany({ orderBy: { createdAt: 'desc' } });
return NextResponse.json(posts);
}
export async function POST(request: NextRequest) {
const body = await request.json();
const parsed = CreatePostBody.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.flatten() },
{ status: 400 }
);
}
const post = await db.post.create({ data: parsed.data });
return NextResponse.json(post, { status: 201 });
}Metadata API
// app/posts/[id]/page.tsx
import type { Metadata } from 'next';
interface Props {
params: Promise<{ id: string }>;
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { id } = await params;
const post = await fetch(`/api/posts/${id}`).then(r => r.json());
return {
title: post.title,
description: post.excerpt,
openGraph: {
title: post.title,
images: [{ url: post.coverImage }],
},
};
}Never hardcode metadata in <head> tags — use the Metadata API. It handles
deduplication, inheritance, and streaming correctly.
Streaming with Suspense
// app/dashboard/page.tsx
import { Suspense } from 'react';
import { UserStats } from './user-stats'; // slow data fetch
import { RecentActivity } from './recent'; // fast data fetch
export default function DashboardPage() {
return (
<div>
<RecentActivity /> {/* renders immediately */}
<Suspense fallback={<p>Loading stats...</p>}>
<UserStats /> {/* streams in when ready */}
</Suspense>
</div>
);
}Wrap independently slow data sources in their own <Suspense> boundaries.
Do not wrap the entire page — that defeats streaming.
TypeScript Conventions
// Use type imports for type-only imports
import type { User } from '@prisma/client';
// Prefer interfaces for object shapes that may be extended
interface UserCardProps {
user: Pick<User, 'id' | 'name' | 'email'>;
onSelect?: (id: string) => void;
}
// Use type aliases for unions and computed types
type Status = 'active' | 'inactive' | 'pending';
type UserWithPosts = User & { posts: Post[] };Rules:
- Never use
any— useunknownand narrow with type guards - Use
satisfiesto validate objects against a type without widening - Co-locate type definitions with the component or function that uses them; export only what other modules need
- Use
next/navigationhooks (useRouter,usePathname) notnext/router— the latter is Pages Router only
Project Structure
app/
(auth)/ — route group, no URL segment
login/page.tsx
register/page.tsx
(dashboard)/
dashboard/page.tsx
posts/
[id]/page.tsx
create/
page.tsx
actions.ts
api/
posts/route.ts
layout.tsx — root layout
not-found.tsx
components/
ui/ — generic, reusable components
posts/ — domain-specific components
lib/
db.ts — database client
auth.ts — auth configuration
queries.ts — reusable server-side query functionsDoes 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.

