go-architect
Skill91 starsChanged 5 days agoApache-2.0View on GitHub
Go application architecture with net/http 1.22+ routing, project structure patterns, graceful shutdown, and dependency injection. Use when building Go web servers, designing project layout, or structuring application dependencies.
- Reads credentials
3 other projects use a version of this.
Adopted by
Most recently taken up by
- GoogleCloudPlatform/devrel-demostheir own version, first seen Nov 2, 2026
- ralvarez-ai/ralvaskillstheir own version, first seen Nov 1, 2026
- ralvarezdev/ralvaskillstheir own version, first seen Sep 29, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- GoogleCloudPlatform/devrel-demos★ 416same name
- ralvarez-ai/ralvaskills★ 4same name
- ralvarezdev/ralvaskills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository85 other files it gives its agents.
- AGENTS.mdAGENTS.md
- llms.txtllms.txt
- agent-architecture-analysisSkill
- app-intents-code-reviewSkill
- artifact-analysisSkill
- axum-code-reviewSkill
- brainstorm-beagleSkill
- bubbletea-code-reviewSkill
- cloudkit-code-reviewSkill
- elixir-performance-reviewSkill
- elixir-security-reviewSkill
- elixir-writing-docsSkill
- exdoc-configSkill
- exunit-code-reviewSkill
- fastapi-code-reviewSkill
- fetch-pr-feedbackSkill
- ffi-code-reviewSkill
- fix-llm-artifactsSkill
- fowler-refactoringSkill
- gen-test-planSkill
- go-code-reviewSkill
- go-data-persistenceSkill
- go-testing-code-reviewSkill
- healthkit-code-reviewSkill
- humanize-beagleSkill
- improve-docSkill
- ios-animation-code-reviewSkill
- liveview-code-reviewSkill
- llm-artifacts-detectionSkill
- llm-judgeSkill
- macros-code-reviewSkill
- phoenix-code-reviewSkill
- postgres-code-reviewSkill
- prfaq-beagleSkill
- prometheus-go-code-reviewSkill
- pytest-code-reviewSkill
- quick-planSkill
- react-flow-code-reviewSkill
- react-flowSkill
- react-router-code-reviewSkill
- react-router-v7Skill
- receive-feedbackSkill
- refactor-repoSkill
- resolve-beagleSkill
- respond-pr-feedbackSkill
- review-ai-writingSkill
- review-elixirSkill
- review-frontendSkill
- review-goSkill
- review-iosSkill
- review-llm-artifactsSkill
- review-planSkill
- review-pythonSkill
- review-remix-v2Skill
- review-rustSkill
- review-skillSkill
- review-structureSkill
- review-tuiSkill
- review-verification-protocolSkill
- run-test-planSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 2 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Use this sequence when implementing or reviewing work that claims to follow this skill.
- Very specific: line 135
When wrapping http.ResponseWriter (e.g.
- Distinctive: line 177
Start flat. Migrate when you see the signs described in the reference.
- Very specific: line 181
Every production Go server needs graceful shutdown.
- Very specific: line 232
Do not start with gin.Default() or echo.New().
- Very specific: line 247
All initialization belongs in main() or a run() function so it can be tested and errors can be handled.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Lead Go Architect
Quick Reference
| Topic | Reference |
| Flat vs modular project layout, migration signals | references/project-structure.md |
| Graceful shutdown with signal handling | references/graceful-shutdown.md |
| Dependency injection patterns, testing seams | references/dependency-injection.md |
Core Principles
- Standard library first -- Use
net/httpand the Go 1.22+ enhancedServeMuxfor routing. Only reach for a framework (chi, echo, gin) when you have a concrete need the stdlib cannot satisfy (e.g., complex middleware chains, regex routes). - Dependency injection over globals -- Pass databases, loggers, and services through struct fields and constructors, never package-level
var. - Explicit over magic -- No
init()side effects, no framework auto-wiring.main.gois the composition root where everything is assembled visibly. - Small interfaces, big structs -- Define interfaces at the consumer, keep them narrow (1-3 methods). Concrete types carry the implementation.
Hard gates
Use this sequence when implementing or reviewing work that claims to follow this skill. Do not skip ahead; each step has a pass condition you can answer with tooling or a concrete file path.
- Toolchain vs APIs — If the code uses Go 1.22+
ServeMuxfeatures (method+path patterns like"GET /x/{id}",r.PathValue, or{path...}), or Go 1.23+r.Pattern/ Go 1.24+slog.DiscardHandler: rungo version(or checkgo.mod) and pass only if the reported toolchain supports those APIs. If the project must stay on an older Go, pass only by not using those APIs and saying so in the review or PR. - Composition root — Pass when
main.goorcmd/.../main.govisibly constructs the server and injects shared dependencies (DB, logger, config). Fail if shared dependencies are wired ininit()or package-levelvarinstead of explicit construction inmain(or arun()called frommain). - Production HTTP shutdown — For a long-lived HTTP service, pass only if shutdown uses
http.Server.Shutdownwith a bounded context (e.g.context.WithTimeout) after waiting onsignal.NotifyContext(or equivalent). Cite the file path when reporting; see references/graceful-shutdown.md for the full pattern. - No env/globals in handlers — Pass when handlers and domain code take dependencies via structs/arguments. Fail if handlers read
os.Getenvfor secrets or use package-levelvarfor DB/clients (loading env inmainor a dedicated config package is fine).
Go 1.22+ Enhanced Routing
Go 1.22 upgraded http.ServeMux with method-based routing and path parameters, eliminating the most common reason for third-party routers.
Method-Based Routing and Path Parameters
mux := http.NewServeMux()
mux.HandleFunc("GET /api/users", s.handleListUsers)
mux.HandleFunc("GET /api/users/{id}", s.handleGetUser)
mux.HandleFunc("POST /api/users", s.handleCreateUser)
mux.HandleFunc("DELETE /api/users/{id}", s.handleDeleteUser)Extracting Path Parameters
func (s *Server) handleGetUser(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
http.Error(w, "missing id", http.StatusBadRequest)
return
}
user, err := s.users.GetUser(r.Context(), id)
if err != nil {
s.logger.Error("getting user", "err", err, "id", id)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user)
}Wildcard and Exact Match
// Exact match on trailing slash -- serves /api/files/ only
mux.HandleFunc("GET /api/files/", s.handleListFiles)
// Wildcard to end of path -- /api/files/path/to/doc.txt
mux.HandleFunc("GET /api/files/{path...}", s.handleGetFile)Routing Precedence
The new ServeMux uses most-specific-wins precedence:
GET /api/users/{id}is more specific thanGET /api/users/GET /api/users/meis more specific thanGET /api/users/{id}- Method routes take precedence over method-less routes
Server Struct Pattern
The Server struct is the central dependency container for your application. It holds all shared dependencies and implements http.Handler.
type Server struct {
db *sql.DB
logger *slog.Logger
router *http.ServeMux
}
func NewServer(db *sql.DB, logger *slog.Logger) *Server {
s := &Server{
db: db,
logger: logger,
router: http.NewServeMux(),
}
s.routes()
return s
}
func (s *Server) routes() {
s.router.HandleFunc("GET /api/users/{id}", s.handleGetUser)
s.router.HandleFunc("POST /api/users", s.handleCreateUser)
s.router.HandleFunc("GET /healthz", s.handleHealth)
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.router.ServeHTTP(w, r)
}Middleware Wrapping & Ordering
Apply middleware at the http.Server level or per-route. Always place panic recovery outermost so panics inside outer middleware (request ID, logger, auth) are also caught:
// Wrap entire server (Recovery outermost)
httpServer := &http.Server{
Addr: ":8080",
Handler: recoveryMiddleware(requestLogger(s)),
}
// Or per-route
s.router.Handle("GET /api/admin/", adminOnly(http.HandlerFunc(s.handleAdmin)))Middleware ResponseWriter Wrapper & r.Pattern
When wrapping http.ResponseWriter (e.g. to capture status codes), implement Unwrap() http.ResponseWriter so Go 1.20+ http.ResponseController (Flush, Hijack, deadlines) continues to work without manually forwarding optional interfaces. On Go 1.23+, log r.Pattern alongside r.Method for bounded route labels:
type statusWriter struct {
http.ResponseWriter
status int
}
func (w *statusWriter) WriteHeader(code int) {
w.status = code
w.ResponseWriter.WriteHeader(code)
}
func (w *statusWriter) Unwrap() http.ResponseWriter {
return w.ResponseWriter
}
func requestLogger(logger *slog.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
sw := &statusWriter{ResponseWriter: w, status: http.StatusOK}
next.ServeHTTP(sw, r)
logger.Info("request",
"method", r.Method,
"pattern", r.Pattern, // Go 1.23+: matched ServeMux pattern
"path", r.URL.Path,
"status", sw.status,
"dur", time.Since(start),
)
})
}
}Project Structure
Choose based on project size:
- Flat structure -- single package, all files in root. Best for CLIs, small services, < ~10 handlers. See references/project-structure.md.
- Modular/domain-driven --
cmd/,internal/with domain packages. For larger apps with multiple bounded contexts. See references/project-structure.md.
Start flat. Migrate when you see the signs described in the reference.
Graceful Shutdown
Every production Go server needs graceful shutdown. The pattern uses signal.NotifyContext to listen for OS signals and http.Server.Shutdown to drain connections.
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
defer cancel()
// ... start server in goroutine ...
<-ctx.Done()
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer shutdownCancel()
httpServer.Shutdown(shutdownCtx)Full pattern with cleanup ordering in references/graceful-shutdown.md.
When to Load References
Load project-structure.md when:
- Scaffolding a new Go project
- Discussing package layout or directory organization
- The project is growing and needs restructuring
Load graceful-shutdown.md when:
- Setting up a production HTTP server
- Implementing signal handling or clean shutdown
- Discussing deployment or container readiness
Load dependency-injection.md when:
- Designing how services, stores, and handlers connect
- Making code testable with interfaces
- Reviewing constructor functions or wiring logic
Anti-Patterns
Global database variables
// BAD -- untestable, hidden dependency
var db *sql.DB
func handleGetUser(w http.ResponseWriter, r *http.Request) {
db.QueryRow(...)
}Pass db through a Server or Service struct instead.
Framework-first thinking
Do not start with gin.Default() or echo.New(). Start with http.NewServeMux(). Only introduce a framework if you hit a real limitation of the stdlib that justifies the dependency.
God packages
A single handlers package with 50 files is not organization. Group by domain (user, order, billing), not by technical layer.
Using init() for setup
// BAD -- invisible side effects, untestable
func init() {
db, _ = sql.Open("postgres", os.Getenv("DATABASE_URL"))
}All initialization belongs in main() or a run() function so it can be tested and errors can be handled.
Reading config in business logic
// BAD -- couples handler to environment
func (s *Server) handleSendEmail(w http.ResponseWriter, r *http.Request) {
apiKey := os.Getenv("SENDGRID_API_KEY") // don't do this
}Inject configuration values or clients through constructors.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

