Docker Compose Environment
π³ Local development and simple deployment environment using Docker Compose orchestration.
π Features
- Go Fiber API Gateway - High-performance HTTP framework with built-in middleware
- Redis Cluster - Master-slave replication with Redis Sentinel for high availability
- MySQL Database - Relational database with GORM ORM integration
- Prometheus - Metrics collection and monitoring
- Grafana - Data visualization and dashboards with automatic datasource implementation
- Redis Insight - Redis GUI for database management
- Docker Compose - Complete container orchestration
- Makefile - Simplified development commands
π Prerequisites
- Docker and Docker Compose
- Go 1.24.4 or higher
- Git
ποΈ Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β API Gateway β β Grafana β β Prometheus β
β (Go Fiber) β β (Port 3000) β β (Port 9090) β
β (Port 8000) β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Redis Cluster β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β Master β β Slave β βSentinel1β βSentinel2β β
β β (6379) β β (6379) β β (26379) β β (26380) β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β β β
β βββββββββββ βββββββββββ β
β βSentinel3β βRedis β β
β β(26381) β βInsight β β
β βββββββββββ β(5540) β β
ββββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β MySQL Database β
β (Port 3306) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quick Start
-
Clone the repository
git clone https://github.com/XDcobra/gofiber-starter-stack.git
cd gofiber-starter-stack
-
Initialize Go module (if needed)
cd services/api-gateway
go mod init github.com/XDcobra/gofiber-starter-stack
go mod tidy
cd ../..
-
Create environment file
cp .env.example .env
# Edit .env with your configuration
-
Start all services
make docker-start
-
Access the services
-
For Production: Review Security settings
- Please read section π Authentication & Security and change the passwords (and usernames) within the .env file, as well as reviewing the exposed service ports
π Project Structure
services/
βββ api-gateway/ # Go Fiber API Gateway
β βββ controller/ # HTTP controllers
β β βββ DummyController/ # Example controller
β β βββ MySQLController/ # MySQL operations
β β βββ RedisController/ # Redis operations
β βββ database/ # Database connections
β β βββ MySQL/ # MySQL connection & models
β β βββ Redis/ # Redis connection
β βββ model/ # Data models
β βββ prometheus/ # Metrics configuration
β βββ router/ # Route definitions
β βββ services/ # Business logic
β βββ Dockerfile # API Gateway container
β βββ go.mod # Go dependencies
β βββ main.go # Application entry point
βββ grafana/ # Grafana configuration
βββ mysql/ # MySQL initialization
βββ prometheus/ # Prometheus configuration
βββ dummy_service*/ # Example microservices that you can add in the future
π§ API Endpoints
Health Check
Redis Operations
GET /redis/ping - Redis connection test
GET /redis/get - Get value from Redis
POST /redis/post - Set value in Redis
MySQL Operations
GET /mysql/get/:id - Get record by ID
POST /mysql/post - Create new record
Prometheus Metrics
GET /metrics - Get the raw prometheus exported data
π Authentication & Security
Password Protected Endpoints
| Service |
Endpoint |
Authentication Type |
Environment Variable |
Description |
| Prometheus |
http://localhost:9090 |
Basic Auth |
PROM_USER / PROM_PASS |
Metrics collection dashboard |
| Grafana |
http://localhost:3000 |
Admin Login |
GF_SECURITY_ADMIN_USER / GF_SECURITY_ADMIN_PASSWORD |
Data visualization dashboard |
| Redis Insight |
http://localhost:5540 |
None |
- |
Redis GUI (no auth by default) |
| API Gateway |
http://localhost:8000/metrics |
Basic Auth |
METRICS_USER / METRICS_PASS |
Exported metrics for prometheus |
| MySQL |
localhost:3306 |
Database Auth |
MYSQL_ROOT_PASSWORD / MYSQL_USER / MYSQL_PASSWORD |
Database connection |
Environment Variables for Authentication
# Golang API Gateway metrics endpoint
METRICS_USER='metrics_user'
METRICS_PASS='metrics_password'
# Prometheus Authentication
PROM_USER='prometheus_user'
PROM_PASS='prometheus_password'
# Grafana Authentication
GF_SECURITY_ADMIN_USER='admin'
GF_SECURITY_ADMIN_PASSWORD='password'
# MySQL Authentication
MYSQL_ROOT_PASSWORD='root_password'
MYSQL_USER='user'
MYSQL_PASSWORD='password'
# MySQL Database name
MYSQL_DATABASE='example_db'
Default Credentials
- Prometheus: Use the values from
PROM_USER and PROM_PASS in your .env file
- Grafana:
- Username:
admin
- Password: Value of
GF_SECURITY_ADMIN_PASSWORD in your .env file
- MySQL:
- Root Password: Value of
MYSQL_ROOT_PASSWORD in your .env file
- User Password: Value of
MYSQL_PASSWORD in your .env file
Security Notes
- API Gateway endpoints are currently public - implement authentication middleware for production
- Redis Insight has no authentication by default - consider adding reverse proxy with auth
- Prometheus and Grafana use basic authentication - ensure strong passwords in production
- MySQL uses database-level authentication - keep credentials secure
- Docker exposes all service ports at the moment - for production builds, consider to only expose the service ports that should be reachable from the outside (e.g. remove redis-sentinel from being reachable from outside as it is not needed normally)
π³ Docker Services
| Service |
Port |
Description |
| API Gateway |
8000 |
Go Fiber application |
| Grafana |
3000 |
Data visualization |
| Prometheus |
9090 |
Metrics collection |
| Redis Master |
6379 |
Redis primary instance |
| Redis Slave |
6379 |
Redis replica |
| Redis Sentinel 1 |
26379 |
Redis sentinel for HA |
| Redis Sentinel 2 |
26380 |
Redis sentinel for HA |
| Redis Sentinel 3 |
26381 |
Redis sentinel for HA |
| Redis Insight |
5540 |
Redis GUI |
| MySQL |
3306 |
Database |
π οΈ Development Commands
# Start all services
make docker-start
# Stop all services
make docker-stop
# Stop and remove containers
make docker-down
# View logs
docker-compose logs -f
# Rebuild specific service
docker-compose build api-gateway
π Monitoring & Observability
Prometheus Metrics
The API Gateway automatically exposes metrics at /metrics endpoint:
- HTTP request duration
- Request count by status code
- Active connections
- Custom business metrics
In case you want to expose more custom metrics, consider to add these into the Gofiber-Prometheus file
Grafana Dashboards
Pre-configured dashboards for:
- API Gateway performance
- Redis cluster health
- MySQL database metrics
- System resource usage
π Redis Cluster Configuration
The Redis setup includes:
- Master-Slave Replication for data redundancy
- Redis Sentinel for automatic failover
- Redis Insight for visual management
- High Availability with automatic master election
ποΈ Database Setup
MySQL
- Automatic schema migration with GORM
- Connection pooling
- Transaction support
- Model auto-generation
Redis
- Connection pooling
- Automatic reconnection
- Sentinel support for HA
- Pub/Sub capabilities
π Production Deployment
- Update environment variables for production
- Configure SSL/TLS certificates
- Set up proper logging and log rotation
- Configure backup strategies for databases
- Set up monitoring alerts in Grafana
- Use external volumes for data persistence
- ServiceAccounts & JWTs for more security instead of BasicAuth