Bibit is a Go project template for backend services. One command gives you a working HTTP server, gRPC server, background worker, PostgreSQL setup, migrations, code generators, tests, and observability, so you can start on business logic right away.
The code comes with a small sign-up/sign-in feature (user and user_session). That feature exists to show how each layer is written. Read it, copy its patterns, then delete it. See Starter kit.
- Requirements
- Create a project
- Commands and conventions
- Project layout
- Observability
- Deployment
- Starter kit
- Go 1.27+
- PostgreSQL 18+ (the schema uses
uuidv7()) - goreman for
./bin/dev:go install github.com/mattn/goreman@latest protoc, only if you write gRPC services
The scripts in bin/ install the other tools (air, mockery, nilaway, protoc plugins) the first time you run them.
wget -qO- https://raw.githubusercontent.com/anonychun/bibit/refs/heads/main/new.sh | bash -s github.com/anonychun/billing-apiThe script clones Bibit, replaces the module path github.com/anonychun/bibit with the name you pass, renames the # Bibit heading in README.md and AGENTS.md, copies .env.sample to .env, and writes the result to a directory named after the last path segment (billing-api in the example).
Then:
cd billing-api
# fill in .env
./bin/db setup
./bin/devAGENTS.md lists every bin/ command and the rules for each layer: component shape, entity, migration, repository, usecase, errors, handlers, middleware, jobs, file storage, tests, and commits. Coding agents read it automatically, and it is the reference for people too.
cmd/
db/ database CLI
generate/ code generators
server/ HTTP + gRPC servers
worker/ background job worker
internal/
api/ response envelope, API errors, validation errors
bootstrap/ dependency injector and process lifecycle
client/ clients for other systems (River job queue)
config/ environment configuration
consts/ shared constants and API errors
current/ request-scoped values on context.Context
db/ database connections, migrator, seeder
dto/ response shapes shared across usecases
entity/ database models
job/ background jobs, one package per job
lib/ small helpers
middleware/ HTTP middleware, one package per middleware
o11y/ logging, metrics, tracing
repository/ data access, one package per table
server/ HTTP server, gRPC server, routes
storage/ file storage (S3)
usecase/ business logic and handlers, one package per feature
validation/ struct validation
worker/ worker process and job registration
migrations/ SQL and Go migrations (embedded in the binary)
proto/ protobuf definitions
pkg/pb/ generated protobuf code
public/ static files served at /
Every command calls o11y.Setup at startup:
- Logs go to stdout as JSON through
log/slog. Useslog.Info(...)and friends anywhere. - Metrics use OpenTelemetry with a Prometheus exporter, served at
GET /metrics. The Echo OpenTelemetry middleware records HTTP metrics. - Traces use OpenTelemetry, are sampled at 100%, and go to
OTLP_ENDPOINTover gRPC. The service name is the Go module path.
The Dockerfile builds the db, server, and worker binaries into a Debian slim image. On start, bin/docker-entrypoint runs db create, db migrate, and db seed, then starts both processes from Procfile with goreman. To run one process per container, override the command:
docker run --env-file .env my-image /app/bin/server start
docker run --env-file .env my-image /app/bin/worker startThese files exist to demonstrate the patterns. Delete them, or rewrite them for your domain, once you have your own feature in place:
internal/entity/user.go,internal/entity/user_session.gointernal/repository/user/,internal/repository/user_session/internal/usecase/api/v1/app/auth/internal/middleware/auth/internal/job/hello/, and its registration ininternal/worker/worker.gointernal/consts/cookie.goand the auth errors ininternal/consts/error.go- The auth handler field in
internal/server/http_server.goand the/api/v1/approutes ininternal/server/route.go - The
usersanduser_sessionstables inmigrations/20010114000000_init.sql current.Userininternal/current/current.go, if you drop the auth middleware
Keep the rest: health (backs /up and the gRPC health service), the root repository package (transactions), attachment, storage, and the infrastructure packages.