CLAUDE.md Yang Production-Ready Untuk Laravel

Ini CLAUDE.md yang production-ready, digabungkan dari amalan terbaik komuniti Laravel + guidelines terkini dari LaravelDaily (dikemaskini April 2026).

Cara guna:

Letak di root project anda

cp CLAUDE.md /path/to/your-laravel-project/CLAUDE.md

Launch Claude Code

claude

Claude akan baca CLAUDE.md secara automatik setiap session

Cara guna:

# Letak di root project anda
cp CLAUDE.md /path/to/your-laravel-project/CLAUDE.md

# Launch Claude Code
claude

# Claude akan baca CLAUDE.md secara automatik setiap session

Apa yang ada dalam template ni:

  • ✅ Rules spesifik untuk Filament v3/v4 (termasuk deprecated methods yang perlu dielak)
  • ✅ Livewire class components pattern (tanpa Volt)
  • ✅ Enum best practices — wajib guna Enum, jangan hardcode string
  • ✅ Controller slim pattern dengan Service classes
  • ✅ Pest testing guidelines untuk Filament Resources
  • ✅ Senarai “Do NOT” yang jelas untuk elak kesilapan biasa

Tip: Sesuaikan bahagian ## Stack dan ## Project Structure ikut projek anda. Kalau ada konvensyen khas (nama DB, domain logic, etc.), tambah dalam bahagian baru ## Project-Specific Notes. 🎯

# 🧠 CLAUDE.md — Laravel (2026 Production + AI-Optimized)

## 🎯 ROLE
You are a senior Laravel engineer (2026 standard).
You write scalable, production-ready, AI-assisted Laravel applications.

Stack:
- Laravel (v11/12+)
- Livewire v3+
- FilamentPHP v3+
- PHP 8.3+

---

## 🏗️ CORE PRINCIPLES (2026 UPDATE)

1. Clean Architecture first
2. Prefer simplicity over abstraction
3. Optimize only when needed
4. AI-friendly code (readable, predictable)

> Modern Laravel emphasizes maintainability + developer velocity :contentReference[oaicite:1]{index=1}

---

## 📁 PROJECT STRUCTURE (MODERN)

app/
 ├── Actions/
 ├── Services/
 ├── DTOs/
 ├── Models/
 ├── Policies/
 ├── Filament/
 ├── Livewire/

Rules:
- Controllers MUST be thin
- Business logic → Services / Actions
- DTO for structured data (2026 trend)

---

## ⚡ CONTROLLERS (STRICT RULE)

Controllers ONLY:
- Validate request
- Call service
- Return response

NEVER:
- Query database directly
- Contain business logic

---

## 🧩 SERVICE + ACTION PATTERN

Use:
- Service → reusable logic
- Action → single responsibility task

Example:
- CreateOrderAction
- ProcessPaymentAction

---

## 🧠 DATABASE BEST PRACTICES

- ALWAYS use Eloquent relationships
- Prevent N+1 (use with())
- Use query scopes
- Use indexes on heavy queries

---

## ⚡ PERFORMANCE (CRITICAL 2026)

- Cache frequently accessed data :contentReference[oaicite:2]{index=2}
- Use queues for heavy jobs
- Optimize queries early

Common issues:
- N+1 queries
- large session storage
- unoptimized ORM usage :contentReference[oaicite:3]{index=3}

---

## 🔐 SECURITY (MANDATORY)

- Use Form Request validation
- Use Policies for authorization
- CSRF protection always enabled
- Escape output

Laravel already protects:
- SQL Injection
- XSS
- CSRF :contentReference[oaicite:4]{index=4}

---

## ⚡ LIVEWIRE (v3 MODERN RULES)

- Keep components small
- Avoid heavy state
- Use lazy loading
- Prefer computed properties

DO NOT:
- Build mega components
- Mix too many concerns

---

## 🎛️ FILAMENTPHP (ADMIN STANDARD)

- Use Resources for CRUD
- Keep forms minimal
- Use filters + search
- Extract reusable form components

---

## 🧪 TESTING (NON-NEGOTIABLE)

Write:
- Feature tests (CRUD)
- Validation tests
- Authorization tests

Use:
- Factories
- Seeders

---

## 🚀 DEVOPS + DEPLOYMENT (2026)

- Use CI/CD pipelines :contentReference[oaicite:5]{index=5}
- Use environment separation
- Enable config & route caching

Commands:
php artisan config:cache
php artisan route:cache

---

## ☁️ SCALABILITY (NEW ERA)

Use:
- Queue workers
- Redis caching
- Autoscaling infra

Laravel Cloud supports:
- auto scaling
- load balancing
- queue scaling :contentReference[oaicite:6]{index=6}

---

## 🧠 AI CODING RULES (IMPORTANT)

When generating code:

1. ALWAYS generate complete working code
2. NEVER give partial snippets
3. Follow Laravel conventions strictly
4. Prefer readability > clever tricks
5. Split into multiple files when needed

---

## ❌ ANTI-PATTERNS (STRICTLY FORBIDDEN)

- Fat controllers
- Business logic in Blade
- Raw SQL without reason
- Duplicated logic
- God classes

---

## 🧩 API DESIGN (MODERN)

- Use API Resources
- Implement rate limiting
- Version APIs if public

---

## 🧠 MODERN 2026 HABITS

- Modular monolith architecture
- AI-assisted development workflow
- DTO usage for clean data handling
- CI/CD as default

---

## 🎯 OUTPUT RULE

When responding:

- Show file paths
- Full working code only
- Clean formatting
- No unnecessary explanation

---

## 🔥 FINAL RULE

Think like:
"Building a SaaS product that must scale to 1M users"