skills/go-microservice-scaffold/SKILL.md
Scaffold a new Go microservice: directory structure, naming conventions, file layout, and step-by-step creation guide following clean architecture. Trigger: When creating a new microservice, adding a new domain, or reviewing service structure.
npx skillsauth add 333-333-333/agents go-microservice-scaffoldInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Architecture principles (dependency rule, ports & adapters, layer responsibilities) live in the
clean-architectureskill. Load it first if you need the WHY. This skill covers the HOW for Go.
Each microservice lives under api/ and follows this layout:
When a service has one primary domain (e.g., notification, booking):
api/
{service-name}/ # e.g., booking, payment, notification
cmd/
server/
main.go # Entry point — composition root
internal/
domain/ # Domain layer: entities, value objects, ports
entity.go
value_object.go
port.go
error.go
application/ # Application layer: use cases, DTOs
service.go
dto.go
infrastructure/ # Infrastructure layer: implementations
config/ # Environment configuration
config.go
database/ # Database connection setup
postgres.go
handler/ # HTTP/gRPC handlers
http.go
grpc.go
middleware/ # HTTP middleware
auth.go
logging.go
repository/ # Persistence implementations
postgres.go
memory.go
messaging/ # Message pub/sub implementations
publisher.go
subscriber.go
server/ # Server setup
http.go
grpc.go
proto/ # Protobuf definitions for this service
{domain}.proto
migrations/ # SQL migrations
000001_initial.up.sql
000001_initial.down.sql
tests/
e2e/ # E2E tests (Bruno collections)
bruno.json
environments/
local.bru
{domain}/
*.bru
load/ # Load tests (k6 scripts)
smoke.js
load.js
Dockerfile
go.mod
go.sum
Makefile
README.md
Test location convention: See
testing-strategyskill for where each test level goes (unit, integration, contract, E2E, load).
Only use this when a service has multiple distinct domains (e.g., booking + availability):
api/
{service-name}/
cmd/server/main.go
internal/
{domain-1}/ # e.g., booking
domain/
application/
infrastructure/
{domain-2}/ # e.g., availability
domain/
application/
infrastructure/
shared/ # ONLY for truly cross-domain concerns
middleware/
config/
Rule of thumb: If you have
internal/shared/, reconsider. Most "shared" code belongs ininfrastructure/.
| Element | Convention | Example |
|---------|-----------|---------|
| Service directory | lowercase singular noun | api/booking/ |
| Domain directory | domain/ at internal root | internal/domain/ |
| Entity file | entity.go | internal/domain/entity.go |
| Port file | port.go | internal/domain/port.go |
| Use case file | service.go | internal/application/service.go |
| Package names | short, lowercase, singular | package booking |
| Interfaces | verb-er or descriptive | BookingRepository, PaymentGateway |
| Structs | noun | Booking, CreateBookingInput |
| Domain errors | Err prefix | ErrBookingNotFound, ErrBookingOverlap |
| Environment variables | SCREAMING_SNAKE | DB_PASSWORD |
See assets/port.go
See assets/service.go
For single-domain services (most common):
internal/domain/entity.gointernal/application/service.gointernal/infrastructure/For multi-domain services (rare):
internal/{domain-name}/domain/, application/, infrastructure/internal/{domain-name}/domain/entity.gointernal/{domain-name}/domain/port.gointernal/{domain-name}/application/service.gointernal/{domain-name}/infrastructure/cmd/server/main.go (see go-service-bootstrap skill)api/{service-name}/ with full structure abovego mod init github.com/{org}/bastet/api/{service-name}go-docker-deploy skill)go-grpc-services skill)go-repository-pattern skill)go-service-bootstrap skill)local-dev-workflow skill)# Create a new SINGLE-DOMAIN service scaffold (most common)
mkdir -p api/{service}/cmd/server
mkdir -p api/{service}/internal/{domain,application,infrastructure/{config,database,handler,middleware,repository,messaging,server}}
mkdir -p api/{service}/proto
mkdir -p api/{service}/migrations
# Initialize Go module
cd api/{service} && go mod init github.com/{org}/bastet/api/{service}
# Verify structure
tree api/{service}
| Don't | Do |
|----------|-------|
| api/booking/controllers/ | api/booking/internal/infrastructure/handler/ |
| api/booking/models/ | api/booking/internal/domain/entity.go |
| internal/shared/ in single-domain services | Put in internal/infrastructure/ |
| internal/{domain}/ when service has one domain | Use internal/domain/ directly |
| Import cloud SDK in domain | Define interface in domain, implement in infrastructure |
| Shared database between services | Each service owns its data |
| utils/ package | Put helpers in the domain or infrastructure where they belong |
| Business logic in handlers | Handlers call application service, that's it |
| Skill | What it covers |
|-------|----------------|
| clean-architecture | Principles: dependency rule, layers, ports & adapters (load first!) |
| go-service-bootstrap | Configuration, DI wiring, environments, graceful shutdown |
| go-gin-handlers | HTTP handler patterns, middleware, error responses |
| go-repository-pattern | Persistence, migrations, sqlc |
| go-docker-deploy | Dockerfile, docker-compose, deployment |
testing
Review Flutter components and screens for UX/UI compliance. Trigger: When user invokes /ux-review command or requests UX audit.
development
TypeScript strict patterns and best practices. Trigger: When implementing or refactoring TypeScript in .ts/.tsx (types, interfaces, generics, const maps, type guards, removing any, tightening unknown).
testing
Testing philosophy and strategy for every feature: test pyramid, mandatory levels per change type, completion checklist, and skill delegation. Trigger: When planning tests for a feature, reviewing test coverage, defining acceptance criteria, or asking what tests a change needs.
development
Terraform security practices: sensitive variables, secret management, state protection, .gitignore patterns, and CI/CD credential handling. Trigger: When handling secrets in Terraform, configuring state backends, reviewing .gitignore for Terraform, or setting up CI/CD pipelines for infrastructure.