add-provider
Checklist for adding a new AI provider (image, video, text, audio) that satisfies all 5 integration principles — ACL, bulkhead, idempotency, observability, and…
Systematic 5-step debugging flow for Go 1.22+ services. Load when a test fails, a goroutine leaks, a downstream provider hangs, errors lose context, or production logs are unhelpful. Forces layer isolation (handler vs service vs repo vs provider) and runs the 5 most common Go
$ npx -y skills add yerdaulet-damir/vibe-coding-rules --skill debug-go --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/debug-goContext preview
The summary Claude sees to decide when to auto-load this skill.
Systematic 5-step debugging flow for Go 1.22+ services. Load when a test fails, a goroutine leaks, a downstream provider hangs, errors lose context, or production logs are unhelpful. Forces layer isolation (handler vs service vs repo vs provider) and runs the 5 most common Go
name: debug-go description: Systematic 5-step debugging flow for Go 1.22+ services. Load when a test fails, a goroutine leaks, a downstream provider hangs, errors lose context, or production logs are unhelpful. Forces layer isolation (handler vs service vs repo vs provider) and runs the 5 most common Go antipattern greps before any code change — prevents the "add a goroutine to fix a slow handler" cascade.
Stop. Do not edit any file yet. Work through these 5 steps in order.
---
Go bugs almost always live in one of these layers. Identify which one before touching code.
| Symptom | Likely layer | First grep | |---------|------------|-----------| | 500 in prod, no useful log | Handler — error mapping | `grep -n "errors.Is\|errors.As" internal/server/handlers.go` | | Wrong amount / state after mutation | Service / repo | `grep -n "Hold\|Confirm\|Refund" internal/<domain>/service.go` | | Hangs under load | HTTP client / bulkhead | `grep -rn "http.DefaultClient\|MaxConnsPerHost" internal/` | | `context deadline exceeded` everywhere | Missing `ctx` propagation | `grep -rn "context.Background()\|context.TODO()" internal/` | | Goroutine leak in pprof | `errgroup` not used / unclosed channels | `grep -rn "go func\b" internal/` | | Test passes locally, race on CI | Shared mutable state | `go test ./... -race` | | Panic crashes server | Missing `recover` middleware | `grep -rn "recover()" internal/server/` | | Downstream API change broke us | Provider parser | `grep -rn "json.Unmarshal\|json.NewDecoder" internal/providers/` |
Pick **one** layer. Do not touch any other layer in this debug pass.
---
# Antipattern 1: http.DefaultClient (no per-provider isolation)
grep -rn "http\.DefaultClient" internal/
# Antipattern 2: context.Background() / context.TODO() in non-main code
grep -rn "context\.Background()\|context\.TODO()" internal/ \
--include="*.go" | grep -v "_test.go"
# Antipattern 3: panic in production code
grep -rn "panic(" internal/ --include="*.go" | grep -v "_test.go\|recover"
# Antipattern 4: fmt.Println / log.Printf instead of slog
grep -rn "fmt\.Println\|log\.Printf" internal/ --include="*.go" | grep -v "_test.go"
# Antipattern 5: errors not wrapped with %w
grep -rn "errors\.New(\"[^%]*: \"" internal/ --include="*.go"
# Hits with concatenation suggest a missed `%w` opportunity.| Result | Root cause | Principle | |--------|-----------|-----------| | `http.DefaultClient` used | Bulkhead broken — one slow downstream blocks all | F4 | | `context.Background()` in handler chain | Lost cancellation/deadline propagation | F2 | | `panic()` in handler/service | Server crashes on edge case | F3 | | `fmt.Println`/`log.Printf` | Logs without context, unsearchable | F6 | | `errors.New` with concatenated context | Lost error chain, `errors.Is/As` fails | F3 |
---
For service/repo bugs — write a failing test first:
func TestService_RaceOnConcurrentCharge(t *testing.T) {
t.Parallel()
svc := newTestService(t, dec("10.00"))
ctx := context.Background()
// Two concurrent charges with the same idempotency key.
// Should hold once, not twice.
var wg sync.WaitGroup
var ids [2]string
for i := 0; i < 2; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
id, _ := svc.Charge(ctx, "u-1", dec("4.00"), "idem-x")
ids[i] = id
}()
}
wg.Wait()
if ids[0] != ids[1] {
t.Fatalf("idempotency violated: %s vs %s", ids[0], ids[1])
}
}Run it:
go test -run TestService_RaceOnConcurrentCharge -race -v ./internal/credits/
It must FAIL before the fix.
For HTTP client / provider bugs — use `httptest.Server` to simulate the failure:
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusTooManyRequests)
}))
defer srv.Close()
p := &FalAI{client: srv.Client(), baseURL: srv.URL, log: slog.Default()}
_, err := p.Generate(context.Background(), JobRequest{ModelID: "m", Prompt: "p"})
if !errors.Is(err, ErrRateLimited) {
t.Fatalf("expected ErrRateLimited, got %v", err)
}---
Minimum change. Do not refactor unrelated code.
| Layer | Where to fix | |-------|------------| | Handler / error → HTTP code | `internal/server/handlers.go` | | Business logic | `internal/<domain>/service.go` | | Persistence / concurrency | `internal/<domain>/repository.go` | | External API parsing | `internal/providers/<name>.go` (the ACL) | | HTTP client config | `internal/httpclient/client.go` | | Logging context | `internal/context/keys.go` + middleware | | Graceful shutdown | `internal/server/run.go` |
**Goroutine leaks specifically:** add `errgroup` with a parent `context.WithCancel`. Every `go func` should be replaceable by `g.Go(func() error { ... })`. (Principle F8.)
---
# Type / vet check go vet ./... # Race detector — catches concurrency bugs you can't see by reading go test ./... -race # All tests pass go test ./... # (If you have a linter) golangci-lint run
Then re-run all 5 antipattern greps from Step 2. You must not have introduced any new violations while fixing.
---
| Error / Symptom | Where to look | Likely cause | |----------------|--------------|--------------| | `runtime error: invalid memory address` | nil pointer | A struct field not initialized — check the constructor | | `concurrent map read and write` | shared mutable map | Add `sync.Mutex` or use `sync.Map` if read-heavy | | `context deadline exceeded` cascading everywhere | parent ctx | Probably a fixed `context.WithTimeout(ctx, 1s)` upstream | | `dial tcp: i/o timeout` | network or DNS | Check provider client `Timeout`; check pod DNS | | `too many open files` | FD ex
54 production architecture principles your AI coding agent (Claude Code, Cursor) follows automatically. Drop-in CLAUDE.md, .cursor/rules/, and .claude/skills/ for FastAPI, Next.js 15, and Go 1.22+. MIT.
Repo: yerdaulet-damir/vibe-coding-rules
Checklist for adding a new AI provider (image, video, text, audio) that satisfies all 5 integration principles — ACL, bulkhead, idempotency, observability, and…
Systematic 5-step backend debugging flow for AI-coded FastAPI apps. Load this skill when a bug is reported, a test fails, or unexpected behavior appears in any…
Systematic 5-step debugging flow for Next.js 15 + React 19 + TypeScript apps. Load when a UI bug is reported, hydration error appears, Server Action returns…
Pre-flight checklist for adding a new feature to a Go 1.22+ service. Load when creating a new endpoint, internal package, external integration, or background…
Pre-flight checklist for adding a new feature to a Next.js 15 + TypeScript app. Load when creating a new page, route, server action, or feature module. Forces…
Pre-flight checklist that must complete before writing the first line of code for any new feature. Load this skill when starting a new endpoint, service…