Agent skill
kratos-service-layer
Generates gRPC/HTTP service handlers for go-kratos microservices. Creates service structs, handler methods, and integrates with protobuf definitions. Use when implementing service layer for kratos services.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/kratos-service-layer
SKILL.md
<essential_principles>
How Kratos Service Layer Works
Service Layer Role
Connects transport (gRPC/HTTP) to business logic:
Responsibilities:
- Handle gRPC/HTTP requests
- Map proto DTOs to business models (via mapper)
- Call use case methods
- Map results back to proto responses
- Convert business errors to gRPC status codes
Service Struct Pattern
type {Entity}Service struct {
pb.Unimplemented{Entity}ServiceServer // Embed unimplemented server
uc biz.{Entity}UseCase // Use case dependency
}
Handler Method Pattern
func (s *{Entity}Service) Create{Entity}(ctx context.Context, in *pb.Request) (*pb.Response, error) {
// 1. Map request to business model
entity := {Entity}FromRequest(in)
// 2. Call use case
result, err := s.uc.Create{Entity}(ctx, entity)
if err != nil {
return nil, toServiceError(err) // Map business error to gRPC error
}
// 3. Map result to response
return &pb.Response{Entity: toProto{Entity}(result)}, nil
}
</essential_principles>
- Create service handlers for new entity
- Add handler methods to existing service
- View handler patterns and examples
Wait for response before proceeding.
After reading the workflow, follow it exactly.
<reference_index> Core: handler-pattern.md, service-structure.md, error-mapping.md Mappers: mapper-conventions.md </reference_index>
<workflows_index>
| Workflow | Purpose |
|---|---|
| create-service.md | Generate service handlers and mappers |
| add-handlers.md | Add methods to existing service |
| view-examples.md | Show patterns |
| </workflows_index> |
<success_criteria> Service layer code is correct when:
- Service struct embeds Unimplemented{Entity}ServiceServer
- Constructor added to service.ProviderSet
- Handlers map DTOs via mapper functions
- Errors converted to gRPC status codes
- All methods have godoc comments
- User reminded to run
make generate</success_criteria>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?