Version: 1.0.0
Team Training Presentation
| Software | Version | Installation |
|---|---|---|
| Go | 1.19+ (1.21.0 recommended) | Install Guide |
| Docker | 27+ | Docker Docs |
| Docker Compose | v2+ | Install Guide |
| Make | Latest | sudo apt install make |
| MySQL | 5.7+ | Via Docker (recommended) |
| Git | Latest | sudo apt install git |
go version # Should show 1.19+
docker --version # Should show Docker 27+
docker compose version # Should show v2.x
make --version # Should show make version
VS Code, GoLand, or any Go IDE
MySQL Workbench, DBeaver, or TablePlus
Postman, Insomnia, or curl
Git (already installed)
# Clone the repository
git clone <repository-url>
cd go-api
# Verify you're on the correct branch
git branch
# If needed, switch to development branch
git checkout release
go-api/
├── cmd/ # Application entry points
├── config/ # Configuration management
├── internal/ # Private application code
│ ├── api/ # API handlers & routes
│ ├── domain/ # Business logic (DDD)
│ ├── model/ # Data models
│ └── middleware/ # HTTP middleware
├── database/ # Migrations & seeders
├── docker/ # Docker configurations
└── tests/ # Test files
# Automated setup with interactive prompts
./scripts/setup-env.sh
This script will:
.env file# 1. Copy the example file
cp .env.example .env
# 2. Edit with your preferred editor
nano .env
# or
code .env
App Configuration:
ENVIRONMENT=local
DOCKER_NETWORK_MODE=bridge
PORT=8085
HOST=0.0.0.0
Database Configuration:
DB_HOST=classera_db
DB_PORT=3306
DB_USER=your_database_user
DB_PASSWORD=your_secure_password
DB_NAME=classera_g2
DB_DRIVER=mysql
DB_MAX_IDLE_CONNS=10
DB_MAX_OPEN_CONNS=100
# JWT Configuration
JWT_SECRET=your-secret-key
JWT_PASSPHRASE=your-passphrase
JWT_ENCRYPT_METHOD=AES-128-CBC
JWT_IV=1122334455667788
# Security Settings
SECURITY_IV=your_security_iv
SECURITY_PASSPHRASE=your_security_passphrase
SECURITY_HASH_STRING=your_hash_string
SECURITY_SALT=your_salt
SECURITY_CIPHER_SEED=your_cipher_seed
SECURITY_KEY=your_security_key
SECURITY_ENCRYPTION_METHOD=your_encryption_method
SECURITY_SUFFIX=your_suffix
TELEMETRY_ENABLED=true
TELEMETRY_SERVICE_NAME=golang-blueprint
TELEMETRY_SERVICE_VERSION=1.0.0
TELEMETRY_TRACING_ENABLED=true
JAEGER_ENDPOINT=localhost:4318
# Start only the database container
docker-compose -f docker-compose.local.yml up -d db
# Verify database is running
docker ps | grep db
# Start MySQL service
sudo systemctl start mysql
# Create database
mysql -u root -p
CREATE DATABASE golang_blueprint;
EXIT;
# Test database connection
mysql -h localhost -P 3306 -u root -p -e "SELECT 1;"
# Build the CLI tool
make build-cli
# Create a new migration
./bin/cli migrate create create_users_table
# Run all migrations
./bin/cli migrate up
# Check migration status
./bin/cli migrate status
# Run migrations (requires Docker container)
make migrate
# Create new migration
make migrate-create name=create_products
# Check status
make migrate-status
# Seed all tables
make seed
# Seed specific table
make seed-table table=users
# Check seeder status
make seed-status
# Force re-run all seeders
make seed-force
# Start all services (app, database, monitoring)
make run-app-local
# This may take time on first run due to DB dump import
classera_db)# View application logs
docker-compose -f docker-compose.local.yml logs -f app
# View database logs
docker-compose -f docker-compose.local.yml logs -f db
networks:
api-30_classera-network:
name: api-30_classera-network
external: true
services:
classera-web:
# ... other config
networks:
- api-30_classera-network
In your frontend application's .env file:
# Database Configuration
DB_HOST=classera_db
DB_PORT=3306
DB_USER=MrRDS
DB_PASSWORD=C1assnaPr0dD
DB_NAME=classera_g2
classera_db as DB_HOST (Docker service name)api-30_classera-network# Check if both containers are on same network
docker network inspect api-30_classera-network
# Test database connection from frontend container
docker exec -it classera-web-container mysql -h classera_db -u MrRDS -p
# Health check endpoint
curl http://localhost:8085/health
# Or visit in browser
http://localhost:8085/health
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00Z"
}
| Service | URL | Description |
|---|---|---|
| API | http://localhost:8085 | Main API endpoint |
| Swagger | http://localhost:8085/swagger/index.html | API Documentation |
| Health | http://localhost:8085/health | Health check |
| Metrics | http://localhost:8085/metrics | Prometheus metrics |
make tunnel-stg-up
make tunnel-stg-down
make tunnel-me-up
make tunnel-me-down
make tunnel-oman-up
make tunnel-oman-down
make tunnel-pk-up
make tunnel-pk-down
Create environment file for the environment you want to connect to:
# For staging
cp .env.example .env.stg
# For Middle East production
cp .env.example .env.me
# For Oman production
cp .env.example .env.oman
# For Pakistan production
cp .env.example .env.pk
Edit the environment file and add:
SSH_HOST=your-server-ip
REMOTE_DB_HOST=10.0.0.5
REMOTE_DB_PORT=3306
LOCAL_TUNNEL_PORT=3307
⚠️ Important: Use different LOCAL_TUNNEL_PORT for each environment!
# For staging
make tunnel-stg-up
# For Middle East production
make tunnel-me-up
# For Oman production
make tunnel-oman-up
# For Pakistan production
make tunnel-pk-up
Update your local .env to use the tunnel:
DB_HOST=localhost
DB_PORT=3307 # Your LOCAL_TUNNEL_PORT
DB_USER=MrRDS
DB_PASSWORD=C1assnaPr0dD
DB_NAME=classera_g2
# Connect via tunnel
mysql -h localhost -P 3307 -u MrRDS -p
# Or use your application
make run-app-local
# Check if tunnel is running
ps aux | grep "ssh -N -f -L"
# Test connection
mysql -h localhost -P 3307 -u MrRDS -p -e "SELECT 1;"
# Stop specific tunnel
make tunnel-stg-down
make tunnel-me-down
# Stop all tunnels
make tunnel-all-down
# Manual command format
ssh -N -f -L {local_port}:{remote_db_host}:{remote_db_port} ubuntu@{server_ip}
# Example
ssh -N -f -L 3307:10.0.0.5:3306 [email protected]
# Stop manual tunnel
pkill -f "ssh -N -f -L 3307:10.0.0.5:3306"
Central Monitoring Hub:
| Service | URL | Credentials |
|---|---|---|
| Prometheus | http://localhost:9090 | admin/{{nginx/auth}} |
| Grafana | http://localhost:3000 | admin/admin |
| Jaeger | http://localhost:16686 | admin/{{nginx/auth}} |
| Metrics API | http://localhost:8085/metrics | admin/{{nginx/auth}} |
1. Start Your Day:
# Pull latest changes
git pull origin release
# Start services
docker-compose -f docker-compose.local.yml up -d
# Check application status
curl http://localhost:8085/health
2. Create New Feature:
# Create migration
make migrate-create name=add_feature_table
# Edit migration file
# database/migrations/YYYYMMDDHHMMSS_add_feature_table.sql
# Run migration
make migrate
# Generate code (if needed)
go run scripts/generate.go -name product -type model
Generate Complete Stack (Recommended):
# Generate model + domain + handler (full stack)
go run scripts/generate.go -name product -type model
This generates:
internal/model/product.go - Data modelinternal/domain/product/repository.go - Repository interface & implementationinternal/domain/product/service.go - Service interface & implementationinternal/api/v1/handler/product/product_handler.go - HTTP handlers (Echo)internal/api/v1/handler/product/product_routes.go - Route registrationtmp/ directory# Generate domain layer only (repository + service)
go run scripts/generate.go -name product -type domain
# Generate handler only
go run scripts/generate.go -name product -type handler
# Generate seeder
go run scripts/generate.go -name product -type seeder
make test
make test-unit
make test-integration
make test-coverage
The API uses URL versioning:
/api/v1/* (Stable)/api/v2/* (Beta)# Health check
GET /api/v1/health
# Authentication
POST /api/v1/auth/login
POST /api/v1/auth/register
# Courses
GET /api/v1/courses
GET /api/v1/courses/:id
POST /api/v1/courses
After making API changes:
make swagger
Then visit:
make migratemake migrate-create name=Xmake seedmake swaggermake testmake run-app-localmake stop-app-localmake metricsmake prometheusmake telemetry-status# Check if MySQL is running
docker ps | grep db
# Check database credentials
cat .env | grep DB_
# Find process using port
lsof -i :8085
# Kill the process
kill -9 <PID>
# Check status
make migrate-status
# Rollback
make migrate-down
env.local.example to .envdocker-compose up -d dbmake migratemake seedmake run-app-localcurl http://localhost:8085/health