agentleFS
bkjain655bkjain655/agent-skills/skills/nextjs-app-router/SKILL.md

nextjs-app-router

Skill0 starsChanged 3 months agoMITView on GitHub

Next.js App Router patterns: layouts, loading/error boundaries, Server and Client Components, route groups, and env helpers. Use when building or refactoring Next.js 13+ App Router applications.

  • Reads credentials

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use skill-creator.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SentrySkill

    skill-creator

    Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer Link for internal routes.

    line 68
  2. Very specific:

    Document every var in .env.example.

    line 80

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Next.js App Router

File conventions

FilePurpose
layout.tsxShared shell; export metadata when page is client
page.tsxRoute UI — Server Component by default
loading.tsxSuspense fallback for segment
error.tsxError boundary ("use client")
not-found.tsx404 for segment
route.tsAPI route handler

Route groups (optional)

app/
  (marketing)/
    layout.tsx    → light marketing chrome
    page.tsx
  (app)/
    layout.tsx    → app shell / auth gate
    dashboard/page.tsx

Groups don't affect URL path.

Metadata on client pages

Client page.tsx cannot export metadata — use sibling layout.tsx:

// app/dashboard/layout.tsx
import type { Metadata } from "next";
export const metadata: Metadata = { title: "Dashboard", robots: { index: false } };
export default function Layout({ children }: { children: React.ReactNode }) {
  return children;
}

Server Component data

// Server Component — no "use client"
export default async function Page() {
  const data = await fetchData(); // or direct DB
  return <ClientView initial={data} />;
}

Pass serializable props only to client children.

Navigation

import Link from "next/link";
import { useRouter, usePathname, useSearchParams } from "next/navigation";

Prefer Link for internal routes; router.replace for redirects after guard checks.

Env helpers (lib/env.ts)

Centralize reads — never scatter process.env in components:

export function getSiteUrl(): string {
  return process.env.NEXT_PUBLIC_SITE_URL ?? "http://localhost:3000";
}

Document every var in .env.example; upsert .env when adding new vars.

Root layout checklist

- [ ] lang on <html>
- [ ] fonts via next/font
- [ ] global providers (theme, tooltip, analytics)
- [ ] SkipToMain link
- [ ] metadataBase for production URLs

Anti-patterns

  • Fetching in client what server could fetch once
  • Importing server-only modules into client components
  • Multiple nested "use client" boundaries without reason
  • Hardcoding URLs instead of env-based getSiteUrl()

Pair with: nextjs-ui-foundation, nextjs-seo-metadata, nextjs-api-routes.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.