crud-di

crud-di is a skill for Claude Code, Codex from ArtisanCloud/PowerX. It costs 28 tokens per session (1,655 once invoked), scanned A, original, Apache-2.0.

A set of coding rules for dependency injection in PowerX CRUD services. Dependency injection means supplying a component’s database, logger, cache, or other outside services from the application setup instead of creating them inside request handlers.

In plain words
What is it for?
Use it when implementing or checking dependency setup, constructors, repositories, services, handlers, and startup or shutdown order in a Go codebase.
Why use it?
It prevents business code from directly creating clients or connecting to databases, and keeps HTTP, gRPC, and message-based entry points able to reuse the same service logic.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/artisancloud/powerx/di
Any agent
npx skills add ArtisanCloud/PowerX --skill di
Clone the repo
git clone --depth 1 https://github.com/ArtisanCloud/PowerX

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for crud-di

README.md
[![agentmods](https://agentmods.dev/badge/skills/artisancloud/powerx/di.svg)](https://agentmods.dev/skills/artisancloud/powerx/di)
Your own site
<a href="https://agentmods.dev/skills/artisancloud/powerx/di"><img src="https://agentmods.dev/badge/skills/artisancloud/powerx/di.svg" alt="Measured on agentmods" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,655 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.01655
Opus 5 $0.00014 $0.00827
Sonnet 5 $0.00006 $0.00331
Haiku 4.5 $0.00003 $0.00166

Measured today against content hash 4fd783ef9710, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

crud-di scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.codex/skills/crud/di/SKILL.md · 191 lines

How it starts

The opening of the file, as written. The whole thing — 191 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PowerX CRUD DI

步骤

  1. 打开 本文件内嵌规则
  2. 按规则执行实现/校对。
  3. 完成后按核对清单验收。

核对点

  • 与 PowerX 当前代码结构、路径与命名一致。
  • 仅在传输层/契约层做职责内改动,不跨层越界。

规则(内嵌)

di.yaml

kind: ruleset
name: crud_di
version: 1.0.0
owner: powerx
status: stable

meta:
  intent: >
    统一依赖注入装配:Deps 作为单一入口,Service/Repo/Handler 经构造函数注入;
    禁止在 Handler/Service 中直接 new 外部客户端或直连 DB;支持 HTTP/GRPC/MQ 等多传输共用同一业务服务。
  references:
    - constitution.md
    - dev_crud_http_guides.md

scope:
  codebase:
    deps_file: "internal/app/shared/deps.go"
    service_globs:
      - "internal/service/**/**_service.go"
    repo_globs:
      - "internal/repository/**/**_repo.go"
    handler_globs:
      - "internal/transport/http/**/**_handler.go"
    grpc_server_globs:
      - "internal/transport/grpc/**/**.go"

principles:
  - Deps 为“服务容器”:提供 DB/Logger/Cache/EventBus/KeyRing/Config 等基础依赖。
  - 构造函数注入:NewXxxService(NewXxxRepo(...));禁止全局单例与包级可变状态。
  - 传输解耦:HTTP/GRPC 层仅持有 Service;Service 不感知传输实现。
  - 生命周期统一:Deps 负责启动/关闭顺序(DB→Repo/Service→Transport)。

checks:
  - id: deps.file.exists
    level: error
    when: { file: "internal/app/shared/deps.go" }
    assert:
      - must_define: "type Deps struct"
      - must_define: "func NewDeps() (*Deps, error)"
  - id: service.constructor
    level: error
    when: { glob: "internal/service/**/**_service.go" }
    assert:
      - must_define_like: "func New*Service(*Deps) *"
      - must_not_import: ["database/sql","gorm.io/gorm"]   # Service 通过 deps 间接持有 DB
  - id: repo.constructor
    level: error
    when: { glob: "internal/repository/**/**_repo.go" }
    assert:
      - must_define_like: "func New*Repo(*gorm.DB) *"
  - id: handler.depends_on_service_only
    level: error
    when: { glob: "internal/transport/http/**/**_handler.go" }
    assert:
      - must_define_like: "type *Handler struct { svc *service.* }"
      - must_define_like: "func New*Handler(*service.*) *"
      - must_not_import: ["gorm.io/gorm","database/sql","net/http"]
  - id: grpc.server.uses_service
    level: warn
    when: { glob: "internal/transport/grpc/**/**.go" }
    assert:
      - should_contain: "deps.*Service"   # gRPC 服务实现注入 Service,而非直连 Repo/DB
  - id: deps.no_new_external_in_handlers
    level: error
    when: { glob: "internal/transport/http/**/**_handler.go" }
    assert:
      - must_not_call: ["redis.NewClient(","kafka.NewReader(","http.DefaultClient.Do"]

acceptance:
  checklist:
    - "[ ] internal/app/shared/deps.go 定义 Deps 与 NewDeps"
    - "[ ] Service/Repo/Handler 均提供 New* 构造函数"
    - "[ ] Handler/GRPC 层仅依赖 Service,不直连 Repo/DB/外部客户端"
    - "[ ] Deps 提供 DB/Logger/Cache/EventBus/KeyRing/Config 等公共依赖"
    - "[ ] 无全局可变单例;关闭顺序由 Deps 统一管理"

templates:
  deps_go: |
    // internal/app/shared/deps.go
    package shared

    import (
      "context"
      "gorm.io/gorm"
      "github.com/redis/go-redis/v9"
      "log"
    )

    type Deps struct {
      DB      *gorm.DB
      Redis   *redis.Client
      Logger  *log.Logger
      // EventBus  any
      // KeyRing   any  // 与 STS 对齐的验签/加密材料
      // Config    *Config
      // Tracer    trace.Tracer
      // ...
      // 业务服务
      {{Entity}}Service *{{domain}}.{{Entity}}Service
    }

    func NewDeps() (*Deps, error) {
      // 1) 初始化基础设施(DB/Cache/Logger/...)
      db := mustOpenDB()
      rdb := mustOpenRedis()
      logger := mustLogger()

      d := &Deps{DB: db, Redis: rdb, Logger: logger}

      // 2) 初始化 Repository & Service
      {{entity}}Repo := {{domain}}repo.New{{Entity}}Repo(d.DB)
      d.{{Entity}}Service = {{domain}}svc.New{{Entity}}Service(d, {{entity}}Repo)

      return d, nil
    }

    func (d *Deps) Close(ctx context.Context) error {
      // 逆序关闭资源
      if d.Redis != nil { _ = d.Redis.Close() }
      // if d.DB != nil { sqlDB, _ := d.DB.DB(); _ = sqlDB.Close() }
      return nil
    }
  service_go: |
    // internal/service/{{domain}}/{{resource}}_service.go
    package {{domain}}svc

    import "github.com/ArtisanCloud/PowerX/internal/app/shared"

    type {{Entity}}Service struct {
      deps *shared.Deps
      repo {{domain}}repo.{{Entity}}Repo
    }

    func New{{Entity}}Service(d *shared.Deps, r {{domain}}repo.{{Entity}}Repo) *{{Entity}}Service {
      return &{{Entity}}Service{deps: d, repo: r}
    }
  repo_go: |
    // internal/repository/{{domain}}/{{resource}}_repo.go
    package {{domain}}repo

    import "gorm.io/gorm"

    type {{Entity}}Repo interface {
      // 定义接口方法
    }

    type {{Entity}}RepoImpl struct {
      db *gorm.DB
    }

    func New{{Entity}}Repo(db *gorm.DB) {{Entity}}Repo {
      return &{{Entity}}RepoImpl{db: db}
    }
  wire_in_api_go: |
    // internal/transport/http/{{layer}}/{{domain}}/api.go
    func Register{{Domain}}Routes(rg *gin.RouterGroup, deps *shared.Deps) {
      h := New{{Entity}}Handler(deps.{{Entity}}Service)
      g := rg.Group("/{{domain}}/{{resource}}")
      {
        g.POST("", h.Create)
        g.GET("", h.List)
        g.GET("/:id", h.Get)
        g.PATCH("/:id", h.Update)
        g.DELETE("/:id", h.Delete)
      }
    }

Read the full file on GitHub · 191 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today First seen · 191 lines · 28 tokens per session scan A 4fd783ef9710

Subscribe to this mod's changes

crud-di is a skill published in the GitHub repository ArtisanCloud/PowerX (364 stars, last pushed 4d ago), licensed Apache-2.0. It adds 28 tokens to every session and 1,655 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-04.