/matex-skills:Matex-Add-Domainfrom matex-skills
Generates a new business domain (handler/service/dao + route registration + assembly + tests) in the Matex scaffold. Follows layered architecture with dependency injection.
Ships in matex-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
在 internal/domain/<name>/ 下新增一个业务域,并把它的路由挂到服务上。参考现成的 internal/domain/helloworld。
internal/domain/<name>/创建三个文件(沿用 helloworld 的形态):
service.go — 业务逻辑,Deps 结构注入,nil 即"未配置":
package <name>
import (
"context"
"github.com/smallnest/matex/pkg/core/db"
"github.com/smallnest/matex/pkg/core/redis"
"github.com/smallnest/matex/pkg/core/kafka"
)
type Deps struct {
DB *db.DB
Redis *redis.Client
Producer *kafka.Producer
// 其它服务专属依赖
}
type Service struct{ deps Deps }
func New(d Deps) *Service { return &Service{deps: d} }
func (s *Service) Do(ctx context.Context, id int64) (any, error) {
// 业务:缓存读写、DB、事件发布,每处 if s.deps.X != nil 防御
return nil, nil
}
handler.go — HTTP 边界,只做参数解析 + 调 service + 返回:
type Handler struct{ svc *Service }
func (h *Handler) Do(ctx context.Context, r *http.Request) (any, error) {
id := r.PathValue("id")
if id == "" {
return nil, errs.Invalid(40001, "id is required")
}
// 需要 body 时用 httpx.ReadJSON(r, &req),失败返回 errs.Invalid(40002, ...)
return h.svc.Do(ctx, parseID(id))
}
dao.go — 数据访问(若用到 DB):
type DAO struct{ db *db.DB }
func (d *DAO) ByID(ctx context.Context, id int64) (*Row, error) {
return d.db.QueryOne[Row](ctx, `SELECT ... WHERE id = ?`, id)
}
internal/app/service.go 里装配// 逗号-ok 取基础设施;需要它时用 env.RequireDB() / env.RequireKafka() 让启动失败。
deps := <name>.Deps{}
if db, ok := env.DB(); ok {
deps.DB = db
}
if rc, ok := env.Redis(); ok {
deps.Redis = rc
}
if p, ok := env.Kafka(); ok {
deps.Producer = p
}
s.<name> = <name>.New(deps)
// BuildRouter 里注册路由:
srv.Handle("GET", "/api/v1/<name>/{id}", <name>.NewHandler(s.<name>).Do)
redistest.Start(t) 拿 redis;dbtest.Start(t) 拿迁移好的库(默认 SQLite,离线可用;需要新表就加 migrations/NNN_xxx.sql)。errs,不裸 errors.New 抛给框架。pkg/core。GET/POST…),path 用 Go 1.22 语法({id})。make ci
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
15 skills in this plugin
/Matex-Setup-Audit-LogMatex Setup Audit Log在 matex 中记录审计日志:pkg/core/audit 的 Record/Event(actor/action/resource/result/detail),默认写结构化日志,可用 SetSink 落库或投递到只追加的存储。当用户说"审计 / 审计日志 / audit log / 操作记录 / 谁改了什么 / 合规 / 不可否认 / access log"时使用。/Matex-Setup-AuthMatex Setup Auth在 matex 中接入认证与授权:配置 auth 段、验签 Bearer token、按路由分级保护、读取当前主体。当用户说"加认证 / 加鉴权 / 接 auth / setup auth / JWT / OIDC / 登录校验 / token 校验 / 权限控制 / RBAC"时使用。/Matex-Setup-CacheMatex Setup Cachenpx claudepluginhub smallnest/matex --plugin matex-skills