Go Backend Architecture

Go modular-monolith backend template for building maintainable, testable APIs with built-in caching and observability.
Purpose
For both engineers and AI agents. Shared rules in AGENTS.md keep structure consistent. The template:
- Provides a reusable backend starter that follows clean architecture.
- Keeps business logic isolated from frameworks and vendors.
- Offers production-ready foundations: HTTP, DB (PostgreSQL with pgvector), cache/KV integration, migrations, tracing, metrics, and structured logging.
- Serves as a base repo to clone for new app projects.
Architecture and Principles
See package-level README.md files and AGENTS.md for implementation guidance and shared architecture rules for both engineers and AI agents.
Why SQL-first data access (no ORM):
- Raw SQL with
sqlc + squirrel provides explicit query control, predictable performance tuning, and compile-time type safety.
- Common downsides are handled by:
sqlc generated typed mappings to reduce runtime schema/query mismatch risk.
squirrel composable dynamic SQL to avoid fragile string concatenation.
- Clean Architecture + repository boundaries to isolate SQL in infra adapters and keep usecases storage-agnostic.
Requirements
Use as a Starter
- Create a new repository from this template.
- Bootstrap the project:
./scripts/bootstrap-template.sh --module github.com/your-org/your-backend
This updates module/import paths, service and stack naming, OpenAPI title, and README title.
Optional flags:
--service-name: sets the service identity used in .env.example and the root README title.
--project-slug: sets the local stack slug used by docker/container/database naming.
--api-title: sets info.title in docs/openapi.yaml.
- If you cloned this repo directly, rename your project directory and set the Git remote to your new repository. The script does not change directory names or remotes.
- Validate with
make openapi-generate && make test.
- Review
docker-compose.yml, .env.example, and docs/openapi.yaml for project-specific values. The account/health code is example domain—replace or remove it and add your own migrations and features.
- Review
AGENTS.md and package-level README.md files before feature development.
Setup and Run
cp .env.example .env
make install
make dev-up && make migrate-up
make run
- Verify
GET /health?check=ready
Common commands: make dev-logs, make dev-down, make migrate-status, make openapi-generate, make run-stop.
Default local ports: Postgres 5432, Redis 6379, OTel 4317/4318, HyperDX 8081.