Skip to content

πŸš€ Go REST API starter with JWT auth, PostgreSQL, GORM, Docker hot-reload, Swagger docs, and clean architecture. One-command setup, comprehensive documentation, and TODO tutorial. Perfect for building production APIs quickly or learning Go best practices in web development. Includes tests, CI/CD, and deployment guides.

License

vahiiiid/go-rest-api-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

GRAB Logo

Go REST API Boilerplate

Production-ready in 90 seconds. No headaches, just clean code.

GRAB is a Go boilerplate that doesn't waste your time β€” highly tested, Docker-ready, fully documented, with everything you need.

Go Version codecov CI Docker Go Report Card License: MIT Documentation PRs Welcome GitHub Stars

πŸ“– Full Documentation β€’ πŸš€ Quick Start β€’ ✨ Live Demo


πŸ•’ Why Waste Days on Setup?

You know the pain: Starting a new Go project means days of configuring Docker, wiring up authentication, setting up migrations, writing boilerplate code, and praying your hot-reload actually works.

GRAB changes that.

make quick-start  # ← One command. 90 seconds. You're building features.

This is the real deal. The production-grade boilerplate you wish you had from day one:

βœ… Clean Architecture β€” Handler β†’ Service β†’ Repository (GO industry standard)
βœ… Security & JWT Auth β€” Rate limiting, CORS, input validation built-in
βœ… Database Migrations β€” PostgreSQL with version control & rollback
βœ… Comprehensive Tests β€” Unit + integration with CI/CD pipeline
βœ… Interactive Docs β€” Auto-generated Swagger + Postman collection
βœ… Structured Logging β€” JSON logs with request IDs and tracing
βœ… Structured Error Handling β€” Consistent API errors with codes and details
βœ… Production Docker β€” Multi-stage builds, health checks, optimized images
βœ… Environment-Aware β€” Dev/staging/prod configs + Make automation & more
βœ… Graceful Shutdown β€” Zero-downtime deployments with configurable timeouts
βœ… Hot-Reload (2 seconds!) β€” Powered by Air, not magic

And that's just scratching the surface. Check the full documentation to see everything GRAB offers.

πŸ† Built Following Go Standards

Not some random structure β€” follows official Go project layout + battle-tested community patterns from golang-standards/project-layout. The same architecture used by Gin, GORM, and production Go services.

🎯 Perfect For

  • πŸš€ Shipping Fast β€” Launch MVPs and production APIs in days, not weeks
  • πŸ‘₯ Team Projects β€” Consistent standards everyone understands
  • πŸ—οΈ Scaling Up β€” Architecture that grows with your business
  • πŸ“– Learning Go β€” See how pros structure real-world applications

πŸš€ Quick Start

Get your API running in under 2 minutes:

Prerequisites

πŸ’‘ Want to run without Docker? See the Manual Setup Guide in the documentation.

One-Command Setup ⚑

git clone https://github.com/vahiiiid/go-rest-api-boilerplate.git
cd go-rest-api-boilerplate
make quick-start
Quick Start Demo

πŸŽ‰ Done! Your API is now running at:


✨ See It In Action

Interactive Swagger Documentation

Swagger UI

Open http://localhost:8080/swagger/index.html to explore and test all endpoints interactively.

Or Use Postman

Postman Collection

Import the pre-configured collection from api/postman_collection.json with example requests and tests.

πŸš€ Ready to Build?

  • πŸ“– Development Guide β€” Learn how to add models, routes, and handlers
  • πŸ’‘ TODO List Tutorial β€” Complete step-by-step feature implementation from scratch

πŸ’Ž What Makes GRAB Different?

Not Just Features β€” A Complete Development Experience

Most boilerplates give you code. GRAB gives you a professional development workflow.

πŸ” Authentication That Actually Works

  • JWT-based auth (HS256) β€” Secure, stateless, ready for production
  • Context helpers β€” Type-safe user extraction (no more casting nightmares)
  • Password security β€” Bcrypt hashing with best-practice cost factor
  • Rate limiting β€” Token-bucket protection against abuse built-in

πŸ‘‰ Context Helpers Guide

πŸ—„οΈ Database Setup That Doesn't Fight You

  • PostgreSQL + GORM β€” Production-grade ORM with relationship support

  • golang-migrate β€” Industry-standard migrations with timestamp versioning

  • Complete migration CLI β€” Create, apply, rollback with ease

    make migrate-create NAME=add_posts_table  # Create with timestamp
    make migrate-up                            # Apply all pending
    make migrate-down                          # Rollback last (safe)
    make migrate-down STEPS=3                  # Rollback multiple
    make migrate-status                        # Check current version
    make migrate-goto VERSION=<timestamp>      # Jump to specific version
  • Safety features β€” Confirmation prompts, dirty state detection

  • Transaction support β€” BEGIN/COMMIT wrappers for data integrity

  • Connection pooling β€” Configured for performance out of the box

πŸ‘‰ Migrations Guide

🐳 Docker That Saves Your Sanity

  • 2-second hot-reload β€” Powered by Air, actually works in Docker
  • One command to rule them all β€” make quick-start handles everything
  • Development & production β€” Separate optimized configs
  • Multi-stage builds β€” Tiny production images (~20MB)

πŸ‘‰ Docker Guide

πŸ“š Documentation That Exists (And Helps!)

  • Auto-generated Swagger β€” Interactive API explorer at /swagger/index.html
  • Full documentation site β€” Not just README, real guides at vahiiiid.github.io/go-rest-api-docs
  • Step-by-step tutorials β€” Build a TODO app from scratch
  • Postman collection β€” Import and test immediately

πŸ‘‰ Full Documentation

πŸ§ͺ Tests That Give You Confidence

  • Comprehensive coverage β€” Handlers, services, and repositories all tested
  • In-memory SQLite β€” No external dependencies for tests
  • Table-driven tests β€” Go idiomatic testing patterns
  • CI/CD ready β€” GitHub Actions configured and working

πŸ‘‰ Testing Guide

⚠️ Error Handling That Makes Sense

  • Structured API errors β€” Consistent JSON format with code, message, and details
  • Machine-readable codes β€” NOT_FOUND, VALIDATION_ERROR, etc.
  • Validation details β€” Clear field-level error messages
  • Centralized middleware β€” Single error handler for all endpoints

πŸ‘‰ Error Handling Guide

πŸ—οΈ Architecture That Scales

  • Clean layers β€” Handler β†’ Service β†’ Repository (no shortcuts)
  • Dependency injection β€” Proper DI, easy to mock and test
  • Domain-driven β€” Organize by feature, not by layer
  • Official Go layout β€” Follows golang-standards/project-layout

πŸ‘‰ Development Guide


πŸ› οΈ Development

With Docker (Recommended)

The easiest way to develop with hot-reload and zero setup:

make up        # Start containers with hot-reload
make logs      # View logs
make test      # Run all tests
make lint      # Check code quality
make lint-fix  # Auto-fix linting issues
make down      # Stop containers

What you get:

  • πŸ”₯ Hot-reload β€” Code changes reflect in ~2 seconds (powered by Air)
  • πŸ“¦ Volume mounts β€” Edit code in your IDE, runs in container
  • πŸ—„οΈ PostgreSQL β€” Database on internal Docker network
  • πŸ“š All tools pre-installed β€” No Go installation needed on host

Database Migrations

Production-grade migrations using golang-migrate:

make migrate-create NAME=add_todos_table  # Create new migration
make migrate-up                            # Apply all pending
make migrate-down                          # Rollback last migration
make migrate-status                        # Check current version

For long-running migrations:

go run cmd/migrate/main.go up --timeout=30m --lock-timeout=1m

All environments use SQL migrations for consistency and safety.

πŸ‘‰ Complete Migration Guide

Without Docker

Want to run natively? You'll need Go 1.24+ installed.

make build-binary    # Build binary to bin/server
make run-binary      # Build and run (requires PostgreSQL on localhost)

πŸ‘‰ Full Setup Guide for native development


🚒 Deployment

Production-Ready From Day One

GRAB includes optimized production builds:

make docker-up-prod  # Start production containers

What's included:

  • βœ… Multi-stage Docker builds (minimal image size)
  • βœ… Health check endpoints
  • βœ… Environment-based configuration
  • βœ… No development dependencies
  • βœ… Production logging

Deploy Anywhere

Ready for:

  • AWS ECS/Fargate β€” Container orchestration
  • Google Cloud Run β€” Serverless containers
  • DigitalOcean App Platform β€” Platform-as-a-service
  • Kubernetes β€” Self-managed orchestration
  • Any VPS β€” Using Docker Compose

πŸ‘‰ Deployment Guide for step-by-step instructions


πŸŽƒ Hacktoberfest 2025

Hacktoberfest

We're participating in Hacktoberfest 2025! πŸš€

We welcome contributions from developers of all skill levels! Pick up any open issues labeled hacktoberfest or good first issue, fork the repository, make your changes, and submit a pull request. Whether it's bug fixes, new features, documentation improvements, or test enhancements - every contribution counts! πŸŽ‰


πŸ“– Documentation

🌐 Full Documentation Site

πŸ“š Read the Docs β†’

Complete guides covering everything:

🀝 Contributing to Documentation

Documentation lives in a separate repository. To contribute:

  1. Visit github.com/vahiiiid/go-rest-api-docs
  2. Follow the contributing guidelines
  3. Submit pull requests for improvements

For code contributions, see CONTRIBUTING.md


🀝 Contributing

We ❀️ contributions! See CONTRIBUTING.md for:

  • Code style guidelines
  • Pull request process
  • Testing requirements
  • Commit conventions

Quick Start

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/amazing-feature)
  3. Make your changes
  4. Run tests and linter (make lint-fix && make lint && make test)
  5. Commit your changes (git commit -m 'feat: add amazing feature')
  6. Push to the branch (git push origin feat/amazing-feature)
  7. Open a Pull Request

πŸ™ Built With Amazing Tools

  • Gin β€” Fast HTTP web framework
  • GORM β€” Developer-friendly ORM
  • golang-migrate β€” Database migration toolkit
  • Viper β€” Configuration management
  • golang-jwt β€” JWT implementation
  • swaggo β€” Swagger documentation generator
  • Air β€” Hot-reload for development

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ’¬ Support & Community


Made with ❀️ for the Go community

⭐ Star β€’ πŸ“– Docs β€’ πŸ› Issues β€’ πŸ’¬ Discussions

About

πŸš€ Go REST API starter with JWT auth, PostgreSQL, GORM, Docker hot-reload, Swagger docs, and clean architecture. One-command setup, comprehensive documentation, and TODO tutorial. Perfect for building production APIs quickly or learning Go best practices in web development. Includes tests, CI/CD, and deployment guides.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 14