adr-knowledge

Action-Domain-Responder(ADR)模式知识库,提供针对 Web 的 MVC 替代方案的审计模式、反模式以及 PHP 特定的指南。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "adr-knowledge":https://skillpi.com/zh/skills/deepskill-42b43aca415716325913916512deb5d85315eea5c5b79f3c5c2bfa754fcdd2e4。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

Action-Domain-Responder(ADR)模式知识库,提供针对 Web 的 MVC 替代方案的审计模式、反模式以及 PHP 特定的指南。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: adr-knowledge
description: Action-Domain-Responder pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for ADR (web-specific MVC alternative) audits.

ADR Knowledge Base

Quick reference for Action-Domain-Responder pattern and PHP implementation guidelines.

Core Principles

ADR Components

HTTP Request → Action (collects input)
                 ↓
              Domain (executes business logic)
                 ↓
             Responder (builds HTTP Response)
                 ↓
           HTTP Response

Rule: One action = one HTTP endpoint. Responder builds the COMPLETE response.

Component Responsibilities

Component Responsibility Contains
Action Collects input, invokes Domain, passes to Responder Request parsing, DTO creation, UseCase invocation
Domain Business logic (same as DDD Domain/Application) Entities, Value Objects, UseCases, Services
Responder Builds HTTP Response (status, headers, body) Response building, template rendering, content negotiation

ADR vs MVC Comparison

Aspect MVC Controller ADR Action
Granularity Multiple actions Single action per class
Response building Mixed in controller Separate Responder class
HTTP concerns Scattered Isolated in Responder
Testability Lower (many concerns) Higher (single responsibility)
File structure Few large files Many focused files

Quick Checklists

Action Checklist

  • [ ] Single __invoke() method
  • [ ] No new Response() or response building
  • [ ] No business logic (if/switch on domain state)
  • [ ] Only input parsing and domain invocation
  • [ ] Returns Responder result

Responder Checklist

  • [ ] Receives domain result only
  • [ ] Builds complete HTTP Response
  • [ ] Handles content negotiation
  • [ ] Sets status codes based on result
  • [ ] No domain/business logic
  • [ ] No database/repository access

Domain Checklist

  • [ ] Same as DDD Domain/Application layers
  • [ ] No HTTP/Response concerns
  • [ ] Returns domain objects (not HTTP responses)
  • [ ] Pure business logic

Common Violations Quick Reference

Violation Where to Look Severity
new Response() in Action *Action.php Critical
->withStatus() in Action *Action.php Critical
if ($result->isError()) in Action *Action.php Warning
$repository-> in Responder *Responder.php Critical
$service-> in Responder *Responder.php Critical
Multiple public methods in Action *Action.php Warning
Template logic in Action *Action.php Warning

PHP 8.4 ADR Patterns

Action Pattern

<?php

declare(strict_types=1);

namespace Presentation\Api\User\Create;

use Application\User\UseCase\CreateUser\CreateUserUseCase;
use Application\User\UseCase\CreateUser\CreateUserInput;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class CreateUserAction
{
    public function __construct(
        private CreateUserUseCase $useCase,
        private CreateUserResponder $responder,
    ) {
    }

    public function __invoke(ServerRequestInterface $request): ResponseInterface
    {
        $input = $this->parseInput($request);
        $result = $this->useCase->execute($input);

        return $this->responder->respond($result);
    }

    private function parseInput(ServerRequestInterface $request): CreateUserInput
    {
        $body = (array) $request->getParsedBody();

        return new CreateUserInput(
            email: $body['email'] ?? '',
            name: $body['name'] ?? '',
        );
    }
}

Responder Pattern

<?php

declare(strict_types=1);

namespace Presentation\Api\User\Create;

use Application\User\UseCase\CreateUser\CreateUserResult;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;

final readonly class CreateUserResponder
{
    public function __construct(
        private ResponseFactoryInterface $responseFactory,
        private StreamFactoryInterface $streamFactory,
    ) {
    }

    public function respond(CreateUserResult $result): ResponseInterface
    {
        if ($result->isFailure()) {
            return $this->error($result->error());
        }

        return $this->success($result->userId());
    }

    private function success(string $userId): ResponseInterface
    {
        return $this->json(['id' => $userId], 201);
    }

    private function error(string $message): ResponseInterface
    {
        return $this->json(['error' => $message], 400);
    }

    private function json(array $data, int $status): ResponseInterface
    {
        $body = $this->streamFactory->createStream(
            json_encode($data, JSON_THROW_ON_ERROR)
        );

        return $this->responseFactory->createResponse($status)
            ->withHeader('Content-Type', 'application/json')
            ->withBody($body);
    }
}

Detection Patterns

Action Detection

# Find Action classes
Glob: **/*Action.php
Glob: **/Action/**/*.php
Grep: "implements.*ActionInterface|extends.*Action" --glob "**/*.php"

# Detect Action pattern usage
Grep: "public function __invoke.*Request" --glob "**/*Action.php"

Responder Detection

# Find Responder classes
Glob: **/*Responder.php
Glob: **/Responder/**/*.php
Grep: "implements.*ResponderInterface" --glob "**/*.php"

# Detect Responder pattern usage
Grep: "public function respond" --glob "**/*Responder.php"

Violation Detection

# Response building in Action (Critical)
Grep: "new Response|->withStatus|->withHeader|->withBody" --glob "**/*Action.php"

# Business logic in Action (Warning)
Grep: "if \(.*->status|switch \(|->isValid\(\)" --glob "**/*Action.php"

# Domain calls in Responder (Critical)
Grep: "Repository|Service|UseCase" --glob "**/*Responder.php"

# Multiple public methods in Action (Warning)
Grep: "public function [^_]" --glob "**/*Action.php" | wc -l

File Structure

Recommended Structure

src/
├── Presentation/
│   ├── Api/
│   │   └── {Context}/
│   │       └── {Action}/
│   │           ├── {Action}Action.php
│   │           ├── {Action}Responder.php
│   │           └── {Action}Request.php (optional DTO)
│   ├── Web/
│   │   └── {Context}/
│   │       └── {Action}/
│   │           ├── {Action}Action.php
│   │           ├── {Action}Responder.php
│   │           └── templates/ (for HTML)
│   └── Shared/
│       ├── Action/
│       │   └── ActionInterface.php
│       └── Responder/
│           └── ResponderInterface.php
├── Application/
│   └── {Context}/
│       └── UseCase/
│           └── {Action}/
│               ├── {Action}UseCase.php
│               ├── {Action}Input.php
│               └── {Action}Result.php
└── Domain/
    └── ...

Alternative Structure (Feature-Based)

src/
├── User/
│   ├── Presentation/
│   │   ├── CreateUser/
│   │   │   ├── CreateUserAction.php
│   │   │   └── CreateUserResponder.php
│   │   └── GetUser/
│   │       ├── GetUserAction.php
│   │       └── GetUserResponder.php
│   ├── Application/
│   │   └── ...
│   └── Domain/
│       └── ...

Integration with DDD

ADR fits naturally with DDD layering:

ADR DDD Layer Notes
Action Presentation Entry point for HTTP
Responder Presentation Exit point for HTTP
Domain Domain + Application Business logic via UseCases

PSR Integration

ADR works with PSR-7/PSR-15:

PSR Usage
PSR-7 Request/Response interfaces
PSR-15 Middleware for cross-cutting concerns
PSR-17 Response/Stream factories in Responder

Antipatterns

1. Fat Action (Critical)

// BAD: Action doing too much
class CreateUserAction
{
    public function __invoke(Request $request): Response
    {
        $data = $request->getParsedBody();

        // Validation in Action
        if (empty($data['email'])) {
            return new Response(400, [], 'Email required');
        }

        // Business logic in Action
        $user = new User($data['email']);
        $this->repository->save($user);

        // Response building in Action
        return new Response(201, [], json_encode(['id' => $user->id()]));
    }
}

2. Anemic Responder (Warning)

// BAD: Responder not doing its job
class CreateUserResponder
{
    public function respond($data): Response
    {
        return new Response(200, [], json_encode($data));
    }
}

3. Smart Responder (Critical)

// BAD: Responder with business logic
class CreateUserResponder
{
    public function respond(User $user): Response
    {
        // Domain logic in Responder!
        if ($user->isAdmin()) {
            $this->notificationService->notifyAdmins();
        }

        return $this->json(['id' => $user->id()], 201);
    }
}

References

For detailed information, load these reference files:

  • references/action-patterns.md — Action class patterns and best practices
  • references/responder-patterns.md — Responder class patterns
  • references/domain-integration.md — Integration with DDD Domain layer
  • references/mvc-comparison.md — Detailed MVC vs ADR comparison
  • references/antipatterns.md — Common ADR violations with examples

Assets

  • assets/report-template.md — ADR audit report template

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供ADR模式的完整知识体系,包括核心原则、组件职责和最佳实践
  • 包含实用的检测模式和代码示例,帮助开发者识别和避免常见违规
  • 针对PHP 8.4提供了具体的实现模式和文件结构建议
触发精准90/100

亮点

  • description清晰准确地描述了Skill的核心功能:ADR模式知识库
  • 触发词精准,明确指出了提供模式、反模式和PHP特定指南
结构规范85/100

待提升项

  • 缺少When to Use章节 原报告严重程度:轻微

    文档结构完整但缺少明确的When to Use使用场景说明

    改进建议:建议添加When to Use章节,说明在什么情况下应该使用此知识库

亮点

  • 文档结构层次清晰,从核心原则到具体实现都有涵盖
  • 提供了详细的检查清单和常见违规参考,实用性强
  • 代码示例完整,展示了Action和Responder的标准实现模式
执行可靠80/100

待提升项

  • 缺少异常处理说明 原报告严重程度:轻微

    检测模式提供了grep命令,但缺少对执行异常情况的处理建议

    改进建议:建议补充检测命令执行失败时的处理方案或替代方法

亮点

  • 提供了完整的检测模式,包括文件查找和违规检测的grep命令
  • 代码示例使用了PSR标准接口,具有良好的可移植性
  • 文件结构建议合理,支持多种组织方式
证据可验 (前四项均值)85/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。