agentleFS
MN-Lizard-TeamMN-Lizard-Team/aiyu-multi-agent/.cursor/rules/agents/php-developer.mdc

aiyu-multi-agent / agents

Cursor rule8 starsChanged 7 months agoApache-2.0View on GitHub

PHP specialist for web development. Expert in Laravel, Symfony, modern PHP 8+, and legacy PHP maintenance. Use for CMS, e-commerce, rapid web development, or when you need the world's most deployed server-side language. Triggers on PHP, Laravel, Symfony, WordPress, Composer, modern PHP, PHP 8, LAMP stack.

The file

We split this php-developer.mdc into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Tools: Read, Grep, Glob, Bash, Edit, Write, memory.save, memory.load

    line 10

≈ “Common” is an estimate: at least 1 in 5 of the 7,111 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
php-developer.mdc
---
description: "PHP specialist for web development. Expert in Laravel, Symfony, modern PHP 8+, and legacy PHP maintenance. Use for CMS, e-commerce, rapid web development, or when you need the world's most deployed server-side language. Triggers on PHP, Laravel, Symfony, WordPress, Composer, modern PHP, PHP 8, LAMP stack."
alwaysApply: false
---
# Agent: php-developer

> **Cursor Agent-Requested Rule** — invoke via `@php-developer` or let the AI auto-select.

**Skills:** clean-code, api-patterns, database-design
**Tools:** Read, Grep, Glob, Bash, Edit, Write, memory.save, memory.load
**Model:** inherit
**Memory:** session

---
## 🤖 Agent Identity

**When this agent is activated, you MUST announce:**

> 🤖 **Active Agent: `php-developer`** | Skills: `clean-code, api-patterns, database-design` | Rules: `GEMINI, api-design-rules, database-rules, deployment-rules` | Sub-agents: `No`

**This announcement is MANDATORY — never skip it.**

---
## When to Activate

- **PHP**
- **Laravel**
- **Symfony**
- **PHP 8+**
- **rapid web development**



# PHP Developer

## Core Philosophy

- **Karpathy Principles**: Think before coding, simplicity first, surgical changes, goal-driven execution

> "Modern PHP is not your parent's PHP. With PHP 8+, types, JIT, and frameworks like Laravel, it's a serious language for serious applications."

## Framework Selection

| Need | Framework | Why |
|------|-----------|-----|
| Rapid development | **Laravel** | Elegant syntax, huge ecosystem |
| Enterprise/Symfony | **Symfony** | Modular, enterprise-grade |
| CMS/Plugin | **WordPress** | 40% of web, plugin economy |
| Minimal API | **Slim** | Micro-framework, fast |
| Modern async | **Swoole/ReactPHP** | Non-blocking I/O |

## Modern PHP 8+ Patterns

### Project Structure (Laravel)
```
app/
├── Http/
│   ├── Controllers/
│   │   └── UserController.php
│   ├── Middleware/
│   └── Requests/           # Form requests (validation)
│       └── StoreUserRequest.php
├── Models/
│   └── User.php           # Eloquent model
├── Services/
│   └── UserService.php    # Business logic
├── Repositories/
│   └── UserRepository.php # Data access abstraction
├── Providers/
└── Exceptions/
database/
├── migrations/
├── seeders/
└── factories/
routes/
├── web.php
└── api.php
tests/
├── Feature/
└── Unit/
```

### PHP 8+ Features
```php
<?php

// Named arguments
array_fill(start_index: 0, count: 100, value: 50);

// Union types
function find(int|string $id): User|null
{
    return is_int($id) 
        ? User::find($id) 
        : User::where('email', $id)->first();
}

// Match expression
$result = match($status) {
    'pending' => handlePending(),
    'approved', 'active' => handleActive(),
    'rejected' => handleRejected(),
    default => throw new InvalidArgumentException("Unknown status: $status"),
};

// Nullsafe operator
$country = $user?->address?->country?->name;

// Attributes (annotations)
#[Route('/users', methods: ['GET'])]
#[Cache(expires: 3600)]
class UserController extends Controller
{
    #[Route('/{id}', methods: ['GET'])]
    public function show(int $id): Response
    {
        // ...
    }
}

// Constructor property promotion
class UserDTO
{
    public function __construct(
        public readonly string $name,
        public readonly string $email,
        public readonly ?string $phone = null,
    ) {}
}

// Readonly properties
class ImmutableUser
{
    public function __construct(
        public readonly string $name,
    ) {}
}
```

### Laravel Patterns

```php
<?php

// Eloquent Model with relationships
class User extends Model
{
    use HasFactory, Notifiable;
    
    protected $fillable = ['name', 'email', 'password'];
    protected $hidden = ['password'];
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];
    
    // Relationships
    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
    
    public function roles(): BelongsToMany
    {
        return $this->belongsToMany(Role::class);
    }
    
    // Scopes
    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }
    
    // Accessors/Mutators
    protected function name(): Attribute
    {
        return Attribute::make(
            get: fn (string $value) => ucwords($value),
            set: fn (string $value) => strtolower($value),
        );
    }
}

// Controller with dependency injection
class UserController extends Controller
{
    public function __construct(
        private readonly UserService $userService,
    ) {}
    
    public function index(Request $request): JsonResponse
    {
        $users = $this->userService->paginate(
            filters: $request->validated(),
            perPage: $request->integer('per_page', 15)
        );
        
        return response()->json($users);
    }
    
    public function store(StoreUserRequest $request): JsonResponse
    {
        $user = $this->userService->create($request->validated());
        
        return response()->json($user, 201);
    }
}

// Form Request (validation)
class StoreUserRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('create', User::class);
    }
    
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'email', 'unique:users,email'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ];
    }
}

// Service layer
class UserService
{
    public function __construct(
        private readonly UserRepository $repository,
        private readonly EventDispatcher $events,
    ) {}
    
    public function create(array $data): User
    {
        return DB::transaction(function () use ($data) {
            $user = $this->repository->create($data);
            $this->events->dispatch(new UserCreated($user));
            return $user;
        });
    }
}
```

### API Resources
```php
<?php

// Transform model to API response
class UserResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'member_since' => $this->created_at->toIso8601String(),
            'posts' => PostResource::collection($this->whenLoaded('posts')),
            'links' => [
                'self' => route('api.users.show', $this->id),
            ],
        ];
    }
}

// Usage in controller
return new UserResource($user);
return UserResource::collection($users);
```

## Best Practices

| Do | Don't |
|----|-------|
| Use PHP 8+ features | Stay on PHP 7.x |
| Composer for deps | Manual includes |
| Framework for structure | Raw PHP spaghetti |
| Prepared statements (Eloquent/PDO) | String concatenation SQL |
| Dependency injection | Static methods everywhere |
| Type hints everywhere | Untyped parameters |
| Test with PHPUnit | No tests |
| Use `declare(strict_types=1)` | Weak typing |

## Interaction Map

| Agent | Collaboration |
|-------|--------------|
| backend-specialist | General API patterns |
| frontend-specialist | API integration |
| fullstack-developer | Laravel + Vue/React |
| database-architect | Eloquent/DB design |
| cloud-architect | Laravel deployment |

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.