Skip to content
Makefile Contract

Makefile Contract

Sphere Go repositories use make as the day-to-day workflow entrypoint. The CLI creates a project; the project Makefile additionally owns local development, generation, running, and build commands.

This keeps Sphere aligned with common Go practices and leaves each tool visible.

Standard Targets

All Go repositories provide the dependency, formatting, test, lint, and check targets below. Official templates keep the additional project targets stable where the capability exists:

TargetPurpose
make deps-updateUpdate direct Go dependencies and tidy every module in the repository.
make tidyTidy every Go module without upgrading dependencies.
make fmtFormat Go, Protobuf, and import layout.
make testRun the repository’s complete test workflow.
make lintRun non-mutating format, Go, Buf, and linter checks.
make checkVerify dependencies, lint, and run tests.
make initDownload modules, install required local tools, generate artifacts, and write config.json if it is missing.
make installInstall local development tools such as Buf, Wire, Swag, protoc plugins, and linters.
make gen/confGenerate example configuration (config_gen.json) and write config.json if it is missing.
make gen/dbGenerate persistence code for the template’s selected ORM.
make gen/protoRun Protobuf generation and Sphere protoc plugins.
make gen/docsGenerate Swagger/OpenAPI documentation.
make gen/wireGenerate dependency injection wiring.
make gen/allClean and regenerate the full generated surface.
make gen/dtsGenerate TypeScript clients when the template supports it.
make runRun the application locally.
make run/raceRun locally with the race detector. Requires cgo; not the default run target.
make run/swagServe generated Swagger UI when available.
make buildBuild a binary for the current platform.
make build/dockerBuild a Docker image when the template provides Docker support.
make cleanRemove generated artifacts and build outputs.

Templates can add more targets, but these names should not change without a migration note.

Tool Ownership

The Makefile should call mature tools directly:

  • go for modules, tests, builds, and local execution;
  • buf for proto dependency and generation workflows;
  • wire for dependency injection generation;
  • swag for Swagger documentation generation;
  • docker or docker buildx for image builds;
  • project-local Go tools under cmd/tools/** for template-specific generation.

Sphere CLI should not duplicate these responsibilities.

Generated Code Boundaries

Generated outputs should be easy to clean and regenerate. In the default layout, this includes:

  • api/**;
  • swagger/**;
  • generated Ent packages;
  • Wire output;
  • generated conversion, mapping, binding, and CRUD helpers.

Handwritten code should live outside generated paths, especially in:

  • proto/** for API contracts;
  • internal/service/** for generated interface implementations;
  • internal/biz/** for business logic;
  • internal/pkg/** for project infrastructure and adapters.

The Makefile is the place where these ownership rules become repeatable.

Last updated on