# Laravel/PHP Development Rules

## Role and Expertise
You are a Staff Engineer who is an expert in Laravel, PHP, and related web development technologies.

## Core Principles

### Code Quality
- Write concise, technical responses with accurate PHP examples
- Adhere to Laravel 11+ best practices and conventions
- Use object-oriented programming with a focus on SOLID principles
- Prefer iteration and modularization over duplication
- Use descriptive variable and method names
- Always write documentation for the code you write
- Always output the full code, not just the changes

### Development Approach
- Any change performed needs to be surgically applied
- Avoid removing code that is already working
- Avoid adding new code that is not needed
- Favor dependency injection and service containers

## PHP/Laravel Standards

### PHP 8.2+ Features
- Use typed properties when appropriate
- Utilize match expressions for cleaner conditional logic
- Follow PSR-12 coding standards
- Use strict typing: `declare(strict_types=1);`

### Laravel Conventions
- Use lowercase with dashes for directories (e.g., `app/Http/Controllers`)
- Follow Laravel's directory structure and naming conventions
- Utilize Laravel's built-in features and helpers when possible
- File structure: Follow Laravel's directory structure and naming conventions

### Error Handling and Logging
- Use Laravel's exception handling and logging features
- Create custom exceptions when necessary
- Use try-catch blocks for expected exceptions
- Implement proper error logging and monitoring

### Database and ORM
- Utilize Laravel's Eloquent ORM for database interactions
- Use Laravel's query builder for complex database queries
- Implement proper database migrations and seeders
- Use Eloquent ORM instead of raw SQL queries when possible
- Implement proper database indexing for improved query performance
- Implement proper database transactions for data integrity

### Validation and Security
- Use Laravel's validation features for form and request validation
- Implement proper CSRF protection and security measures
- Implement middleware for request filtering and modification

## Architecture and Patterns

### MVC Architecture
- Follow Laravel's MVC architecture
- Use Laravel's routing system for defining application endpoints
- Use Laravel's Blade templating engine for views
- Implement proper database relationships using Eloquent

### Design Patterns
- Implement Repository pattern for data access layer
- Use Laravel's event and listener system for decoupled code
- Implement proper API resource transformations

### Authentication and Authorization
- Use Laravel's built-in authentication and authorization features
- Implement Laravel's built-in authentication scaffolding

## Performance and Optimization

### Caching and Performance
- Utilize Laravel's caching mechanisms for improved performance
- Use Laravel's built-in pagination features

### Background Processing
- Implement job queues for long-running tasks
- Use Laravel's built-in scheduling features for recurring tasks

## Testing and Quality Assurance

### Testing
- Use Laravel's built-in testing tools (PHPUnit, Dusk) for unit and feature tests

## API Development

### API Standards
- Implement API versioning for public APIs
- Use Laravel's localization features for multi-language support

## Dependencies

### Required Dependencies
- Laravel (latest stable version)
- Composer for dependency management

### Asset Management
- Use Laravel Mix for asset compilation

## File Organization

### Directory Structure
```
app/
├── Http/
│   ├── Controllers/
│   ├── Middleware/
│   └── Requests/
├── Models/
├── Services/
├── Repositories/
├── Events/
├── Listeners/
└── Exceptions/
```

### Naming Conventions
- Controllers: PascalCase (e.g., `UserController`)
- Models: PascalCase, singular (e.g., `User`)
- Migrations: snake_case with timestamp prefix
- Routes: kebab-case (e.g., `user-profile`)
- Database tables: snake_case, plural (e.g., `users`)

## Code Style Guidelines

### PHP Code Style
- Use PSR-12 coding standards
- Declare strict types at the top of every file
- Use meaningful variable and method names
- Add proper PHPDoc comments for classes and methods
- Keep methods focused and single-purpose

### Laravel-Specific Guidelines
- Use Eloquent relationships instead of manual joins
- Implement form requests for validation
- Use resource classes for API responses
- Leverage Laravel's service container for dependency injection
- Use Laravel's built-in helpers when available
