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.mdsource content
Proxy Pattern Generator
Creates Proxy pattern infrastructure for controlling access to objects.
When to Use
| Scenario | Example |
|---|---|
| Lazy initialization | Load expensive resources on first access |
| Access control | Check permissions before delegating |
| Caching | Cache results of expensive operations |
| Logging | Log 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}/
— Operations contract{Name}Interface.php
Step 2: Generate Proxy
Path:
src/Infrastructure/{BoundedContext}/Proxy/
— Lazy initializationLazy{Name}Proxy.php
— Result cachingCaching{Name}Proxy.php
— Permission checksAccessControl{Name}Proxy.php
— Call loggingLogging{Name}Proxy.php
Step 3: Generate Tests
— Proxy behavior verification{ProxyName}Test.php
File Placement
| Component | Path |
|---|---|
| Subject Interface | |
| Real Subject | or |
| Proxy | |
| Unit Tests | |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Subject Interface | | |
| Real Subject | | |
| Proxy | | |
| Test | | |
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
| Proxy | Purpose |
|---|---|
| LazyLoadingProxy | Defer expensive object creation |
| CachingProxy | Cache method results |
| AccessControlProxy | Check permissions before execution |
| LoggingProxy | Log all method calls |
| MetricsProxy | Collect performance metrics |
| RetryProxy | Retry failed operations |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Proxy != Real Subject | Behavior differs | Proxy must be transparent |
| Heavy Proxy | Too much logic | Keep proxies focused |
| Missing Interface | Can't substitute proxy | Use shared interface |
| Leaky State | Proxy state affects behavior | Keep proxies stateless when possible |
| Multiple Responsibilities | Proxy does many things | One proxy, one concern |
References
For complete PHP templates and examples, see:
— Lazy loading, caching, access control proxy templatesreferences/templates.md
— Repository, service proxies with unit testsreferences/examples.md