A high-performance REST API built with Go and Gin framework
Gintama is a production-ready REST API server built with Go, designed for high performance and cost-effectiveness. The codebase follows clean architecture principles with dependency injection as its core design pattern.
- High Performance: Built on the Gin web framework with optimized middleware
- Clean Architecture: Dependency injection and separation of concerns
- Database Migrations: Automated schema management with golang-migrate
- Security: JWT authentication, Helmet middleware, CORS support
- Developer Experience: Hot reload support, comprehensive Make commands
- Production Ready: Docker support, cross-compilation, CI/CD ready
- Framework: Gin v1.11.0
- Database: PostgreSQL with lib/pq
- Migrations: golang-migrate
- Authentication: JWT with golang-jwt
- Email: Resend integration
- Middleware: CORS, Gzip, Rate Limiting, Request ID, Helmet
- Go 1.24.5 or higher
- PostgreSQL 18 or higher (using uuid v7)
- Make (optional but recommended)
- Clone the repository
git clone https://github.com/masb0ymas/gintama.git
cd gintama- Set up environment variables
cp .envrc.example .envrcEdit .envrc and configure your environment variables:
# Required configurations
export PORT=8080
export ENV=development
export DEBUG=true
export APP_NAME=gintama
# Database connection
export DB_DSN=postgres://postgres:postgres@localhost:5432/gintama?sslmode=disable
# JWT secret (generate a secure random string, with `openssl rand -base64 32`)
export JWT_SECRET=your-secret-key-here
# Application URLs
export CLIENT_URL=http://localhost:3000
export SERVER_URL=http://localhost:8080
# Optional: Email service (Resend)
export RESEND_API_KEY=your-resend-api-key
export [email protected]- Set up the database
Create your PostgreSQL database, then update the database name in /migrations/000001_initial-database.up.sql (search for dev_gintama and replace with your database name).
- Run migrations and seed data
make db/migrations/up/seed- Start the application
make runThe API will be available at http://localhost:8080
# List all available commands
make help# Run the application
make run
# Build the application
make build/api# Connect to the database using psql
make db/psql
# Create a new database migration
make db/migrations/new name=create_users_table
# Apply all pending migrations
make db/migrations/up
# Apply migrations and seed test data
make db/migrations/up/seed
# Rollback all migrations
make db/migrations/down
# Refresh database (down + up)
make db/migrations/refresh
# Refresh database with seed data
make db/migrations/refresh/seedgintama/
βββ cmd/
β βββ api/ # API server entry point
β βββ migrate/ # Migration CLI tool
βββ internal/ # Private application code
β βββ handlers/ # HTTP request handlers
β βββ models/ # Data models
β βββ repository/ # Data access layer
β βββ services/ # Business logic
βββ migrations/ # Database migration files
βββ public/ # Static files
βββ script/ # Utility scripts
βββ templates/ # Email/HTML templates
βββ .envrc.example # Environment variables template
βββ Dockerfile # Container configuration
βββ Makefile # Build and development commands
βββ go.mod # Go module dependencies
Build and run with Docker:
# Build the Docker image
docker build -t gintama:latest .
# Run the container
docker run -d -p 8080:8080 gintama:latestSet up GitHub Actions by configuring the workflows in .github/workflows. The CI/CD pipeline can push images to:
- Google Container Registry (GCR)
- AWS Elastic Container Registry (ECR)
- Docker Hub
- Any OCI-compatible registry
Build the application for your target environment:
make build/apiThis generates two binaries:
/bin/api- Compiled for your local machine's architecture/bin/linux_amd64/api- Cross-compiled for Linux AMD64 (production servers)
Deploy the appropriate binary to your server and run it with the required environment variables.
Ensure these are properly configured in production:
ENV=productionDEBUG=falseJWT_SECRET- Use a strong, randomly generated secretDB_DSN- Production database connection stringCLIENT_URL- Your frontend application URLSERVER_URL- Your API server URL
- JWT-based authentication
- Helmet middleware for security headers
- CORS configuration
- Rate limiting support
- Environment-based configuration
- SQL injection protection via parameterized queries
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.
GitHub: @masb0ymas
Email: [email protected]
Credit: @edwardanthony
Give a βοΈ if this project helped you!