Next.js App Router in Core
Core's apps (apps/admin, apps/donor, apps/missionary, apps/factory-console) use the App Router with cacheComponents: true and partialPrefetching: true. Read the installed docs under node_modules/next/dist/docs/ for API details; this skill covers the Core-specific decisions.
Rules
- Server-first: Default to Server Components; add
'use client'only for interactivity or browser APIs, as a small leaf. - Every server
awaitis a decision: Stream it behind<Suspense>, cache it with'use cache', or block deliberately withexport const instant = falseplus a reason comment. A bare top-levelawaitin a page or layout blocks the App Shell. Details:docs/ai/skills/cache-components/SKILL.mdand the Instant Navigation section ofdocs/ai/rules/frontend.md. - Data ownership: Business queries and privileged mutations live in
packages/api; pages and route handlers call it and stay thin. Browser-visible table data uses@asym/databasecollections and hooks. Seedocs/guides/architecture/data-access-boundary.md. - Mutations: Use Server Actions or
packages/apicommands for privileged writes, and invalidate the affected cache tags (updateTagin Server Actions). - No removed segment config:
dynamic,revalidate,fetchCache, anddynamicParamsexports are unavailable with Cache Components. - Errors: Use
error.tsxandnot-found.tsxfor route-level handling. - Page composition: For feature folders, colocated Suspense skeletons, and leaf-client UX, also load
docs/ai/skills/nextjs-app-architecture/SKILL.md.
Checklist
- [ ] Server Components by default; client components small and justified
- [ ] Each server
awaitstreamed, cached, or deliberately blocked with a reason - [ ]
<Suspense>boundaries close to the dynamic read, not around the whole page body - [ ] Business data and privileged mutations go through
packages/api - [ ] Mutations invalidate the correct cache tags
- [ ] Route-level errors handled via
error.tsx/not-found.tsx
Example
import { Suspense } from "react";
export default function Page() {
return (
<>
<PageHeader />
<Suspense fallback={<DonorListSkeleton />}>
<DonorList />
</Suspense>
</>
);
}
async function DonorList() {
const donors = await listDonorsForCurrentUser(); // request-time read, streamed
return <DonorTable donors={donors} />;
}