From 99d1c64ac9c8006aff01d52c51e952d1cbdb1dd7 Mon Sep 17 00:00:00 2001 From: Ufuk Cetinkaya Date: Thu, 26 Feb 2026 12:36:13 +0300 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20claude=20code=20kod=20=C3=BCretme?= =?UTF-8?q?=20komutlar=C4=B1=20eklendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CLAUDE.md ve 6 adet slash command eklendi: - /component: React component oluşturma - /page: Next.js sayfa oluşturma - /hook: Custom React hook oluşturma - /form: Validasyonlu form componenti - /api: API route handler oluşturma - /layout: Next.js layout componenti --- .claude/commands/api.md | 140 +++++++++++++++++++++++++++++ .claude/commands/component.md | 104 ++++++++++++++++++++++ .claude/commands/form.md | 117 +++++++++++++++++++++++++ .claude/commands/hook.md | 89 +++++++++++++++++++ .claude/commands/layout.md | 160 ++++++++++++++++++++++++++++++++++ .claude/commands/page.md | 115 ++++++++++++++++++++++++ CLAUDE.md | 66 ++++++++++++++ 7 files changed, 791 insertions(+) create mode 100644 .claude/commands/api.md create mode 100644 .claude/commands/component.md create mode 100644 .claude/commands/form.md create mode 100644 .claude/commands/hook.md create mode 100644 .claude/commands/layout.md create mode 100644 .claude/commands/page.md create mode 100644 CLAUDE.md diff --git a/.claude/commands/api.md b/.claude/commands/api.md new file mode 100644 index 0000000..cda65a8 --- /dev/null +++ b/.claude/commands/api.md @@ -0,0 +1,140 @@ +--- +description: Next.js API route handler olusturur (App Router). Ornek: /api users - Kullanici CRUD endpointleri +argument-hint: route-yolu - Aciklama ve HTTP metodlari +--- + +Asagidaki bilgilere gore bir Next.js API route handler olustur: + +$ARGUMENTS + +## Kurallar + +### Dosya Konumu +- Route handler: `app/api/[route-yolu]/route.ts` +- Ic ice route: `app/api/[ust]/[alt]/route.ts` +- Dinamik route: `app/api/[route]/[id]/route.ts` + +### Route Handler Yapisi +```ts +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(request: NextRequest) { + try { + // Islem mantigi + + return NextResponse.json({ data }, { status: 200 }); + } catch (error) { + console.error("[GET /api/route]:", error); + return NextResponse.json( + { error: "Sunucu hatasi" }, + { status: 500 }, + ); + } +} + +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + + // Validasyon + // Islem mantigi + + return NextResponse.json({ data }, { status: 201 }); + } catch (error) { + console.error("[POST /api/route]:", error); + return NextResponse.json( + { error: "Sunucu hatasi" }, + { status: 500 }, + ); + } +} +``` + +### Dinamik Route Handler +```ts +import { NextRequest, NextResponse } from "next/server"; + +interface RouteParams { + params: Promise<{ id: string }>; +} + +export async function GET(request: NextRequest, { params }: RouteParams) { + const { id } = await params; + + try { + return NextResponse.json({ data }, { status: 200 }); + } catch (error) { + console.error(`[GET /api/route/${id}]:`, error); + return NextResponse.json( + { error: "Kayit bulunamadi" }, + { status: 404 }, + ); + } +} + +export async function PUT(request: NextRequest, { params }: RouteParams) { + const { id } = await params; + const body = await request.json(); + + try { + return NextResponse.json({ data }, { status: 200 }); + } catch (error) { + console.error(`[PUT /api/route/${id}]:`, error); + return NextResponse.json( + { error: "Sunucu hatasi" }, + { status: 500 }, + ); + } +} + +export async function DELETE(request: NextRequest, { params }: RouteParams) { + const { id } = await params; + + try { + return NextResponse.json({ message: "Basariyla silindi" }, { status: 200 }); + } catch (error) { + console.error(`[DELETE /api/route/${id}]:`, error); + return NextResponse.json( + { error: "Sunucu hatasi" }, + { status: 500 }, + ); + } +} +``` + +### Zorunlu Kurallar +1. **Server-only**: Route handler'lar her zaman server-side calisir, `"use client"` KULLANMA +2. **TypeScript**: Request body, response ve params icin tip tanimla +3. **Next.js 16 params**: `params` artik `Promise` — `await` ile eris +4. **Hata yonetimi**: Her handler'i try/catch ile sar +5. **HTTP status kodlari**: Dogru status kodlarini kullan (200, 201, 400, 404, 500) +6. **Loglama**: Hatalarda `console.error` ile endpoint bilgisini logla +7. **Validasyon**: POST/PUT body'sini islemeden once dogrula + +### Query Parameter Okuma +```ts +export async function GET(request: NextRequest) { + const searchParams = request.nextUrl.searchParams; + const page = parseInt(searchParams.get("page") || "1", 10); + const limit = parseInt(searchParams.get("limit") || "10", 10); +} +``` + +### Response Tipleri +```ts +// JSON response +return NextResponse.json({ data }, { status: 200 }); + +// Bos response +return new NextResponse(null, { status: 204 }); + +// Header ile response +return NextResponse.json(data, { + headers: { "Cache-Control": "max-age=3600" }, +}); +``` + +Dosyayi olusturduktan sonra kullaniciya bilgi ver: +- Olusturulan dosya yolu +- Endpoint URL'leri ve HTTP metodlari +- Request/Response format ornekleri diff --git a/.claude/commands/component.md b/.claude/commands/component.md new file mode 100644 index 0000000..5584348 --- /dev/null +++ b/.claude/commands/component.md @@ -0,0 +1,104 @@ +--- +description: Yeni bir React component olusturur. Ornek: /component Button - Tiklanabilir buton componenti +argument-hint: ComponentAdi - Kisa aciklama +--- + +Asagidaki bilgilere gore bir React component olustur: + +$ARGUMENTS + +## Kurallar + +### Dosya Konumu +- Temel UI componenti ise (Button, Input, Card, Modal, Badge...): `components/ui/ComponentAdi.tsx` +- Ozellige ozel component ise: `components/ComponentAdi.tsx` +- Eger aciklamada farkli bir konum belirtilmisse, onu kullan + +### Component Yapisi +```tsx +// Gerekli ise "use client" en uste ekle (useState, useEffect, event handler varsa) + +interface ComponentAdiProps { + // Props tanimla +} + +export default function ComponentAdi({ ...props }: ComponentAdiProps) { + return ( + // JSX + ); +} +``` + +### Zorunlu Kurallar +1. **TypeScript**: Props icin interface tanimla, `any` kullanma +2. **Tailwind CSS**: Stil icin sadece Tailwind class'lari kullan, inline style veya CSS module kullanma +3. **Server Component varsayilan**: `"use client"` sadece interaktivite gerekiyorsa ekle +4. **Default export** kullan +5. **Dosya adi** PascalCase olmali +6. **Responsive**: Mobile-first yaklasim, `sm:`, `md:`, `lg:` breakpoint'leri kullan +7. **Dark mode**: `dark:` prefix ile karanlik tema destegi ekle +8. **Erisilebilirlik**: Uygun ARIA attribute'leri, semantik HTML etiketleri kullan +9. **Import path**: `@/` alias kullan (ornek: `@/components/ui/Button`) + +### Props Tasarimi +- Opsiyonel prop'lar icin `?` kullan +- `className` prop'u kabul et (kullanicinin stil ekleyebilmesi icin) +- Event handler'lar icin uygun React tipi kullan (`React.MouseEvent`, `React.ChangeEvent` vb.) +- children prop'u gerekliyse `React.ReactNode` tipinde tanimla + +### Ornek Cikti Yapisi +Eger `/component Button - Tiklanabilir buton componenti, variant ve size destegi` yazildiysa: + +```tsx +"use client"; + +interface ButtonProps { + children: React.ReactNode; + variant?: "primary" | "secondary" | "outline" | "ghost"; + size?: "sm" | "md" | "lg"; + disabled?: boolean; + className?: string; + onClick?: React.MouseEventHandler; +} + +export default function Button({ + children, + variant = "primary", + size = "md", + disabled = false, + className = "", + onClick, +}: ButtonProps) { + const baseStyles = + "inline-flex items-center justify-center rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none"; + + const variants = { + primary: "bg-foreground text-background hover:bg-foreground/90 focus:ring-foreground", + secondary: + "bg-zinc-100 text-zinc-900 hover:bg-zinc-200 dark:bg-zinc-800 dark:text-zinc-100 dark:hover:bg-zinc-700", + outline: "border border-zinc-300 hover:bg-zinc-100 dark:border-zinc-700 dark:hover:bg-zinc-800", + ghost: "hover:bg-zinc-100 dark:hover:bg-zinc-800", + }; + + const sizes = { + sm: "h-8 px-3 text-sm", + md: "h-10 px-4 text-base", + lg: "h-12 px-6 text-lg", + }; + + return ( + + ); +} +``` + +Dosyayi olusturduktan sonra kullaniciya bilgi ver: +- Dosya yolu +- Kullanim ornegi (import + JSX) +- Eklenen prop'larin listesi diff --git a/.claude/commands/form.md b/.claude/commands/form.md new file mode 100644 index 0000000..6a50aad --- /dev/null +++ b/.claude/commands/form.md @@ -0,0 +1,117 @@ +--- +description: Validasyonlu form componenti olusturur. Ornek: /form LoginForm - Email ve sifre ile giris formu +argument-hint: FormAdi - Form alanlari ve aciklama +--- + +Asagidaki bilgilere gore validasyonlu bir form componenti olustur: + +$ARGUMENTS + +## Kurallar + +### Dosya Konumu +- Form component'leri: `components/forms/FormAdi.tsx` + +### Form Yapisi +```tsx +"use client"; + +import { useState, type FormEvent } from "react"; + +interface FormAdiData { + // Form alanlari +} + +interface FormAdiErrors { + // Hata alanlari (her alan opsiyonel string) +} + +interface FormAdiProps { + onSubmit: (data: FormAdiData) => void | Promise; + className?: string; +} + +export default function FormAdi({ onSubmit, className = "" }: FormAdiProps) { + const [formData, setFormData] = useState({ /* varsayilan degerler */ }); + const [errors, setErrors] = useState({}); + const [isSubmitting, setIsSubmitting] = useState(false); + + function validate(data: FormAdiData): FormAdiErrors { + const newErrors: FormAdiErrors = {}; + // Validasyon kurallari + return newErrors; + } + + async function handleSubmit(e: FormEvent) { + e.preventDefault(); + const validationErrors = validate(formData); + setErrors(validationErrors); + + if (Object.keys(validationErrors).length > 0) return; + + setIsSubmitting(true); + try { + await onSubmit(formData); + } catch { + // Hata yonetimi + } finally { + setIsSubmitting(false); + } + } + + return ( +
+ {/* Form alanlari */} +
+ ); +} +``` + +### Zorunlu Kurallar +1. **"use client"**: Form'lar her zaman client component +2. **TypeScript**: Form data ve error tipleri icin interface tanimla +3. **Tailwind CSS**: Tum stiller Tailwind ile +4. **Validasyon**: Client-side validasyon ZORUNLU +5. **Hata gosterimi**: Her alanin altinda hata mesaji goster +6. **Loading durumu**: Submit sirasinda buton disabled + yukleniyor gostergesi +7. **Erisilebilirlik**: + - `