services-and-interfaces
Define and implement services that encapsulate business logic with proper constructor-based dependency injection.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-04
- Stars
- ★ 41
- Forks
- 0
01 前言 Front Matter
- name
- services-and-interfaces
- description
- Define and implement services that encapsulate business logic with proper constructor-based dependency injection.
02 资源文件 1
- 脚本examples/todo_service.go1.5 KB
03 SKILL.md 正文
Services & Interface Design
When to use this skill
- Create services that encapsulate business logic
- Implement business operations that delegate to repositories for data access (Database)
- Add authentication or domain-specific features as services
Key principles
- Concrete struct design: Services are defined as interfaces and implemented by concrete structs with the same name lowercase and with a constructor (e.g.,
TodoServiceandtodoServicewithNewTodoServiceconstructor) - Constructor-based injection: Dependencies passed at construction
- Single responsibility: Each service handles one domain concern
- Repository delegation: Services delegate all data access to repositories
- Context-aware: All public methods accept
context.Context - Interface return types: Constructors return interfaces, not concrete types
- Single File Exports: Each service implementation is in its own file. However, all service interfaces are exported from
interfaces.gounder theservices/folder.
Pattern
Services handle business logic:
- Define interface for service with methods representing business operations
- Implement as concrete struct with repository dependencies
- Constructor function injects all dependencies
- Methods are thin wrappers that validate, transform, and delegate to repositories
- Return interfaces from constructors
Example
See examples/todo_service.go for:
- TodoService interface definition
- todoService implementation with constructor
- Validation and repository delegation patterns
Common mistakes
- Service-to-service direct calls without interfaces
- Putting queries in services (repositories own data access)
- Missing context parameter
- Exporting implementation struct instead of interface
- Not testing with mocks
References
- services/core.go - Core service interfaces
- internal/services/user_service.go
- internal/services/account_service.go
04 同仓库更多 Skills
typst
Typst document creation and package development. Use when: (1) Working with .typ files, (2) User mentions typst, typst.toml, or typst-cli, (3) Creating or using Typst packages, (4) Developing document templates, (5) Converting Markdown/LaTeX to Typst
shadcn
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".
handoff
Compact the current conversation into a handoff document for another agent to pick up.
grilling
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
grill-me
A relentless interview to sharpen a plan or design.
dont-waffle
Use this skill when answering questions, explaining concepts, writing technical responses, reviewing code, or helping with development tasks. Communicate in clear, simple, standard English. Keep answers concise and focused, remove unnecessary filler and repetition, explain technical ideas in plain language, and structure information so it is easy to read and understand. When showing code, present it clearly with enough context for the developer to understand what it does and where it belongs.