nextjs-shadcn by laguagu/claude-code-nextjs-skills
npx skills add https://github.com/laguagu/claude-code-nextjs-skills --skill nextjs-shadcn构建独特、生产级的界面,避免千篇一律的“AI 风格”美学。
globals.css 中的 CSS 变量,绝不硬编码颜色bunx --bun shadcn@latest create --preset "https://ui.shadcn.com/init?base=radix&style=nova&baseColor=neutral&iconLibrary=lucide&font=geist-sans" --template next
// page.tsx - 仅包含内容,不包含布局框架
export default function Page() {
return (
<>
<HeroSection />
<Features />
<Testimonials />
</>
);
}
// layout.tsx - 共享 UI(页头、页脚、侧边栏)
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
<Header />
<main>{children}</main>
<Footer />
</>
);
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
"use client" 仅用于叶子组件(最小边界)children 传递服务器端内容始终使用 @/ 别名(例如 @/lib/utils),而不是相对路径(../../lib/utils)。
import { cn } from "@/lib/utils";
function Button({ className, ...props }) {
return <button className={cn("px-4 py-2 rounded", className)} {...props} />;
}
app/
├── (protected)/ # 需要身份验证的路由
│ ├── dashboard/
│ ├── settings/
│ ├── components/ # 路由特定组件
│ └── lib/ # 路由特定工具/类型
├── (public)/ # 公开路由
│ ├── login/
│ └── register/
├── actions/ # Server Actions(全局)
├── api/ # API 路由
├── layout.tsx # 根布局
└── globals.css # 主题变量
components/ # 共享组件
├── ui/ # shadcn 基础组件
└── shared/ # 业务组件
hooks/ # 自定义 React 钩子
lib/ # 共享工具
data/ # 数据库查询
ai/ # AI 逻辑(工具、代理、提示词)
export default async function Page({
params,
searchParams,
}: {
params: Promise<{ id: string }>;
searchParams: Promise<{ q?: string }>;
}) {
const { id } = await params;
const { q } = await searchParams;
}
关键规则:
Server Actions = 仅用于变更操作(创建、更新、删除)
数据获取 = 在 Server Components 或 'use cache' 函数中
// ❌ 错误:使用 Server Action 获取数据 "use server" export async function getUsers() { return await db.users.findMany() }
// ✅ 正确:使用带缓存的数据函数 // data/users.ts export async function getUsers() { "use cache" cacheTag("users") cacheLife("hours") return await db.users.findMany() }
// ✅ 正确:直接在 Server Component 中读取 cookies export default async function Page() { const theme = (await cookies()).get("theme")?.value ?? "light" return <App theme={theme} /> }
"use cache";
import { cacheTag, cacheLife } from "next/cache";
export async function getProducts() {
cacheTag("products");
cacheLife("hours");
return await db.products.findMany();
}
"use server";
import { updateTag, revalidateTag } from "next/cache";
import { z } from "zod";
const schema = z.object({
title: z.string().min(1),
content: z.string(),
});
export async function createPost(formData: FormData) {
// 始终验证输入
const parsed = schema.parse({
title: formData.get("title"),
content: formData.get("content"),
});
await db.insert(posts).values(parsed);
updateTag("posts"); // 读写一致性
}
使用 proxy.ts 进行请求拦截(替代中间件)。放置在项目根目录:
// proxy.ts(项目根目录,与 app/ 同级)
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function proxy(request: NextRequest) {
// 身份验证检查、重定向等
}
export const config = {
matcher: ['/dashboard/:path*'],
}
始终使用 bun,绝不使用 npm 或 npx:
bun install(而非 npm install)bun add(而非 npm install package)bunx --bun(而非 npx)每周安装量
160
代码仓库
GitHub 星标数
16
首次出现
2026 年 1 月 26 日
安全审计
已安装于
opencode145
codex143
gemini-cli142
cursor141
github-copilot140
kimi-cli131
Build distinctive, production-grade interfaces that avoid generic "AI slop" aesthetics.
globals.css, never hardcode colorsbunx --bun shadcn@latest create --preset "https://ui.shadcn.com/init?base=radix&style=nova&baseColor=neutral&iconLibrary=lucide&font=geist-sans" --template next
// page.tsx - content only, no layout chrome
export default function Page() {
return (
<>
<HeroSection />
<Features />
<Testimonials />
</>
);
}
// layout.tsx - shared UI (header, footer, sidebar)
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
<Header />
<main>{children}</main>
<Footer />
</>
);
}
"use client" only at leaf components (smallest boundary)childrenAlways use @/ alias (e.g., @/lib/utils) instead of relative paths (../../lib/utils).
import { cn } from "@/lib/utils";
function Button({ className, ...props }) {
return <button className={cn("px-4 py-2 rounded", className)} {...props} />;
}
app/
├── (protected)/ # Auth required routes
│ ├── dashboard/
│ ├── settings/
│ ├── components/ # Route-specific components
│ └── lib/ # Route-specific utils/types
├── (public)/ # Public routes
│ ├── login/
│ └── register/
├── actions/ # Server Actions (global)
├── api/ # API routes
├── layout.tsx # Root layout
└── globals.css # Theme tokens
components/ # Shared components
├── ui/ # shadcn primitives
└── shared/ # Business components
hooks/ # Custom React hooks
lib/ # Shared utils
data/ # Database queries
ai/ # AI logic (tools, agents, prompts)
export default async function Page({
params,
searchParams,
}: {
params: Promise<{ id: string }>;
searchParams: Promise<{ q?: string }>;
}) {
const { id } = await params;
const { q } = await searchParams;
}
CRITICAL RULE:
Server Actions = ONLY for mutations (create, update, delete)
Data fetching = In Server Components or 'use cache' functions
// ❌ WRONG: Server Action for data fetching "use server" export async function getUsers() { return await db.users.findMany() }
// ✅ CORRECT: Data function with caching // data/users.ts export async function getUsers() { "use cache" cacheTag("users") cacheLife("hours") return await db.users.findMany() }
// ✅ CORRECT: Read cookies in Server Component directly export default async function Page() { const theme = (await cookies()).get("theme")?.value ?? "light" return <App theme={theme} /> }
"use cache";
import { cacheTag, cacheLife } from "next/cache";
export async function getProducts() {
cacheTag("products");
cacheLife("hours");
return await db.products.findMany();
}
"use server";
import { updateTag, revalidateTag } from "next/cache";
import { z } from "zod";
const schema = z.object({
title: z.string().min(1),
content: z.string(),
});
export async function createPost(formData: FormData) {
// Always validate input
const parsed = schema.parse({
title: formData.get("title"),
content: formData.get("content"),
});
await db.insert(posts).values(parsed);
updateTag("posts"); // Read-your-writes
}
Use proxy.ts for request interception (replaces middleware). Place at project root:
// proxy.ts (project root, same level as app/)
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function proxy(request: NextRequest) {
// Auth checks, redirects, etc.
}
export const config = {
matcher: ['/dashboard/:path*'],
}
Always use bun , never npm or npx:
bun install (not npm install)bun add (not npm install package)bunx --bun (not npx)Weekly Installs
160
Repository
GitHub Stars
16
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode145
codex143
gemini-cli142
cursor141
github-copilot140
kimi-cli131
UI组件模式实战指南:构建可复用React组件库与设计系统
10,700 周安装