go-repository-pattern
Installation
SKILL.md
When to Use
- Creating a new repository for a domain aggregate
- Implementing PostgreSQL adapter with sqlc
- Writing database migrations
- Setting up database connection and pooling
- Adding transactional support
- Creating in-memory repository for local dev / unit tests
Critical Patterns
| Pattern | Rule |
|---|---|
| Interface in domain | Repository interface lives in domain/port.go |
| sqlc for PostgreSQL | Write SQL, generate type-safe Go code — no ORMs, no manual scanning |
| In-memory for local/tests | Pure Go map implementation for zero-dep development |
| Migrations versioned | Use golang-migrate with sequential numbered files |
| Each service owns its DB | No shared databases between microservices |
| Context everywhere | All repository methods accept context.Context as first parameter |
Related skills