A robust Go API template built following Clean Architecture principles and Domain-Driven Design (DDD) patterns. This project uses Docker-first development for consistency across all environments.
- Docker & Docker Compose - Install Docker
- Task (Taskfile) - Installation guide
Note: No local Go installation required! All operations run in Docker containers via Task commands.
git clone <repository-url>
cd go-clean-template
task start # One-command setup and start
Access Points:
- API: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger/index.html
- Health Check: http://localhost:8080/health
Service | Port | Description |
---|---|---|
API | 8080 | Go application with live reload |
PostgreSQL | 5432 | Primary database |
Redis | 6379 | Caching layer |
# Development (Docker-first)
task start # Setup and start development
task dev # Start with live reload
task check # Run quality checks (format, lint, test)
task health # Check service health
task clean # Clean everything
# Code Quality (in Docker)
task fmt # Format Go code
task lint # Lint code with golangci-lint
task test # Run tests
task test-coverage # Run with coverage
# Dependencies (in Docker)
task deps # Download and tidy dependencies
task deps-update # Update dependencies
# Documentation
task swag-gen # Generate Swagger docs
For advanced Docker operations, see DOCKER.md.
Current:
- Go 1.24 with Chi Router
- PostgreSQL 15 + Redis 7 (configured)
- Viper (config) + Zap (logging)
- Swagger/OpenAPI documentation
- Docker & Docker Compose (Docker-first development)
- Task (Taskfile.yml) for all operations
- Air for live reload in containers
- Health monitoring endpoints
Planned:
- Ent ORM, JWT Authentication, Business Logic Implementation
go-clean-template/
βββ cmd/api/ # Application entry point
βββ internal/
β βββ application/ # Use cases and business logic
β βββ domain/ # Domain entities and business rules
β βββ infrastructure/ # External concerns (database, config, logging)
β βββ presentation/ # HTTP handlers, routes, API documentation
β βββ shared/ # Shared utilities (errors, response)
βββ config/ # Configuration files
βββ docs/ # API documentation
βββ build/ # Dockerfiles
βββ deployments/ # Docker Compose & scripts
βββ Taskfile.yml # Task automation
This project implements Clean Architecture with clear separation of concerns:
Core business logic - Entities, value objects, business rules. No external dependencies.
domain/
βββ example/ # Domain-specific entities
βββ shared/ # Common domain concepts
β βββ events/ # Domain events
β βββ values/ # Shared value objects
β βββ interfaces/ # Domain contracts
βββ services/ # Domain services
Use cases - Orchestrates domain objects, depends only on domain layer.
application/
βββ example/ # Application services
β βββ commands/ # Command handlers
β βββ queries/ # Query handlers
β βββ dto/ # Application DTOs
β βββ interfaces/ # Repository contracts
βββ common/ # Shared application logic
βββ services/ # Application services
HTTP interface - Handlers, routes, middleware, DTOs, Swagger documentation.
presentation/http/
βββ handlers/ # HTTP request handlers
βββ middleware/ # CORS, auth, logging
βββ dto/ # Request/response structures
βββ routes.go # API endpoints
βββ server.go # HTTP server setup
External concerns - Database, config, logging, authentication implementations.
infrastructure/
βββ auth/ # JWT, password hashing
βββ config/ # Environment, YAML config
βββ logger/ # Structured logging
βββ persistence/ # Database, repositories
Common utilities - Enhanced error handling with chaining, response formatting, validation.
shared/
βββ errors/ # Enhanced error handling with cause chaining
βββ response/ # HTTP response utilities with error chain support
βββ validation/ # Input validation helpers
- Dependency Rule: Outer layers depend on inner layers
- Framework Independence: Business logic isolated from frameworks
- Testability: Each layer independently testable
- Single Responsibility: Each layer has one clear purpose
HTTP β Presentation β Application β Domain
β β β β
Response β Infrastructure β Infrastructure
Endpoint | Purpose |
---|---|
/health |
Detailed health with dependencies |
/heartbeat |
Simple heartbeat |
/live |
Container liveness probe |
/ready |
Container readiness probe |
/system |
System information |
Swagger UI: http://localhost:8080/swagger/index.html
Currently Available Endpoints:
- Health monitoring (
/health
,/live
,/ready
) - Heartbeat (
/heartbeat
)
Planned: Full RESTful API implementation following clean architecture patterns.
Uses hybrid configuration system with clear separation of concerns:
- Environment Variables - Runtime, sensitive, environment-specific
- YAML Configuration (
config/config.yaml
) - Static application behavior - Code Defaults - Essential fallbacks for critical services
.env.example
β.env
- Environment-specific and sensitive dataconfig/config.yaml
- Static configurations (CORS, rate limiting, Swagger, metrics)docker-compose.yml
- Development environment setup
- Security: Sensitive data only in environment variables
- Flexibility: Easy environment-specific overrides
- Maintainability: Static configs in version control
- Deployment: Simple
.env
file changes for different environments
task setup
automatically copies .env.example
to .env
and downloads dependencies.
task test # Run tests
task test-coverage # Run with coverage
All tests run in Docker for consistency across environments.
The project uses Air for live reload during development, automatically rebuilding and restarting the application when code changes are detected.
- Watches:
cmd/
,internal/
,config/
,docs/
directories - File Types:
.go
,.yaml
,.yml
,.json
files - Excludes: Test files, temporary files, build artifacts
- Build Target:
./tmp/main
(excluded from Docker context)
task dev # Start with live reload (Docker-first approach)
Benefits: Instant feedback during development, no manual restarts needed, fully integrated with Docker development workflow. Air runs inside the development container, ensuring consistency across all environments.
task setup # Copy .env.example to .env
# Edit .env with production values
task start # Start all services
task health # Verify services
For production, update .env
with secure values (JWT_SECRET, passwords, etc.).
- Install Docker and Task
- Run
task setup
andtask dev
- Make changes (live reload enabled)
- Run
task check
before committing - Submit pull request
- DOCKER.md - Advanced Docker operations, troubleshooting, and deployment
Md. Erfanul Islam Bhuiyan - Software Engineer