Claude Code के साथ Accelerating Next.js Full-Stack Development
Claude Code का उपयोग करके accelerating next.js full-stack development सीखें। Practical tips और code examples शामिल हैं।
Next.js × Claude Code सेフルスタックdevelopment
Next.jsのApp Routerは、フロントエンドとバックエンドをintegration的にdevelopmentできるframework है।Claude Code के साथ combineる बातで、page、APIroute、databaseintegration तकを一気にbuild किया जा सकता है。
Projectの初期setup
> Next.js 14 + TypeScript + Tailwind CSS + Prismaの
> Projectをबनाओ。App Routerを使用。
> निम्नलिखितの構成で:
> - src/app: page・layout
> - src/components: 共通component
> - src/lib: utility・DB接続
> - prisma: スkeyマ・migration
Server Componentsのutilization
dataフェッチングをServer Componentsでकरनाpattern generateさせ है।
> ブlog記事listpageをServer Componentでबनाओ。
> Prisma सेdatafetch。pageネーションsupport。
// src/app/posts/page.tsx
import { prisma } from "@/lib/prisma";
import { PostCard } from "@/components/PostCard";
import { Pagination } from "@/components/Pagination";
interface Props {
searchParams: Promise<{ page?: string }>;
}
export default async function PostsPage({ searchParams }: Props) {
const { page: pageParam } = await searchParams;
const page = Number(pageParam) || 1;
const perPage = 12;
const [posts, total] = await Promise.all([
prisma.post.findMany({
take: perPage,
skip: (page - 1) * perPage,
orderBy: { createdAt: "desc" },
include: { author: { select: { name: true, avatar: true } } },
}),
prisma.post.count(),
]);
return (
<main className="container mx-auto px-4 py-8">
<h1 className="mb-8 text-3xl font-bold">記事list</h1>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{posts.map((post) => (
<PostCard key={post.id} post={post} />
))}
</div>
<Pagination
currentPage={page}
totalPages={Math.ceil(total / perPage)}
basePath="/posts"
/>
</main>
);
}
export const metadata = {
title: "記事list",
description: "सभीの記事 displayします",
};
Server Actionsのutilization
formprocessingをServer Actionsでimplement करते हैं。
> 記事createformをServer Actionsでimplement करो。
> validationはzod、error handlingも含めて。
// src/app/posts/new/actions.ts
"use server";
import { prisma } from "@/lib/prisma";
import { redirect } from "next/navigation";
import { z } from "zod";
const CreatePostSchema = z.object({
title: z.string().min(1, "タイトルは必須です").max(200),
content: z.string().min(10, "本文は10文字以ऊपरज़रूरीです"),
published: z.boolean().default(false),
});
export type FormState = {
errors?: Record<string, string[]>;
message?: string;
};
export async function createPost(
prevState: FormState,
formData: FormData
): Promise<FormState> {
const parsed = CreatePostSchema.safeParse({
title: formData.get("title"),
content: formData.get("content"),
published: formData.get("published") === "on",
});
if (!parsed.success) {
return { errors: parsed.error.flatten().fieldErrors };
}
await prisma.post.create({
data: { ...parsed.data, authorId: "current-user-id" },
});
redirect("/posts");
}
API Routeのcreate
बाहर部integration用のAPI Routeも同時にcreateでき है।
> /api/posts のRoute Handlerをबनाओ。
> GET(list・search・pageネーション)と POST(create)。
> authenticationcheckも含めて。
// src/app/api/posts/route.ts
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth";
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const page = Number(searchParams.get("page")) || 1;
const q = searchParams.get("q") || "";
const limit = 20;
const where = q
? { title: { contains: q, mode: "insensitive" as const } }
: {};
const [posts, total] = await Promise.all([
prisma.post.findMany({
where,
take: limit,
skip: (page - 1) * limit,
orderBy: { createdAt: "desc" },
}),
prisma.post.count({ where }),
]);
return NextResponse.json({
data: posts,
meta: { page, limit, total },
});
}
export async function POST(request: NextRequest) {
const session = await auth();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const body = await request.json();
const post = await prisma.post.create({
data: { ...body, authorId: session.user.id },
});
return NextResponse.json({ data: post }, { status: 201 });
}
middlewareのsettings
authenticationroutingをmiddlewareで制御し है।
> authenticationがज़रूरीなrouteをmiddlewareで保護して。
> /dashboard, /posts/new, /api/posts(POST) はauthentication必須。
DBintegrationके details के लिएDBmigrationautomationを、Reactcomponentの設計はReactdevelopmentを爆速にする方法をदेखें。日々のdevelopment効率をऊपरげるコツは生産性を3倍にする10のTipsもあわせてदेखें。
Summary
Claude CodeとNext.jsの組み合わせは、フルスタックdevelopmentを劇的に加速し है।Server Components、Server Actions、API Routeを一貫してgenerateできるため、フロントエンド सेバックエンド तकシームレスにdevelopmentを進められ है।
Next.jsके details के लिएNext.jsofficial documentation、Claude Codeके बारे मेंはAnthropicofficial documentationをदेखें。
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।