A powerful CLI tool that generates modern Go backend projects with Gin, GORM, JWT authentication, and enterprise-grade project structure.
- π― Interactive CLI with beautiful terminal UI (using Bubble Tea)
- ποΈ Modern Tech Stack: Gin web framework, GORM ORM, JWT auth
- ποΈ Multiple Databases: PostgreSQL, MySQL, SQLite, MongoDB support
- π Authentication: JWT-based auth with bcrypt password hashing
- π Enterprise Structure: Clean architecture with services, handlers, middleware
- π³ Docker Support: Dockerfile and docker-compose.yml generation
- π§ͺ Testing: Unit test templates included
- π§ Auto-Migration: Database tables created automatically
- π Environment Config: .env file support with godotenv
- Go 1.21+ installed on your system
- Git (optional, for cloning)
- Database (PostgreSQL/MySQL/SQLite/MongoDB) - optional, projects can run without DB
# Clone the repository
git clone <repository-url>
cd go-backend-generator
# Install dependencies
go mod tidy
# Build the generator
go build -o go-backend-gen main.go
# Run the interactive generator
./go-backend-gen
# Or run directly with Go
go run main.go
# Add to system path
sudo cp go-backend-gen /usr/local/bin/
# Run
go-backend-genThe generator will ask you:
- Project Name:
my-awesome-api - Go Module Name:
github.com/username/my-awesome-api - Database Choice: PostgreSQL, MySQL, SQLite, MongoDB, or None
- Features:
- β Authentication (JWT-based)
- β Docker Support
- β REST API (User CRUD)
- β Unit Tests
my-awesome-api/
βββ cmd/server/main.go # Application entry point
βββ internal/
β βββ api/
β β βββ handlers/ # HTTP handlers (Gin)
β β β βββ health.go # Health check endpoint
β β β βββ user.go # User CRUD endpoints
β β βββ middleware/ # Auth middleware
β β βββ routes/ # Route setup
β βββ auth/ # Authentication service
β βββ config/ # Configuration management
β βββ database/ # GORM database connection
β βββ models/ # Data models with GORM tags
β βββ services/ # Business logic layer
β βββ utils/ # Utility functions
βββ migrations/ # Database migrations
βββ .env # Environment variables
βββ .env.example # Example environment file
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ go.mod # Go dependencies
βββ README.md # Project documentation
cd my-awesome-api
# Install dependencies
go mod tidy
# Set up environment (optional)
cp .env.example .env
# Edit .env with your database credentials
# Run the server
go run main.goThe generated project includes these endpoints:
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
POST |
/api/v1/auth/register |
User registration |
POST |
/api/v1/auth/login |
User login |
GET |
/api/v1/users |
Get all users |
POST |
/api/v1/users |
Create user |
GET |
/api/v1/users/:id |
Get user by ID |
PUT |
/api/v1/users/:id |
Update user |
DELETE |
/api/v1/users/:id |
Delete user |
# Health check
curl http://localhost:8080/health
# Register a new user
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"username": "johndoe",
"password": "secretpassword",
"first_name": "John",
"last_name": "Doe"
}'
# Login
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "secretpassword"
}'
# Get users (requires authentication)
curl -X GET http://localhost:8080/api/v1/users \
-H "Authorization: Bearer YOUR_JWT_TOKEN"If you enabled Docker support, you can run the generated project with:
# Build and run with Docker Compose
docker-compose up --build
# Or build manually
docker build -t my-awesome-api .
docker run -p 8080:8080 my-awesome-apicreatedb my-awesome-api
export DATABASE_URL="postgres://localhost/my-awesome-api?sslmode=disable"mysql -u root -p -e "CREATE DATABASE my_awesome_api;"
export DATABASE_URL="root:password@tcp(localhost:3306)/my_awesome_api"# No setup needed - file will be created automatically
export DATABASE_URL="my-awesome-api.db"Run tests in the generated project:
cd my-awesome-api
go test ./...To modify the generator itself:
- Edit Templates: Update templates in
main.go - Add Features: Modify the
ProjectConfigstruct and generation logic - Test Changes: Run
go run main.goto test your changes
The generated projects follow these patterns:
- Handlers: HTTP request/response logic in
internal/api/handlers/ - Services: Business logic in
internal/services/ - Models: Data structures in
internal/models/ - Database: GORM setup in
internal/database/ - Config: Environment configuration in
internal/config/
- β Password Hashing: bcrypt with salt
- β JWT Authentication: Secure token-based auth
- β Input Validation: Struct validation tags
- β Database Security: GORM prevents SQL injection
- β CORS Ready: Easy to add CORS middleware
github.com/charmbracelet/bubbletea- Terminal UIgithub.com/charmbracelet/lipgloss- Terminal styling
github.com/gin-gonic/gin- Web frameworkgorm.io/gorm- ORMgithub.com/golang-jwt/jwt/v5- JWT authenticationgolang.org/x/crypto- Password hashinggithub.com/joho/godotenv- Environment variablesgithub.com/google/uuid- UUID generation
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Gin Web Framework - Fast HTTP web framework
- GORM - Fantastic ORM library
- Bubble Tea - Beautiful terminal UIs
Happy Coding! π
Generate modern Go backends in seconds!