services/

directory
v0.0.0-...-f03ab3a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2025 License: MIT

README ΒΆ

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

  1. Clone the repository

    git clone https://github.com/XDcobra/gofiber-starter-stack.git
    cd gofiber-starter-stack
    
  2. Initialize Go module (if needed)

    cd services/api-gateway
    go mod init github.com/XDcobra/gofiber-starter-stack
    go mod tidy
    cd ../..
    
  3. Create environment file

    cp .env.example .env
    # Edit .env with your configuration
    
  4. Start all services

    make docker-start
    
  5. Access the services

  6. For Production: Review Security settings


πŸ“ 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
  • GET / - API 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

  1. Update environment variables for production
  2. Configure SSL/TLS certificates
  3. Set up proper logging and log rotation
  4. Configure backup strategies for databases
  5. Set up monitoring alerts in Grafana
  6. Use external volumes for data persistence
  7. ServiceAccounts & JWTs for more security instead of BasicAuth

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL