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!
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 | 6380 (host) | Caching layer |
# Development
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
# Testing
task test # Run tests
task test-coverage # Run with coverage
# Dependencies
task deps # Download and tidy dependencies
task deps-update # Update dependencies
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
- 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 - Error handling, response formatting, validation.
- 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:
- Environment variables (
.env
file) - YAML configuration (
config/config.yaml
) - Docker environment (docker-compose.yml)
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.
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