Awesome-claude-code create-adapter

Generates Adapter pattern for PHP 8.4. Converts incompatible interfaces, wraps legacy code and external libraries. 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-adapter" ~/.claude/skills/dykyi-roman-awesome-claude-code-create-adapter && rm -rf "$T"
manifest: skills/create-adapter/SKILL.md
source content

Adapter Pattern Generator

Creates Adapter pattern infrastructure for converting incompatible interfaces into expected ones.

When to Use

ScenarioExample
Legacy code integrationWrap old API with new interface
Third-party library wrappingStripe SDK, AWS SDK adapters
Interface standardizationMultiple payment gateways with unified interface
Backward compatibilitySupport old and new interfaces

Component Characteristics

Target Interface

  • Defines expected operations
  • Client code depends on this
  • Domain layer contract

Adapter

  • Implements target interface
  • Wraps adaptee (existing class)
  • Translates calls between interfaces

Adaptee

  • Existing incompatible class
  • Legacy code or external library
  • Not modified by adapter

Generation Process

Step 1: Generate Target Interface

Path:

src/Domain/{BoundedContext}/

  1. {Name}Interface.php
    — Expected interface contract

Step 2: Generate Adapter

Path:

src/Infrastructure/{BoundedContext}/Adapter/

  1. {Provider}{Name}Adapter.php
    — Converts adaptee to target interface
  2. {Legacy}{Name}Adapter.php
    — Wraps legacy code
  3. {External}{Name}Adapter.php
    — Wraps third-party library

Step 3: Generate Tests

  1. {AdapterName}Test.php
    — Adapter behavior verification

File Placement

ComponentPath
Target Interface
src/Domain/{BoundedContext}/
Adapter
src/Infrastructure/{BoundedContext}/Adapter/
Adaptee (existing)External library or legacy code
Unit Tests
tests/Unit/Infrastructure/{BoundedContext}/Adapter/

Naming Conventions

ComponentPatternExample
Target Interface
{Name}Interface
PaymentGatewayInterface
Adapter
{Provider}{Name}Adapter
StripePaymentGatewayAdapter
Test
{ClassName}Test
StripePaymentGatewayAdapterTest

Quick Template Reference

Target Interface

interface {Name}Interface
{
    public function {operation}({params}): {returnType};
}

Adapter

final readonly class {Provider}{Name}Adapter implements {Name}Interface
{
    public function __construct(
        private {Adaptee} $adaptee
    ) {}

    public function {operation}({params}): {returnType}
    {
        // Translate params to adaptee format
        $adapteeResult = $this->adaptee->{adapteeMethod}({adapteeParams});

        // Convert result to target format
        return {convertedResult};
    }
}

Usage Example

// Stripe SDK is the adaptee
$stripeClient = new \Stripe\StripeClient($apiKey);

// Adapter makes it compatible with our interface
$paymentGateway = new StripePaymentGatewayAdapter($stripeClient);

// Use through our domain interface
$result = $paymentGateway->charge($amount, $token);

Common Adapters

AdapterPurpose
PaymentGatewayAdapterWrap Stripe, PayPal, Square APIs
StorageAdapterWrap AWS S3, Google Cloud Storage
MessengerAdapterWrap Slack, Discord, Telegram APIs
EmailAdapterWrap SendGrid, Mailgun, AWS SES
CacheAdapterWrap Redis, Memcached, APCu
LoggerAdapterWrap Monolog, Syslog, custom loggers

Anti-patterns to Avoid

Anti-patternProblemSolution
Leaky AdapterExposing adaptee detailsReturn only target interface types
Multiple ResponsibilitiesAdapter doing business logicKeep adapters focused on translation
Tight CouplingAdapter depends on concrete adapteeAccept interface when possible
Heavy TranslationComplex conversions in adapterExtract translator services
Missing Error HandlingAdaptee exceptions leakCatch and convert to domain exceptions

References

For complete PHP templates and examples, see:

  • references/templates.md
    — Target Interface, Adapter templates for payment, storage, messaging
  • references/examples.md
    — Stripe, PayPal, AWS S3, legacy user adapters with unit tests