app-router-patterns

app-router-patterns is a cursor rule for Cursor from tugkanboz/awesome-cursorrules. It costs 2,554 tokens per session, scanned A, original, MIT.

A set of patterns for building applications with the Next.js App Router, the file-based routing system in modern Next.js. It explains when to use server-side components, browser-side components, route handlers, server actions, and metadata.

In plain words
What is it for?
Use it when creating or reviewing Next.js pages, data access, interactive React components, API-like route handlers, server actions, and page metadata.
Why use it?
It helps an agent choose where data fetching and interactivity belong, reducing unnecessary browser code and common App Router mistakes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tugkanboz/awesome-cursorrules/app-router-patterns
Clone the repo
git clone --depth 1 https://github.com/tugkanboz/awesome-cursorrules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for app-router-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/tugkanboz/awesome-cursorrules/app-router-patterns.svg)](https://agentmods.dev/rules/tugkanboz/awesome-cursorrules/app-router-patterns)
Your own site
<a href="https://agentmods.dev/rules/tugkanboz/awesome-cursorrules/app-router-patterns"><img src="https://agentmods.dev/badge/rules/tugkanboz/awesome-cursorrules/app-router-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,554 This file is loaded in full into every session.
When invoked 2,554 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02554 $0.02554
Opus 5 $0.01277 $0.01277
Sonnet 5 $0.00511 $0.00511
Haiku 4.5 $0.00255 $0.00255

Measured 4d ago against content hash 01656ff9b25e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

app-router-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

example-structures/next-js/.cursor/rules/app-router-patterns.mdc · 374 lines

How it starts

The opening of the file, as written. The whole thing — 374 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Next.js App Router Excellence

Server Components vs Client Components

  • Default is Server Component — every file in app/ is a Server Component unless marked otherwise
  • Add "use client" only at the boundary where you need browser APIs, event handlers, or React state
  • Keep "use client" components as leaf nodes; wrap them in Server Components for data fetching
  • Never fetch data inside a Client Component when a Server Component parent can pass it as a prop
// ✅ Server Component — async, direct DB/API access, no "use client"
// app/products/page.tsx
import { db } from '@/lib/db'

export default async function ProductsPage() {
  const products = await db.product.findMany({ orderBy: { createdAt: 'desc' } })

  return (
    <main>
      <h1>Products</h1>
      {products.map((product) => (
        <ProductCard key={product.id} product={product} />
      ))}
    </main>
  )
}

// ✅ Client Component — only for interactivity
// components/add-to-cart-button.tsx
'use client'

import { useState } from 'react'

interface AddToCartButtonProps {
  productId: string
}

export function AddToCartButton({ productId }: AddToCartButtonProps) {
  const [loading, setLoading] = useState(false)

  const handleAdd = async () => {
    setLoading(true)
    await addToCart(productId)
    setLoading(false)
  }

  return (
    <button onClick={handleAdd} disabled={loading}>
      {loading ? 'Adding…' : 'Add to Cart'}
    </button>
  )
}

App Router File Conventions

app/
├── layout.tsx          # Root layout — wraps all routes, runs once
├── page.tsx            # Route UI rendered at /
├── loading.tsx         # Automatic Suspense boundary for this segment
├── error.tsx           # Error boundary ("use client" required)
├── not-found.tsx       # Rendered by notFound() or unmatched routes
├── global-error.tsx    # Error boundary for root layout
├── route.ts            # API Route Handler (no page.tsx in same segment)
├── template.tsx        # Like layout but re-mounts on navigation
└── products/
    ├── page.tsx         # Renders at /products
    ├── [id]/
    │   └── page.tsx     # Renders at /products/:id
    └── (marketing)/     # Route group — ignored in URL path
        └── page.tsx

Read the full file on GitHub · 374 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 374 lines · 2,554 tokens per session scan A 01656ff9b25e

Subscribe to this mod's changes

app-router-patterns is a cursor rule published in the GitHub repository tugkanboz/awesome-cursorrules (20 stars, last pushed yesterday), licensed MIT. It adds 2,554 tokens to every session, about $0.0128 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other cursor rules, from other repositories

cursorrules

You are building an AI/ML project with Python. The project uses PyTorch for model training, handles data pipelines with proper validation, tracks experiments systematically, and follows production ML engineering practices. Code is type-hinted, tested, and reproducible.

survivorforge/cursor-rules · 2,136 tokens

refactoring

Refactoring: systematic approach, extract/inline, guard clauses, early returns.

nedcodes-ok/cursorrules-collection · 683 tokens

unity-input

Guidelines for working with the New Input System in Unity 6.2.

Common-ka/ai-agent-unity-rules · 0 tokens

unity-ui

Assets/ ├── UI/ │ ├── Runtime/ │ │ ├── Controllers/ │ │ │ └── MainMenuController.cs │ │ ├── Views/ │ │ │ └── MainMenuView.cs │ │ ├── ViewModels/ │ │ │ └── HealthViewModel.cs │ │ ├── UXML/ │ │ │ └── MainMenu.uxml │ │ └── USS/ │ │ └── MainMenu.uss │ └── Editor/ │ └── UIBuilderExtensions.cs.

Common-ka/ai-agent-unity-rules · 0 tokens

code-organization

Assets/ ├── !Project/ # Main project content (! keeps it at top) │ ├── Art/ │ │ ├── Materials/ │ │ ├── Models/ │ │ ├── Textures/ │ │ └── Animations/ │ ├── Audio/ │ │ ├── Music/ │ │ ├── SFX/ │ │ └── Mixers/ │ ├── Prefabs/ │ │ ├── Characters/ │ │ ├── Environment/ │ │ ├── UI/ │ │ └── Effects/ │ ├── Scenes/ │ │ ├──…

Common-ka/ai-agent-unity-rules · 1,948 tokens

unity-core

// ✅ DO: PascalCase public class PlayerController : MonoBehaviour { }.

Common-ka/ai-agent-unity-rules · 1,779 tokens