Modern PHP programming patterns
- version
- 1.0.0
- GitHub stars
- 26
Add marketplace
/plugin marketplace add miles990/claude-software-skillsRun it inside Claude Code once, then install the plugin below.
Install
/plugin install php@claude-software-skillsRun it inside Claude Code after adding the marketplace.
Files
Discovered from sourcePHP
Overview
Modern PHP (7.4+/8.x) patterns including typed properties, attributes, and modern OOP features.
Modern PHP Features
Type System
<?php
declare(strict_types=1);
// Typed properties (PHP 7.4+)
class User
{
public string $id;
public string $email;
public ?string $name = null;
public bool $active = true;
public array $roles = [];
public DateTimeImmutable $createdAt;
// Constructor promotion (PHP 8.0+)
public function __construct(
public readonly string $email,
public readonly string $name,
private string $password
) {
$this->id = uniqid();
$this->createdAt = new DateTimeImmutable();
}
}
// Union types (PHP 8.0+)
function process(string|int $value): string|int
{
return is_string($value) ? strtoupper($value) : $value * 2;
}
// Intersection types (PHP 8.1+)
function processIterable(Countable&Iterator $items): int
{
return count($items);
}
// Return types
function findUser(string $id): ?User
{
return $this->repository->find($id);
}
function getUsers(): array
{
return $this->repository->findAll();
}
// Never return type (PHP 8.1+)
function fail(string $message): never
{
throw new RuntimeException($message);
}
// Nullable types
function setName(?string $name): void
{
$this->name = $name;
}
Attributes (PHP 8.0+)
<?php
use Attribute;
// Define attribute
#[Attribute(Attribute::TARGET_PROPERTY)]
class Column
{
public function __construct(
public string $name,
public string $type = 'string',
public bool $nullable = false
) {}
}
#[Attribute(Attribute::TARGET_METHOD)]
class Route
{
public function __construct(
public string $path,
public string $method = 'GET'
) {}
}
#[Attribute(Attribute::TARGET_CLASS)]
class Entity
{
public function __construct(
public string $table
) {}
}
// Using attributes
#[Entity(table: 'users')]
class User
{
#[Column(name: 'id', type: 'uuid')]
public string $id;
#[Column(name: 'email', type: 'string')]
public string $email;
#[Column(name: 'name', nullable: true)]
public ?string $name;
}
class UserController
{
#[Route(path: '/users', method: 'GET')]
public function index(): array
{
return $this->userService->getAll();
}
#[Route(path: '/users/{id}', method: 'GET')]
public function show(string $id): User
{
return $this->userService->find($id);
}
}
// Reading attributes
$reflection = new ReflectionClass(User::class);
$attributes = $reflection->getAttributes(Entity::class);
foreach ($attributes as $attribute) {
$instance = $attribute->newInstance();
echo $instance->table; // 'users'
}
Enums (PHP 8.1+)
<?php
// Basic enum
enum Status
{
case Pending;
case Active;
case Inactive;
public function label(): string
{
return match ($this) {
self::Pending => 'Pending Review',
self::Active => 'Active',
self::Inactive => 'Inactive',
};
}
}
// Backed enum (with values)
enum Role: string
{
case Admin = 'admin';
case Moderator = 'moderator';
case User = 'user';
public function permissions(): array
{
return match ($this) {
self::Admin => ['read', 'write', 'delete', 'admin'],
self::Moderator => ['read', 'write', 'delete'],
self::User => ['read', 'write'],
};
}
public static function fromString(string $value): self
{
return self::from($value);
}
public static function tryFromString(string $value): ?self
{
return self::tryFrom($value);
}
}
// Usage
$status = Status::Active;
echo $status->label(); // "Active"
$role = Role::Admin;
echo $role->value; // "admin"
$userRole = Role::from('user');
$permissions = $userRole->permissions();
Object-Oriented Patterns
Traits
<?php
// Trait definition
trait Timestampable
{
protected ?DateTimeImmutable $createdAt = null;
protected ?DateTimeImmutable $updatedAt = null;
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
public function touch(): void
{
$now = new DateTimeImmutable();
$this->createdAt ??= $now;
$this->updatedAt = $now;
}
}
trait SoftDeletable
{
protected ?DateTimeImmutable $deletedAt = null;
public function delete(): void
{
$this->deletedAt = new DateTimeImmutable();
}
public function restore(): void
{
$this->deletedAt = null;
}
public function isDeleted(): bool
{
return $this->deletedAt !== null;
}
}
// Using traits
class Document
{
use Timestampable;
use SoftDeletable;
public function __construct(
public string $title,
public string $content
) {
$this->touch();
}
}
// Trait conflict resolution
trait A
{
public function hello(): string
{
return 'Hello from A';
}
}
trait B
{
public function hello(): string
{
return 'Hello from B';
}
}
class MyClass
{
use A, B {
A::hello insteadof B;
B::hello as helloFromB;
}
}
Interfaces and Abstract Classes
<?php
// Interface
interface Repository
{
public function find(string $id): ?object;
public function findAll(): array;
public function save(object $entity): void;
public function delete(string $id): void;
}
// Generic-style interface
interface Collection
{
public function add(mixed $item): void;
public function remove(mixed $item): bool;
public function contains(mixed $item): bool;
public function count(): int;
public function toArray(): array;
}
// Abstract class
abstract class BaseRepository implements Repository
{
public function __construct(
protected PDO $pdo,
protected string $table
) {}
abstract protected function hydrate(array $row): object;
public function find(string $id): ?object
{
$stmt = $this->pdo->prepare(
"SELECT * FROM {$this->table} WHERE id = :id"
);
$stmt->execute(['id' => $id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ? $this->hydrate($row) : null;
}
public function findAll(): array
{
$stmt = $this->pdo->query("SELECT * FROM {$this->table}");
return array_map(
fn(array $row) => $this->hydrate($row),
$stmt->fetchAll(PDO::FETCH_ASSOC)
);
}
}
// Concrete implementation
class UserRepository extends BaseRepository
{
public function __construct(PDO $pdo)
{
parent::__construct($pdo, 'users');
}
protected function hydrate(array $row): User
{
return new User(
id: $row['id'],
email: $row['email'],
name: $row['name']
);
}
public function findByEmail(string $email): ?User
{
// Custom method
}
}
Error Handling
<?php
// Custom exceptions
class AppException extends Exception
{
public function __construct(
string $message,
public readonly string $code,
public readonly array $context = [],
?Throwable $previous = null
) {
parent::__construct($message, 0, $previous);
}
}
class ValidationException extends AppException
{
public function __construct(
public readonly array $errors,
?Throwable $previous = null
) {
parent::__construct(
'Validation failed',
'VALIDATION_ERROR',
['errors' => $errors],
$previous
);
}
}
class NotFoundException extends AppException
{
public function __construct(
string $resource,
string $id,
?Throwable $previous = null
) {
parent::__construct(
"{$resource} not found: {$id}",
'NOT_FOUND',
['resource' => $resource, 'id' => $id],
$previous
);
}
}
// Result pattern
readonly class Result
{
private function __construct(
public mixed $value,
public ?string $error,
public bool $success
) {}
public static function success(mixed $value): self
{
return new self($value, null, true);
}
public static function failure(string $error): self
{
return new self(null, $error, false);
}
public function map(callable $fn): self
{
if (!$this->success) {
return $this;
}
return self::success($fn($this->value));
}
public function flatMap(callable $fn): self
{
if (!$this->success) {
return $this;
}
return $fn($this->value);
}
}
// Usage
function createUser(array $data): Result
{
if (empty($data['email'])) {
return Result::failure('Email is required');
}
try {
$user = new User($data['email'], $data['name'] ?? '');
$this->repository->save($user);
return Result::success($user);
} catch (Exception $e) {
return Result::failure($e->getMessage());
}
}
Collections and Arrays
<?php
// Array functions
$users = [
['name' => 'Alice', 'age' => 30],
['name' => 'Bob', 'age' => 25],
['name' => 'Charlie', 'age' => 35],
];
// Filter
$adults = array_filter($users, fn($u) => $u['age'] >= 30);
// Map
$names = array_map(fn($u) => $u['name'], $users);
// Reduce
$totalAge = array_reduce($users, fn($sum, $u) => $sum + $u['age'], 0);
// Find
$bob = array_filter($users, fn($u) => $u['name'] === 'Bob');
$bob = current($bob); // Get first match
// Sort
usort($users, fn($a, $b) => $a['age'] <=> $b['age']);
// Group by (custom)
function groupBy(array $items, string $key): array
{
return array_reduce($items, function ($groups, $item) use ($key) {
$groups[$item[$key]][] = $item;
return $groups;
}, []);
}
// Collection class
class Collection implements Countable, IteratorAggregate
{
public function __construct(private array $items = []) {}
public static function from(array $items): self
{
return new self($items);
}
public function map(callable $fn): self
{
return new self(array_map($fn, $this->items));
}
public function filter(callable $fn): self
{
return new self(array_filter($this->items, $fn));
}
public function reduce(callable $fn, mixed $initial = null): mixed
{
return array_reduce($this->items, $fn, $initial);
}
public function first(): mixed
{
return $this->items[array_key_first($this->items)] ?? null;
}
public function count(): int
{
return count($this->items);
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->items);
}
public function toArray(): array
{
return $this->items;
}
}
// Usage
$result = Collection::from($users)
->filter(fn($u) => $u['age'] >= 30)
->map(fn($u) => $u['name'])
->toArray();
Dependency Injection
<?php
// Interface definition
interface LoggerInterface
{
public function info(string $message, array $context = []): void;
public function error(string $message, array $context = []): void;
}
interface UserRepositoryInterface
{
public function find(string $id): ?User;
public function save(User $user): void;
}
// Service with constructor injection
class UserService
{
public function __construct(
private readonly UserRepositoryInterface $repository,
private readonly LoggerInterface $logger,
private readonly EventDispatcher $events
) {}
public function createUser(string $email, string $name): User
{
$this->logger->info('Creating user', ['email' => $email]);
$user = new User($email, $name);
$this->repository->save($user);
$this->events->dispatch(new UserCreated($user));
return $user;
}
}
// Simple container
class Container
{
private array $bindings = [];
private array $instances = [];
public function bind(string $abstract, callable $concrete): void
{
$this->bindings[$abstract] = $concrete;
}
public function singleton(string $abstract, callable $concrete): void
{
$this->bindings[$abstract] = function ($c) use ($abstract, $concrete) {
if (!isset($this->instances[$abstract])) {
$this->instances[$abstract] = $concrete($c);
}
return $this->instances[$abstract];
};
}
public function get(string $abstract): mixed
{
if (isset($this->bindings[$abstract])) {
return $this->bindings[$abstract]($this);
}
return $this->resolve($abstract);
}
private function resolve(string $class): object
{
$reflection = new ReflectionClass($class);
$constructor = $reflection->getConstructor();
if (!$constructor) {
return new $class();
}
$params = array_map(
fn(ReflectionParameter $p) => $this->get($p->getType()->getName()),
$constructor->getParameters()
);
return $reflection->newInstanceArgs($params);
}
}
Related Skills
- [[backend]] - Laravel, Symfony
- [[database]] - Doctrine, Eloquent
- [[testing]] - PHPUnit, Pest
From the miles990/claude-software-skills README
Claude Software Skills
55 modular software development skills for Claude Code - from architecture to deployment
┌─────────────────────────────────────────────────────────────────┐
│ Claude Software Skills │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Software │ │ Software │ │ Development │ │
│ │ Design │ │ Engineering │ │ Stacks │ │
│ │ 6 │ │ 8 │ │ 8 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Tools & │ │ Domain │ │ Programming │ │
│ │ Integrations │ │ Applications │ │ Languages │ │
│ │ 9 │ │ 12 │ │ 12 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ AI 自動識別任務 → 載入對應領域知識 │
└─────────────────────────────────────────────────────────────────┘
Features
- MCP Compatible - Works with Claude Code, Cursor, and other MCP clients
- Semantic Search - Claude automatically finds relevant skills for your task
- Cross-Domain Integration - Skills work together seamlessly
- Best Practices Built-In - Each skill includes patterns and anti-patterns
- Modular Architecture - Use only what you need
- Sharp Edges - Proactive warnings about common pitfalls with detection patterns
- Validations - Executable code quality rules with regex/ast patterns
- Collaboration - Skills declare relationships for smart delegation and context passing
Installation
Plugin Marketplace (Recommended)
# 1. Add marketplace (GitHub format: owner/repo)
/plugin marketplace add miles990/claude-software-skills
# 2. Open plugin management interface, view available plugins in Discover tab
/plugin
# 3. Install specific skills (choose what you need)
/plugin install frontend@claude-software-skills
/plugin install backend@claude-software-skills
/plugin install api-design@claude-software-skills
# Or mention skill name in conversation, Claude will auto-load
Supported GitHub formats:
# Short format (recommended)
/plugin marketplace add miles990/claude-software-skills
# HTTPS URL
/plugin marketplace add https://github.com/miles990/claude-software-skills.git
# Specify branch or tag
/plugin marketplace add miles990/claude-software-skills#main
Plugin commands:
| Command | Description |
|---|---|
/plugin | Open interactive plugin management interface |
/plugin install <name>@<marketplace> | Install specific plugin |
/plugin disable <name>@<marketplace> | Temporarily disable plugin |
/plugin uninstall <name>@<marketplace> | Completely remove plugin |
Available Skills
Software Design (6 skills)
| Skill | Description |
|---|---|
architecture-patterns | Software architecture patterns and best practices |
design-patterns | Classic and modern software design patterns |
api-design | RESTful, GraphQL, gRPC, and API best practices |
system-design | Scalability, availability, and distributed systems design |
data-design | Data modeling, schema design, and data architecture |
ux-principles | User experience design principles for developers |
Software Engineering (8 skills)
| Skill | Description |
|---|---|
code-quality | Clean code principles, SOLID, and code review practices |
testing-strategies | Unit, integration, E2E testing and TDD practices |
devops-cicd | CI/CD pipelines, infrastructure as code, and deployment |
performance-optimization | Profiling, optimization techniques, and best practices |
security-practices | OWASP Top 10, authentication, and secure coding |
reliability-engineering | SRE principles, observability, and incident management |
documentation | Technical writing, API docs, and documentation best practices |
internationalization | i18n/l10n architecture design and multi-language support |
Development Stacks (8 skills)
| Skill | Description |
|---|---|
frontend | Modern frontend with React, Vue, and web technologies |
backend | Backend with Node.js, Express, NestJS, and server patterns |
mobile | Mobile with React Native, Flutter, and native patterns |
database | Database design, SQL, NoSQL, and data management |
cloud-platforms | AWS, GCP, Azure services and cloud-native development |
ai-ml-integration | AI/ML APIs, LLM integration, and intelligent apps |
realtime-systems | WebSocket, real-time communication, event-driven |
edge-iot | Edge computing, IoT protocols, and embedded systems |
Tools & Integrations (9 skills)
| Skill | Description |
|---|---|
git-workflows | Git version control, branching, and collaboration |
project-management | Agile, Scrum, Kanban, and issue tracking |
development-environment | IDE setup, dev containers, and local development |
monitoring-logging | Application monitoring, logging, and alerting |
api-tools | API testing, documentation, and development tools |
automation-scripts | Build automation, task runners, and scripting |
auto-dev-setup | Auto-Dev workflow for Human-in-the-Loop automation |
claude-code-plugin | Claude Code Plugin development and marketplace management |
claude-code-sdk | Claude Code SDK for AI-powered applications |
Domain Applications (12 skills)
| Skill | Description |
|---|---|
application-patterns | Common application development patterns |
e-commerce | E-commerce platforms, payments, shopping cart |
saas-platforms | SaaS architecture, multi-tenancy, subscriptions |
content-platforms | CMS, blogging platforms, content management |
communication-systems | Email, notifications, messaging systems |
developer-tools | CLI tools, SDKs, developer experience |
game-development | Game development patterns and architectures |
flame | Flame Engine 2D game development for Flutter |
flame-core | Flame Engine core - components, input, collision |
flame-systems | Flame Engine 14 game systems |
flame-templates | Game templates - RPG, Platformer, Roguelike |
desktop-apps | Desktop apps with Electron and Tauri |
Programming Languages (12 skills)
| Skill | Description |
|---|---|
javascript-typescript | Modern JavaScript and TypeScript patterns |
python | Python programming patterns and best practices |
go | Go programming patterns and idioms |
rust | Rust patterns and ownership concepts |
java-kotlin | Java and Kotlin programming patterns |
csharp-dotnet | C# and .NET development patterns |
cpp | Modern C++ programming patterns and idioms |
ruby | Ruby programming patterns and idioms |
php | Modern PHP programming patterns |
swift | Swift patterns for iOS and macOS |
shell-bash | Shell scripting and Bash programming |
sql | SQL patterns for database querying and design |
Other Installation Methods
Clone to Skills Directory
# Clone to your skills directory
git clone https://github.com/miles990/claude-software-skills.git ~/.claude/skills/software-skills
Claude will automatically discover and use the skills when relevant to your tasks.
With MCP Server
This repository is compatible with claude-skills-mcp:
# Install the MCP server
pip install claude-skills-mcp
# Add this repository as a skill source
# The server will load skills from ~/.claude/skills/
Cursor IDE
Add to your Cursor MCP settings:
{
"mcpServers": {
"software-skills": {
"command": "npx",
"args": ["-y", "claude-skills-mcp"],
"env": {
"SKILLS_PATH": "/path/to/claude-software-skills"
}
}
}
}
Manual Reference
Simply clone and reference the SKILL.md files in your prompts:
git clone https://github.com/miles990/claude-software-skills.git
Auto-Dev: Automated Development Workflow
One-click setup for GitHub Actions automated development workflow, let Claude help you complete development tasks.
Quick Setup
Using API Key:
curl -fsSL https://raw.githubusercontent.com/miles990/claude-software-skills/main/scripts/setup-auto-dev-apikey.sh | bash
Using Claude Max (OAuth):
curl -fsSL https://raw.githubusercontent.com/miles990/claude-software-skills/main/scripts/setup-auto-dev-max.sh | bash
Post-Installation Setup
| Version | Setup Method |
|---|---|
| API Key | Get Key from console.anthropic.com, set in GitHub Secrets ANTHROPIC_API_KEY |
| Claude Max | Run claude /install-github-app for auto OAuth Token setup |
Usage
- Issue Trigger: Create Issue → Add
auto-devlabel - Comment Trigger: Comment
@claude [instruction]on any Issue/PR
Detailed docs: AUTO-DEV.md
Usage Examples
User: Help me design a microservices architecture for an e-commerce platform
Claude: [Automatically uses architecture-patterns + e-commerce + api-design skills]
User: Review this Python code for performance issues
Claude: [Automatically uses python + performance-optimization + code-quality skills]
User: Set up CI/CD for a React + Node.js monorepo
Claude: [Automatically uses devops-cicd + frontend + backend + git-workflows skills]
Directory Structure
claude-software-skills/
├── .claude-plugin/ # Plugin configuration
│ └── marketplace.json # Lists all 55 skills as individual plugins
├── .github/
│ └── workflows/ # CI/CD automation
├── software-design/ # Architecture & design skills
├── software-engineering/ # Development practices
├── development-stacks/ # Tech stack skills
├── tools-integrations/ # Developer tools
├── domain-applications/ # Domain-specific patterns
├── programming-languages/ # Language-specific skills
├── docs/
│ ├── SKILL-TEMPLATE.md # Template for new skills
│ └── software-skills.md
├── CONTRIBUTING.md
├── LICENSE
└── README.md
How It Works
Each skill module contains a SKILL.md file with:
- Metadata - Name, description, tags for semantic search
- Key Concepts - Core knowledge and terminology
- Best Practices - Recommended approaches with examples
- Common Pitfalls - What to avoid and why
- Patterns & Anti-patterns - Do's and don'ts with code
- Tools & Resources - Recommended tools and references
- Decision Guide - When to use this skill
When you describe a task, Claude:
- Searches for relevant skills using semantic matching
- Loads the appropriate SKILL.md files
- Applies the knowledge to your specific context
- Follows best practices while avoiding common pitfalls
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Adding a New Skill
- Create a directory under the appropriate category
- Add a
SKILL.mdfollowing our template - Include practical examples and best practices
- Submit a pull request
License
MIT License - See LICENSE for details.
Related Projects
- claude-domain-skills - Non-technical domain skills
- claude-skills-mcp - MCP server for skill discovery
Built for developers, by developers, with Claude
Details
- Marketplace
- miles990/claude-software-skills
- Source
- programming-languages/php
- Category
- Community
- Listed since
- Apr 6, 2026
More from miles990/claude-software-skills
All 56- project-managementv1.0.0
- pythonv1.0.0
- realtime-systemsv1.0.0
- reliability-engineeringv1.0.0
- rubyv1.0.0
- rustv1.0.0
- saas-platformsv1.0.0
- security-practicesv1.0.0
- shell-bashv1.0.0
- sqlv1.0.0
- swiftv1.0.0
- system-designv1.0.0
- testing-strategiesv1.0.0
- ux-principlesv1.0.0
- ai-ml-integrationv1.0.0
- analyze-repov1.0.0
- api-designv1.0.0
- api-toolsv1.0.0
- application-patternsv1.0.0
- architecture-patternsv1.0.0
- auto-dev-setupv1.0.0
- automation-scriptsv1.0.0
- backendv1.0.0
- claude-code-pluginv1.0.0
Similar to php
pythonmiles990/claude-software-skills26 starsPython programming patterns and best practices
rubymiles990/claude-software-skills26 starsRuby programming patterns and idioms
developer-kit-phpgiuseppe-trisciuoglio/developer-kit372 starsPHP and WordPress development capabilities
jutsu-phpTheBushidoCollective/han201 starsAdvanced PHP programming skills for modern PHP and security patterns
shell-scriptingwshobson/agents42.8K starsProduction-grade Bash scripting with defensive programming, POSIX compliance, and comprehensive testing
modern-web-guidanceanthropics/claude-plugins-official47.9K starsKeep your coding agent up to date with the latest web best practices
