This is a Go template of clean architecture to ease and boost up a backend development with up to date libraries utilizing clean architecture as design.
| Name | Used for |
|---|---|
| Go | for backend application |
| Docker and docker-compose | for containers |
| goimports | for formatting source code |
| golangci-lint | for linting source code |
This app has three containers.
apito run api servertaskto run taskpostgresfor database
ββββββββββββββββββββββββββββββββββββββββββββββ
β Docker Compose Project β
β β
β ββββββββββββββββ ββββββββββββββββββ β
β β API β β Task-Runner β β
β β (HTTP) β β (CLI Tasks) β β
β βββββββββ¬βββββββ βββββββββ¬βββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββββ β
β β PostgreSQL DB β β
β β (go_clean_starter DB) β β
β ββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββ
- Go: Primary language for high performance, simplicity, and strong concurrency support
- Echo: Fast and lightweight HTTP web framework with clean routing and rich middleware support
- PostgreSQL: Reliable database with advanced features like JSONB, full-text search, and strong consistency
- sqlc: Generates type-safe Go code from raw SQL queries for compile-time safety and better performance
- golang-migrate: Handles database schema migrations with version control, locking, and rollback support
- oapi-codegen: Generates Go structs and types from OpenAPI specifications for type-safe API development
- Wire: Compile-time dependency injection for clean, type-safe, and maintainable object initialization
- Air: Hot reload tool for fast development cycles with automatic rebuilds on file changes
- Docker & Docker Compose: Containerization for consistent development and deployment environments
go-clean-starter
βββ builder
β βββ dependency.go
β βββ wire.go # manually written wire code
β βββ wire_gen.go # wire code auto generated by `wire.go`
βββ cmd
β βββ migration.go # command to run migration
β βββ serve.go # command to run API server
β βββ task.go # commands to run tasks (currently only one task is defined here)
βββ config
βββ domain # domain models
βββ go.sum
βββ internal
β βββ http # http layer
β β βββ base
β β βββ handler
β β β βββ errors.go
β β β βββ openapi_types.gen.go # auto generated Go structs by doc/api.yaml
β β β βββ user
β β βββ middleware
β β βββ server.go
β βββ repository # data access layer
β β βββ item
β β βββ user
β β βββ transaction.go
β βββ service # business logic layer
β β βββ user
β βββ sqlc # sqlc input & output
β β βββ query
β β β βββ items.sql
β β β βββ users.sql
β β βββ db.go
β β βββ items.sql.go
β β βββ models.go
β β βββ users.sql.go
β βββ task # task program such as job, batch, etc...
β βββ item
β βββ data
β β βββ item.csv
β βββ item.go
β βββ usecase.go
βββ main.go
βββ migration
β βββ migrate.go
β βββ sql # migration sql files
βββ pkg # pkg is empty now. add packages that can be imported by other projects
βββ README.md
βββ WHY.md # document to explain why this tech stack and tech specifications are choosen
βββ docker-compose.test.yaml
βββ docker-compose.yaml
βββ sqlc.yaml # configuration of sqlc- create
.envby copying.env.sample
cp .env.sample .env- run
make buildto build Docker images
make build- run
make upto create and run Docker containers by docker-compose
make upπ‘ This project uses air, which is Go hot reload. Hot reload helps us to develop faster.
- run
make testto testmake testwill create a test environment using the test specific docker-compose.test.yaml with the same Dockerfile as development. Thus safety of test environment is assured as it's separated from local environment for development.
make testOnce the server is running, you can interact with the API:
π Complete API documentation is available in api.yaml - OpenAPI 3.1 specification with all endpoints, schemas, and examples.
curl http://localhost:8080/healthread CONTRIUTING.md to contribute to this project.