๐ go-rest-api-boilerplate - Awesome Go Library for Miscellaneous

AI-friendly, production-ready Go REST API boilerplate with clean architecture, JWT authentication, RBAC, PostgreSQL, Docker hot-reload, and Swagger documentation
Detailed Description of go-rest-api-boilerplate

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, AI-assistant optimized, with everything you need. Built for developers who want to code with AI, not fight it.
๐ Full Documentation โข ๐ Quick Start โข โจ Live Demo
๐ค AI-Friendly Development
GRAB is designed to work seamlessly with your favorite AI coding assistants:
Out-of-the-box AI integration with comprehensive guidelines for:
- GitHub Copilot (VS Code, GoLand, Visual Studio)
- Cursor IDE (with dedicated
.cursor/rules/) - Windsurf IDE (with dedicated
.windsurf/rules/) - JetBrains AI (via AGENTS.md standard)
- Any AI assistant supporting AGENTS.md standard
Note: GoLand users get dual AI support through both GitHub Copilot (via
.github/copilot-instructions.md) and JetBrains AI (viaAGENTS.md). No IDE-specific configuration needed.
AI assistants understand GRAB's Clean Architecture, Docker-first workflow, migration patterns, and testing conventions. Get intelligent code completions, accurate refactoring suggestions, and context-aware help.
๐ Learn More: AI-Friendly Development Guide
๐ 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)
โ
AI-Optimized Guidelines โ Built-in rules for GitHub Copilot, Cursor, Windsurf & AGENTS.md
โ
Security & JWT Auth โ OAuth 2.0 BCP compliant with refresh token rotation, rate limiting, CORS
โ
Role-Based Access Control โ Many-to-many RBAC with JWT integration and secure admin CLI
โ
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
โ
Standardized API Responses โ Consistent envelope format for all endpoints
โ
Structured Error Handling โ Machine-readable error codes with 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
- Docker and Docker Compose
- Git
๐ก 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
๐ Done! Your API is now running at:
- API Base URL: http://localhost:8080/api/v1
- Swagger UI: http://localhost:8080/swagger/index.html
- Health Checks: http://localhost:8080/health โข /health/live โข /health/ready
Create Admin User:
make create-admin # Interactive: prompts for email, name, password
make promote-admin ID=1 # Promote existing user to admin by ID
โจ See It In Action
Interactive Swagger Documentation
Open http://localhost:8080/swagger/index.html to explore and test all endpoints interactively.
Or Use Postman
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
- OAuth 2.0 BCP compliant โ JWT-based auth (HS256) with refresh token rotation and automatic reuse detection
- Enhanced security โ Refresh tokens with family tracking, secure token invalidation, and breach detection
- 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
๐ Authentication Guide | Context Helpers
๐ Role-Based Access Control (RBAC)
- Many-to-many architecture โ Flexible roles system with extensible permissions
- Secure admin CLI โ Interactive admin creation with strong password enforcement (no defaults in code)
- JWT-integrated authorization โ Roles embedded in tokens for server-side validation
- Protected endpoints โ Middleware-based access control (RequireRole, RequireAdmin)
- Three-endpoint pattern โ
/auth/me(current user),/users/:id(specific),/users(admin list) - Paginated user management โ Admin-only user listing with filtering and search
๐ RBAC 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-starthandles everything - Development & production โ Separate optimized configs
- Multi-stage builds โ Tiny production images (~20MB)
๐ Docker Guide
๐ฅ Production-Grade Health Checks
- Kubernetes-ready probes โ Liveness (
/health/live) and readiness (/health/ready) endpoints - Database health monitoring โ Response time tracking with pass/warn/fail thresholds
- RFC-compliant responses โ Following IETF draft standards for health check format
- Zero-downtime deployments โ Smart readiness checks for load balancer integration
- Extensible architecture โ Easy to add custom health checkers (Redis, external APIs, etc.)
๐ Health Checks 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
๐ฆ Standardized API Responses
- Consistent envelope format โ All responses wrapped in
{success, data, error, meta}structure - JSend-inspired design โ Industry best practice for API response formatting
- Type-safe responses โ Predictable structure for frontend integration
- Metadata support โ Pagination, timestamps, request IDs built-in
๐ API Response Format Guide
โ ๏ธ Error Handling That Makes Sense
- Structured API errors โ Machine-readable codes (NOT_FOUND, VALIDATION_ERROR, etc.)
- Detailed error info โ Code, message, details, timestamp, path, request ID
- Validation details โ Clear field-level error messages for bad requests
- Centralized middleware โ Single error handler for consistent responses
- Rate limit errors โ Includes
retry_afterfor proper backoff logic
๐ 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.
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)
- โ Production-grade health checks (liveness & readiness probes)
- โ 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
๐ Documentation
๐ Full Documentation Site
Complete guides covering everything:
- ๐ Getting Started โ Installation and configuration
- ๐ป Development Guide โ Building features
- ๐ก TODO Tutorial โ Step-by-step implementation
- ๐ณ Docker Guide โ Container workflows
- ๐๏ธ Migrations โ Database schema management
- ๐ฅ Health Checks โ Kubernetes probes and monitoring
- ๐งช Testing โ Writing and running tests
- ๐ฆ API Response Format โ Standardized response envelope
- โ ๏ธ Error Handling โ Structured API errors
- ๐ Swagger โ API documentation
- โ๏ธ Configuration โ Environment setup
๐ค Contributing to Documentation
Documentation lives in a separate repository. To contribute:
- Visit github.com/vahiiiid/go-rest-api-docs
- Follow the contributing guidelines
- 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
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Make your changes
- Run tests and linter (
make lint-fix && make lint && make test) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - 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
- ๐ Read the Documentation
- ๐ Report Bugs
- ๐ฌ Ask Questions
- โญ Star this repo if you find it helpful!
Made with โค๏ธ for the Go community
โญ Star โข ๐ Docs โข ๐ Issues โข ๐ฌ Discussions