AgentSkillsCN

hyperf-components

使用 Hyperf 3.1 官方推荐组件的最佳实践模式。内容覆盖核心架构、微服务、数据访问,以及各类实用工具。

SKILL.md
--- frontmatter
name: hyperf-components
description: Usage patterns for official Hyperf 3.1 recommended components. Covers Core Architecture, Microservices, Data Access, and Utilities.
license: MIT
metadata:
  author: TraeAI
  version: "1.2.0"

Core Architecture

RuleKeywordsDescription
config-injectionconfig, env, injectionInject ConfigInterface or use config() helper
logger-factory-usagelog, logger, monologUse LoggerFactory for structured logging
middleware-structuremiddleware, psr-15Use PSR-15 Middleware interface
event-listener-structureevent, listener, psr-14Decouple logic with Event Listeners
aop-aspect-structureaop, aspect, proxyUse Aspects for cross-cutting concerns
custom-process-structureprocess, daemonUse Custom Processes for background tasks
validation-form-requestvalidation, request, formUse FormRequest for validation encapsulation

HTTP Layer

RuleKeywordsDescription
router-annotationsroute, router, annotationUse Annotations for routing
request-injectionrequest, input, injectionInject RequestInterface instead of globals
exception-handlerexception, error, handlerUse ExceptionHandler for global error handling
api-resource-usageresource, json, transformationUse JsonResource for API responses

Microservices & Network

RuleKeywordsDescription
guzzle-client-factoryguzzle, http client, curlUse ClientFactory for coroutine-safe HTTP requests
rpc-service-definitionrpc, jsonrpc, grpcDefine RPC services with interfaces
websocket-controllerwebsocket, socket.ioUse Annotations for WebSocket events
service-governance-annotationsrate limit, circuit breakerUse Annotations for governance
tracer-usagetracer, opentracing, zipkinUse OpenTracing for distributed tracing
async-queue-usagequeue, async, jobUse Async Queue for background tasks
amqp-usageamqp, rabbitmq, queueUse AMQP for RabbitMQ messaging
kafka-usagekafka, queue, streamUse Kafka for high-throughput messaging
tcp-server-usagetcp, server, socketCreate custom TCP servers
websocket-client-usagewebsocket, client, wsUse WebSocket Client for real-time comms
config-center-usageconfig center, nacos, consulUse Config Center for dynamic configuration
metric-usagemetric, prometheus, monitorUse Prometheus for monitoring metrics
retry-usageretry, policy, resilienceUse Retry annotation for fault tolerance
distributed-transaction-usagedtm, saga, tccUse DTM for distributed transactions

Data & Caching

RuleKeywordsDescription
redis-pool-usageredis, pool, connectionUse Redis proxy for connection pooling
model-cache-usagecache, model, ormUse ModelCache for high-performance reads
simple-cache-usagecache, psr-16Use PSR-16 Simple Cache interface
elasticsearch-clientelasticsearch, searchUse ClientBuilderFactory for ES client
model-relationshipsmodel, relation, hasmanyDefine model relationships with return types
model-mutator-usagemodel, mutator, castUse Accessors, Mutators and Casts
db-migration-usagemigration, schema, databaseUse Migrations for schema changes
paginator-usagepagination, paginator, limitUse Paginator for result set paging
scout-usagescout, search, elasticsearchUse Scout for model full-text search

Utilities & System

RuleKeywordsDescription
translation-usagei18n, translation, transUse TranslatorInterface for internationalization
snowflake-id-generatorid, snowflake, uuidUse Snowflake for distributed unique IDs
crontab-usagecron, schedule, taskUse Crontab annotations for scheduling
swagger-annotationsswagger, openapi, docUse Annotations for API documentation
view-render-usageview, render, templateUse RenderInterface for view rendering
command-annotationcommand, console, cliUse Annotations for Console Commands
filesystem-usagefile, storage, flysystemUse FilesystemFactory for file operations
testing-structuretest, phpunit, mockUse Co-PHPUnit and Testing components
constants-usageconstants, error code, enumDefine error codes with AbstractConstants
watcher-configwatcher, hot reload, devUse Watcher for hot reloading in development

Reference