A professional Go backend using Gin, GORM, Redis, and Swagger designed for fintech-grade applications.
Features a clean architecture with Handler → Service → Repository → Model layers, CLI commands for migrations, seeding, and running the server, plus auto-generated Swagger API docs.
- RESTful API using Gin
- GORM ORM with auto-migrations and seed data
- Redis caching layer for high performance
- Structured logging using Zap with request IDs
- Versioned API routes (
/api/v1/...) - CLI commands for DB migration, seeding, and running server
- Auto-generated Swagger / OpenAPI documentation
- Go 1.21+
- Gin Web Framework
- GORM ORM (Postgres / MySQL / SQLite)
- Redis
- Zap Logger
- Swaggo for Swagger Documentation
sudo apt update
sudo apt upgrade -y
wget https://go.dev/dl/go1.21.2.linux-amd64.tar.gz # You can change version
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.21.2.linux-amd64.tar.gz
nano ~/.profile
# Go environment
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bincmd/
├─ api/ # HTTP server entrypoint
│ └─ main.go
└─ cli/
├─ main.go # CLI commands for migrate, seed, run
└─ create_db.go # CLI commands for create db
internal/
├─ config/ # Environment / config loader
├─ observability/ # Logger + request ID middleware
├─ server/ # Gin engine
├─ routes/ # Route registration
├─ handler/ # HTTP handlers (controllers)
├─ service/ # Business logic
├─ repository/ # GORM models + DB queries
├─ cache/ # Redis client wrapper
├─ model/ # Pure data structures (optional)
├─ services/ # Business Logic
└─ middleware/ # Middleware
APP_ENV=local
APP_PORT=8080
LOG_LEVEL=info
NODE_ENV=development
# Security
API_KEY=local-dev-key
# Database (optional)
DB_HOST=localhost
DB_PORT=5433
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=app
DB_LOG_MODE=false
# Cache
REDIS_ADDR=localhost:6379
go mod tidyThis step is optional if your database already exists. You can create the database manually:
-- PostgreSQL example
CREATE DATABASE dbname;Or using a CLI command if implemented
go run ./cmd/api/main.go create-dbTo create tables based on your GORM models
go run ./cmd/api/main.go migrateOr, if AUTO_MIGRATE=true in .env, migrations will run automatically when starting the server.
Populate your database with initial test data
go run ./cmd/api/main.go seedgo run ./cmd/api/main.go runServer will start at:
http://localhost:8080