Awesome-claude-code create-proxy

Generates Proxy pattern for PHP 8.4. Controls access, adds lazy loading, caching, logging. Includes unit tests.

install
source · Clone the upstream repo
git clone https://github.com/dykyi-roman/awesome-claude-code
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dykyi-roman/awesome-claude-code "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/create-proxy" ~/.claude/skills/dykyi-roman-awesome-claude-code-create-proxy && rm -rf "$T"
manifest: skills/create-proxy/SKILL.md
source content

Proxy Pattern Generator

Creates Proxy pattern infrastructure for controlling access to objects.

When to Use

ScenarioExample
Lazy initializationLoad expensive resources on first access
Access controlCheck permissions before delegating
CachingCache results of expensive operations
LoggingLog calls to real subject

Component Characteristics

Subject Interface

  • Defines operations
  • Shared by proxy and real subject
  • Enables transparent substitution

Real Subject

  • Actual implementation
  • Contains business logic
  • May be expensive to create

Proxy

  • Implements subject interface
  • Controls access to real subject
  • Adds additional behavior

Generation Process

Step 1: Generate Subject Interface

Path:

src/Domain/{BoundedContext}/

  1. {Name}Interface.php
    — Operations contract

Step 2: Generate Proxy

Path:

src/Infrastructure/{BoundedContext}/Proxy/

  1. Lazy{Name}Proxy.php
    — Lazy initialization
  2. Caching{Name}Proxy.php
    — Result caching
  3. AccessControl{Name}Proxy.php
    — Permission checks
  4. Logging{Name}Proxy.php
    — Call logging

Step 3: Generate Tests

  1. {ProxyName}Test.php
    — Proxy behavior verification

File Placement

ComponentPath
Subject Interface
src/Domain/{BoundedContext}/
Real Subject
src/Domain/
or
src/Infrastructure/
Proxy
src/Infrastructure/{BoundedContext}/Proxy/
Unit Tests
tests/Unit/Infrastructure/{BoundedContext}/Proxy/

Naming Conventions

ComponentPatternExample
Subject Interface
{Name}Interface
RepositoryInterface
Real Subject
{Name}
UserRepository
Proxy
{Type}{Name}Proxy
LazyUserRepositoryProxy
Test
{ClassName}Test
LazyUserRepositoryProxyTest

Quick Template Reference

Proxy

final class {Type}{Name}Proxy implements {Name}Interface
{
    private ?{Name}Interface $realSubject = null;

    public function __construct(
        private \Closure $factory
    ) {}

    public function {operation}({params}): {returnType}
    {
        {beforeBehavior}

        $result = $this->getRealSubject()->{operation}({args});

        {afterBehavior}

        return $result;
    }

    private function getRealSubject(): {Name}Interface
    {
        if ($this->realSubject === null) {
            $this->realSubject = ($this->factory)();
        }

        return $this->realSubject;
    }
}

Usage Example

// Lazy loading proxy
$repository = new LazyUserRepositoryProxy(
    fn() => new UserRepository($connection)
);

// Real subject created only on first call
$user = $repository->findById($id);

Common Proxies

ProxyPurpose
LazyLoadingProxyDefer expensive object creation
CachingProxyCache method results
AccessControlProxyCheck permissions before execution
LoggingProxyLog all method calls
MetricsProxyCollect performance metrics
RetryProxyRetry failed operations

Anti-patterns to Avoid

Anti-patternProblemSolution
Proxy != Real SubjectBehavior differsProxy must be transparent
Heavy ProxyToo much logicKeep proxies focused
Missing InterfaceCan't substitute proxyUse shared interface
Leaky StateProxy state affects behaviorKeep proxies stateless when possible
Multiple ResponsibilitiesProxy does many thingsOne proxy, one concern

References

For complete PHP templates and examples, see:

  • references/templates.md
    — Lazy loading, caching, access control proxy templates
  • references/examples.md
    — Repository, service proxies with unit tests