Skip to main content

Reference Backend Layout

Use this as a baseline structure for Go services:

cmd/                  # process entrypoints
server/ # HTTP app creation/listening
router/ # route wiring
middleware/ # cross-cutting request middleware
handlers/ # transport layer (HTTP)
services/ # business workflows/orchestration
models/ # persistence models and DB operations
repository/ # optional data-access helpers
schemas/ # request/response DTO contracts
database/ # DB client setup and migrations bootstrap
migrations/ # SQL migrations
tenant_migrations/ # optional tenant-scoped migrations
redisclient/ # optional Redis bootstrap
utils/ # shared utilities
scripts/ # operational scripts
internal/ # internal-only packages

Notes

  • Not every service needs every folder.
  • Keep naming and responsibilities consistent once a pattern is chosen.
  • Prefer adding new capability in the right layer over expanding handlers into orchestration code.