Golang Microservice Boilerplate using PSQL, Docker and Cucumber, API REST. Gin Go and GORM with pagination and implementation of a Clean Architecture.
Golang Microservice Boilerplate using PSQL, Docker and Cucumber, API REST. Gin Go and GORM with pagination and implementation of a Clean Architecture.
A production-ready microservices boilerplate built with Go, implementing Clean Architecture principles with comprehensive testing, security, and documentation.
…graph LR
subgraph "Dependencies Point Inward"
A[Infrastructure] --> B[Application]
B --> C[Domain]
A --> C
end
subgraph "Domain is Independent"
C --> D[No External Dependencies]
end# Clone the repository
git clone https://github.com/gbrayhan/microservices-go
cd microservices-go
# Copy environment file
cp .env.example .env
# Start services
docker-compose up --build -d# Check if services are running
docker-compose ps
# Test the API
curl http://localhost:8080/v1/healthmicroservices-go/
├── src/
│ ├── domain/ # Domain Layer (Entities & Business Rules)
│ ├── application/ # Application Layer (Use Cases)
│ └── infrastructure/ # Infrastructure Layer
│ ├── di/ # Dependency Injection
│ ├── repository/ # Data Access Layer
│ ├── rest/ # HTTP Controllers
│ ├── security/ # JWT & Security
│ └── logger/ # Structured Logging
├── Test/
│ └── integration/ # Integration Tests
├── docs/ # Documentation
└── docker-compose.yml # Development Environment# Run the application
go run main.go
# Run tests
go test ./...
# Run tests with coverage
./coverage.sh
# Run integration tests
./scripts/run-integration-test.bash
# Lint code
golangci-lint run ./...
# Security scan
trivy fs .…stateDiagram-v2
[*] --> Authenticated
Authenticated --> TokenExpired: Access token expires
TokenExpired --> Refreshing: Send refresh token
Refreshing --> Authenticated: New tokens received
Refreshing --> Unauthorized: Invalid refresh token
Unauthorized --> [*]: Re-login required
Authenticated --> [*]: LogoutPOST /v1/auth/login - User loginPOST /v1/auth/access-token - Refresh access tokenGET /v1/user - Get all usersPOST /v1/user - Create userGET /v1/user/:id - Get user by IDPUT /v1/user/:id - Update userDELETE /v1/user/:id - Delete userGET /v1/user/search - Search users with paginationGET /v1/user/search-property - Search by specific propertyGET /v1/medicine - Get all medicinesPOST /v1/medicine - Create medicineGET /v1/medicine/:id - Get medicine by IDPUT /v1/medicine/:id - Update medicineDELETE /v1/medicine/:id - Delete medicineGET /v1/medicine/search - Search medicines with paginationGET /v1/medicine/search-property - Search by specific propertygraph TB
subgraph "Test Pyramid"
E2E[End-to-End Tests
Cucumber Integration]
Integration[Integration Tests
API Testing]
Unit[Unit Tests
Use Cases & Controllers]
end
E2E --> Integration
Integration --> Unit# Run all tests with coverage
./coverage.sh
# Expected coverage: ≥ 80%{
"level": "info",
"timestamp": "2024-01-01T00:00:00Z",
"message": "User login successful",
"user_id": 123,
"email": "[email protected]",
"correlation_id": "req-123-456",
"service": "auth-service"
}# Health endpoint
GET /v1/health
# Response
{
"status": "healthy",
"timestamp": "2024-01-01T00:00:00Z",
"version": "1.0.0"
}# Build production image
docker build -t microservices-go .
# Run with environment variables
docker run -p 8080:8080 \
-e DB_HOST=postgres \
-e DB_PORT=5432 \
-e JWT_ACCESS_SECRET_KEY=your_secret \
microservices-go# Server Configuration
SERVER_PORT=8080
GO_ENV=production
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=password
DB_NAME=microservices_go
# JWT Configuration
JWT_ACCESS_SECRET_KEY=your_access_secret
JWT_REFRESH_SECRET_KEY=your_refresh_secret
JWT_ACCESS_TIME_MINUTE=60
JWT_REFRESH_TIME_HOUR=24git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
No open issues yet, or sync has not completed.