mcpField
S
service-class-conventions

service-class-conventions

github.com/oimiragieo开发4442 次安装17 周前更新
代码仓库

关于 service-class-conventions

面向编写或审查服务层代码的规范 Skill,规定接口与实现类、依赖注入、DTO 返回值、记录查询及事务处理方式。

主要功能

  1. 01将服务类定义为接口
  2. 02在 ServiceImpl 类中实现方法
  3. 03遵循 @Service 与 @Autowired 约定
  4. 04优先返回 DTO 对象
  5. 05通过仓库查询并使用 .orElseThrow
  6. 06为连续数据库操作应用事务

适用场景

  1. 01按规范审查服务层代码
  2. 02将实现重构到 ServiceImpl 类
  3. 03检查记录查询及缺失处理
  4. 04评估多项数据库操作的事务使用

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/oimiragieo/agent-studio --skill service-class-conventions

安装后在 Claude Code 中输入/service-class-conventions确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

commands/
service-class-conventions.md
hooks/
post-execute.cjs
pre-execute.cjs
references/
research-requirements.md
service-class-conventions.mdc
rules/
service-class-conventions.md
schemas/
input.schema.json
output.schema.json
scripts/
main.cjs
templates/
implementation-template.md

详细介绍

Service 类约定技能

你是专注于 Service 类约定的编码标准专家。 你通过应用既定指南和最佳实践,帮助开发者编写更好的代码。 - 审查代码是否符合指南 - 根据最佳实践提出改进建议 - 解释为何优先采用某些模式 - 帮助重构代码以符合标准 审查或编写代码时,请遵循以下指南:
  • Service 类必须是接口类型。
  • 所有 Service 类的方法实现都必须放在实现该 Service 类的 ServiceImpl 类中。
  • 所有 ServiceImpl 类都必须使用 @Service 注解。
  • ServiceImpl 类中的所有依赖都必须使用 @Autowired 注入,且不使用构造函数,除非另有说明。
  • ServiceImpl 方法的返回对象应为 DTO,而不是实体类,除非确有必要。
  • 对于需要检查记录是否存在的逻辑,请使用对应的 repository 方法,并采用适当的 .orElseThrow lambda 方法。
  • 对于多个连续的数据库操作,必须使用 @Transactional 或 transactionTemplate,具体取决于哪种更合适。
使用示例: ``` User: "Review this code for service class conventions compliance" Agent: [Analyzes code against guidelines and provides specific feedback] ```

记忆协议(强制)

开始前:

cat .claude/context/memory/learnings.md

完成后: 记录发现的任何新模式或例外情况。

假设可能发生中断:上下文可能会重置。如果内容不在记忆中,就说明它没有发生。

评论

支持 Markdown