Modular Go backend framework. Clean Architecture + DDD. Echo v5, Viper, gRPC, PostgreSQL, Redis, NATS, Kafka — all managed through a single CLI.
| Tool | Version | Installation |
|---|---|---|
| Go | 1.22+ | go.dev/dl |
| Docker | 24+ | docs.docker.com |
| Docker Compose | v2+ | Included with Docker Desktop |
| Task | 3+ | go install github.com/go-task/task/v3/cmd/task@latest |
| golang-migrate | latest | go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest |
| swag | latest | go install github.com/swaggo/swag/cmd/swag@latest |
Add Go binaries to your PATH. Add to ~/.bashrc or ~/.zshrc:
export PATH="$HOME/go/bin:$PATH"Reload: source ~/.bashrc
cd GoBox
go install ./cmd/goboxOr through Taskfile:
task installTo install into /usr/local/bin:
task install-systemgobox new my-api
cd my-apiThis generates a full project with Clean Architecture:
my-api/
├── cmd/api/main.go # Entry point
├── internal/
│ ├── app/ # Application bootstrap
│ ├── config/ # Viper configuration
│ ├── domain/ # Entities, value objects, repository interfaces
│ ├── usecase/ # Business logic
│ ├── handler/ # HTTP handlers (adapters)
│ ├── repository/ # Database implementations
│ ├── middleware/ # Security middleware
│ ├── module/ # Module interface & registry
│ ├── modules/ # Infrastructure modules
│ └── apperr/ # Centralized error definitions
├── migrations/ # SQL migrations
├── docker/ # Dockerfile, PgBouncer config
├── certs/ # JWT Ed25519 keys (generated)
├── docs/ # Swagger/OpenAPI docs
├── docker-compose.yml # Auto-generated per modules
├── gobox.yml # Project configuration
├── Taskfile.yml # Task runner commands
└── .env.example # Environment variables template
cp .env.example .env
task infra
task devGoBox generates docker-compose.yml dynamically. Only enabled modules have containers — nothing extra runs.
gobox add redis
gobox add nats
gobox add kafka
gobox add grpc
gobox add pgbouncer
gobox add cors
gobox add csrf
gobox add swagger
gobox add authgobox remove redisgobox versiongobox listOutput:
Modules:
* database
* redis
nats
kafka
grpc
cors
csrf
pgbouncer
auth
swagger
* = enabled.
| Module | Description | Container |
|---|---|---|
database |
PostgreSQL 16 via pgx | postgres:16-alpine |
redis |
Redis 7 with password + TLS support | redis:7-alpine |
nats |
NATS 2 messaging | nats:2-alpine |
kafka |
Kafka (KRaft, no Zookeeper) | bitnami/kafka |
grpc |
gRPC server with health check | — |
pgbouncer |
Connection pooler for PostgreSQL | edoburu/pgbouncer |
| Module | Description |
|---|---|
cors |
Cross-Origin Resource Sharing |
csrf |
Cross-Site Request Forgery protection |
| Module | Description |
|---|---|
auth |
JWT authentication with Ed25519 keys, login/refresh endpoints, middleware |
swagger |
Swagger/OpenAPI generation + Scalar UI |
gobox add authThis generates:
internal/handler/auth.go— Login & Refresh token endpointsinternal/middleware/jwt_auth.go— JWT Bearer middlewaremigrations/000001_create_users.up.sql— Users tablecerts/private.pem— Ed25519 private key (signing)certs/public.pem— Ed25519 public key (verification)
| Method | Path | Description |
|---|---|---|
| POST | /auth/login |
Authenticate, returns access + refresh tokens |
| POST | /auth/refresh |
Exchange refresh token for new access token |
import authMw "my-api/internal/middleware"
protected := e.Group("/api", authMw.JWTAuth(publicKey))
protected.GET("/profile", profileHandler)- Algorithm: Ed25519 (EdDSA)
- Access token TTL: 24 hours
- Refresh token TTL: 7 days
gobox add swagger
task swagger- Swagger JSON:
http://localhost:8080/swagger/doc.json - Scalar UI:
http://localhost:8080/scalar
To disable at runtime, set SWAGGER_ENABLED=false in .env.
name: my-api
server:
host: "0.0.0.0"
port: 8080
modules:
- database
- redis
- grpcAll settings are loaded via Viper with environment variable override.
# Server
SERVER_PORT=8080
# PostgreSQL
DATABASE_URL=postgres://gobox:gobox@localhost:5432/mydb?sslmode=disable
DATABASE_TLS=false
# PostgreSQL container
POSTGRES_USER=gobox
POSTGRES_PASSWORD=gobox
POSTGRES_DB=gobox
# PgBouncer
PGBOUNCER_ENABLED=false
PGBOUNCER_PORT=6432
PGBOUNCER_MAX_CONN=1000
PGBOUNCER_POOL_SIZE=25
# Redis
REDIS_URL=localhost:6379
REDIS_PASSWORD=mysecretpassword
REDIS_TLS=false
# NATS
NATS_URL=nats://localhost:4222
# Kafka
KAFKA_BROKERS=localhost:9092
# gRPC
GRPC_PORT=9090
# JWT
JWT_PRIVATE_KEY=certs/private.pem
JWT_PUBLIC_KEY=certs/public.pem
# Swagger
SWAGGER_ENABLED=trueSet in .env:
DATABASE_URL=postgres://gobox:gobox@localhost:5432/mydb?sslmode=verify-full&sslrootcert=/path/to/ca.pem
DATABASE_TLS=trueREDIS_TLS=true
REDIS_PASSWORD=your_redis_passwordThe Redis module will use TLS 1.2+ when REDIS_TLS=true.
docker-compose.yml is auto-generated when you run gobox add or gobox remove. Only enabled modules get containers.
All passwords and ports come from .env:
cp .env.example .env
# Edit passwords in .env
task infragobox add pgbouncerAdds a connection pooler between your app and PostgreSQL. Default pool mode: transaction. Connect your app to port 6432 instead of 5432.
# Run pending migrations
task migrate-up
# Rollback last migration
task migrate-down
# Create new migration
task migrate-create -- create_ordersMigration files go to migrations/ as raw SQL.
| Command | Description |
|---|---|
task dev |
Start API server in development mode |
task build |
Build API binary to bin/api |
task build-cli |
Build GoBox CLI to bin/gobox |
task install |
Install GoBox CLI globally |
task install-system |
Install GoBox CLI to /usr/local/bin/gobox |
task uninstall-system |
Remove GoBox CLI from /usr/local/bin/gobox |
task infra |
Start Docker infrastructure |
task infra-down |
Stop Docker infrastructure |
task migrate-up |
Run database migrations |
task migrate-down |
Rollback last migration |
task migrate-create |
Create new migration file |
task swagger |
Generate Swagger documentation |
task test |
Run all tests |
task lint |
Run golangci-lint |
GitHub Actions workflow: .github/workflows/ci.yml
Pipeline steps:
go mod downloadgolangci-lintgofmtcheckgo vet ./...go test ./...go build ./...
If you rename the default branch or workflow file, update the badge link at the top of this README.
GitHub Actions release workflow: .github/workflows/release.yml
When you push a tag like v0.1.0, GitHub Actions will build gobox for:
- Linux amd64
- Linux arm64
- macOS amd64
- macOS arm64
- Windows amd64
Each artifact is attached to the GitHub Release and embeds version metadata visible through:
gobox versionHandler (HTTP/gRPC) → UseCase (Business Logic) → Repository (Database)
↑ ↑ ↑
Adapters layer Domain layer Adapters layer
Entity structs and repository interfaces. No external dependencies.
type User struct {
ID string
Email string
Password string
CreatedAt time.Time
}
type UserRepository interface {
Create(ctx context.Context, user *User) error
GetByID(ctx context.Context, id string) (*User, error)
}Business logic. Depends only on domain interfaces.
type UserUseCase struct {
repo domain.UserRepository
}
func (uc *UserUseCase) GetByID(ctx context.Context, id string) (*domain.User, error) {
return uc.repo.GetByID(ctx, id)
}HTTP handlers. Calls use cases, returns JSON.
Database implementations of domain repository interfaces.
All application errors are defined in internal/apperr/errors.go:
apperr.ErrNotFound
apperr.ErrUnauthorized
apperr.ErrForbidden
apperr.ErrValidation
apperr.ErrBadRequest
apperr.ErrConflict
apperr.ErrTimeout
apperr.ErrServiceDown
apperr.ErrInvalidToken
apperr.ErrExpiredToken
apperr.ErrDatabaseConnUse in handlers:
if errors.Is(err, apperr.ErrNotFound) {
return c.JSON(404, map[string]string{"error": "not found"})
}// PostgreSQL
dbMod := app.Module("database").(*database.Database)
db := dbMod.DB()
// Redis
redisMod := app.Module("redis").(*redis.Redis)
client := redisMod.Client()
// NATS
natsMod := app.Module("nats").(*nats.NATS)
conn := natsMod.Conn()
// Kafka
kafkaMod := app.Module("kafka").(*kafka.Kafka)
writer := kafkaMod.NewWriter("orders")
reader := kafkaMod.NewReader("orders", "consumer-group")
// gRPC
grpcMod := app.Module("grpc").(*grpc.GRPC)
pb.RegisterMyServiceServer(grpcMod.Server(), &myService{})GET /health returns status of all modules:
{
"status": "ok",
"modules": {
"database": "ok",
"redis": "ok"
}
}| Component | Library | Version |
|---|---|---|
| HTTP Router | Echo | v5.0.4 |
| Configuration | Viper | v1.21.0 |
| Database Driver | pgx | v5.9.1 |
| Redis Client | go-redis | v9.18.0 |
| Messaging | nats.go | v1.49.0 |
| Streaming | kafka-go | v0.4.50 |
| RPC | gRPC | v1.79.3 |
| JWT | golang-jwt | v5.3.1 |
| CLI | Cobra | v1.10.2 |
| Logging | slog | stdlib |