backend-maintenance
Backend codebase maintenance - dead code detection, linting, dependency updates, and cleanup for Go code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Backend codebase maintenance - dead code detection, linting, dependency updates, and cleanup for Go code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Frontend codebase maintenance - dead code detection, linting, dependency updates, and cleanup for TypeScript/React code.
Add a new analytics card to the session summary panel. Covers backend analyzer, database migration, API response, and frontend component with Storybook stories.
Cut a new semver release — tag, write release notes with rigorous DB migration and API change verification, and publish via gh.
Fix bugs using Test-Driven Development. Use for bug fixes from Linear tickets or user reports. Emphasizes writing tests FIRST before any implementation.
| name | backend-maintenance |
| description | Backend codebase maintenance - dead code detection, linting, dependency updates, and cleanup for Go code. |
Periodic evaluation and cleanup for the backend codebase.
subagent_type=Explore for codebase explorationTrack with TodoWrite:
# Install if needed
go install honnef.co/go/tools/cmd/staticcheck@latest
go install golang.org/x/tools/cmd/deadcode@latest
# Run from backend dir
cd backend && ~/go/bin/staticcheck ./...
cd backend && ~/go/bin/deadcode -test ./...
IMPORTANT: Always auto-fix staticcheck and deadcode findings immediately, as long as:
Do NOT ask for permission - just fix and report what was cleaned up.
cd backend && go vet ./...
cd backend && go mod tidy && git diff go.mod go.sum
cd backend && go list -m -u all | grep '\['
# IMPORTANT: Run FULL test suite for accurate coverage
# The -short flag skips integration tests which provide most of the coverage
# Example: internal/db goes from 0% (-short) to 69.5% (full)
cd backend && DOCKER_HOST=unix:///Users/jackie/.orbstack/run/docker.sock go test -cover ./...
Track with TodoWrite:
POSITIVE patterns to verify are in place:
internal/validation packageinternal/ratelimit)NEGATIVE patterns to search for (vulnerabilities):
# SQL injection risks - string concatenation in queries
grep -r 'fmt.Sprintf.*SELECT\|fmt.Sprintf.*INSERT\|fmt.Sprintf.*UPDATE\|fmt.Sprintf.*DELETE'
# Hardcoded secrets
grep -ri 'password.*=.*"\|secret.*=.*"\|apikey.*=.*"\|api_key.*=.*"'
# Ignored errors on sensitive operations
grep -r 'body, _ := io.ReadAll'
Use Grep to find these patterns:
# Long parameter lists (5+ params)
Pattern: "func.*\(.*,.*,.*,.*,.*,"
# Magic numbers (undocumented constants)
Pattern: "[^0-9][0-9]{3,}[^0-9]"
# Commented-out code blocks
Pattern: "//.*func |//.*if |//.*for "
# Naked returns in long functions
Pattern: "return$"
# Empty error handling
Pattern: "if err != nil {\s*}" (multiline)
# Silent error ignoring
Pattern: ", _ :="
Actively search for opportunities to reduce duplication and simplify logic:
Duplicated patterns to look for:
How to search:
Logic simplification to look for:
errors.Is instead of type switches)Action: Report findings with specific file locations and a brief description of the simplification. For low-risk improvements (extracting a shared helper, simplifying a conditional), fix directly. For larger refactors, note in the findings table.
Reviewed and marked as acceptable (see code comments):
OAuth Callbacks (internal/auth/oauth.go) - ACCEPTABLE
HandleGitHubCallback and HandleGoogleCallback share similar logicInline HTML Templates (internal/auth/oauth.go, internal/admin/handlers.go) - ACCEPTABLE
generateDevicePageHTML, HandleLoginSelector, HandleListUsersCookie Operations (internal/auth/oauth.go) - FIXED
clearCookie(w, name) helper functionTwo Rate Limiter Implementations - ACCEPTABLE
internal/ratelimit: Token bucket for API rate limiting (allows bursts)internal/email: Sliding window for strict email quotas (no bursts)EmailRateLimiter typeSession List Queries (internal/db/sessions.go) - ACCEPTABLE
ListUserSessions functionRemaining items to consider (lower priority):
internal/analytics/store.go)
By size/complexity (lines of production code):
| File | Lines | Notes |
|---|---|---|
internal/auth/oauth.go | ~1910 | OAuth flows, device auth, login selector |
internal/api/sync.go | ~1150 | Sync init/chunk/read handlers |
internal/analytics/store.go | ~995 | Card storage operations |
internal/admin/handlers.go | ~711 | Admin user management UI |
internal/db/sessions.go | ~693 | Session CRUD operations |
internal/api/server.go | ~715 | Routing, middleware setup |
internal/api/shares.go | ~650 | Share creation/management |
internal/storage/s3.go | ~363 | S3/MinIO operations |
clearCookie helper added)After fixing issues in Phases 1-2, run the code-simplifier agent to simplify and refine any modified backend code:
Use the Task tool with subagent_type="code-simplifier" and prompt:
"Simplify and refine recently modified Go code in the backend/ directory.
Focus on clarity, consistency, and maintainability while preserving all functionality."
This catches additional simplification opportunities (verbose patterns, unnecessary complexity, inconsistent style) that automated tools miss.
Create a summary with:
| Category | Severity | Issue | Location | Action |
|---|---|---|---|---|
| Security | High/Med/Low | Description | file:line | Fix/Ticket/Ignore |
| Dead Code | ... | ... | ... | ... |
| Code Smell | ... | ... | ... | ... |
| Duplication | ... | ... | ... | ... |
| Simplification | ... | ... | ... | ... |
Positive patterns in this codebase:
Areas reviewed and marked acceptable:
clearCookie helperMinor items to watch:
_, _ := patterns) - low severityCreate Linear tickets with label tech-debt: