Skip to content

minisource/gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Minisource Gateway

API Gateway for the Minisource microservices ecosystem. Provides unified entry point with authentication, rate limiting, circuit breaking, and request routing.

Features

  • πŸ”€ Reverse Proxy - Route requests to backend services
  • πŸ” JWT Authentication - Validate and forward authentication tokens
  • ⚑ Rate Limiting - Redis-backed rate limiting per client
  • πŸ”Œ Circuit Breaker - Automatic failover and recovery
  • πŸ“Š Tracing - OpenTelemetry distributed tracing
  • πŸ₯ Health Checks - Monitor backend service health
  • πŸ›‘οΈ Security Headers - CORS, CSP, and security middleware

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    API Gateway (:8080)                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  Auth   β”‚  β”‚  Rate   β”‚  β”‚ Circuit β”‚  β”‚ Tracing β”‚    β”‚
β”‚  β”‚ Middle  β”‚  β”‚ Limiter β”‚  β”‚ Breaker β”‚  β”‚         β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β”‚
β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                         β”‚                                β”‚
β”‚                   β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”                         β”‚
β”‚                   β”‚   Proxy   β”‚                         β”‚
β”‚                   β”‚  Router   β”‚                         β”‚
β”‚                   β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό                  β–Ό                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Auth     β”‚   β”‚  Notifier   β”‚   β”‚   Other     β”‚
β”‚   :9001     β”‚   β”‚   :9002     β”‚   β”‚  Services   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

  • Go 1.24+
  • Redis 7+
  • Docker & Docker Compose (optional)

Development

# Clone repository
git clone https://github.com/minisource/gateway.git
cd gateway

# Copy environment file
cp .env.example .env

# Run with Docker Compose
make docker-up

# Or run locally
make run

Configuration

Variable Description Default
SERVER_PORT Gateway port 8080
SERVER_HOST Bind address 0.0.0.0
AUTH_SERVICE_URL Auth service URL http://localhost:9001
NOTIFIER_SERVICE_URL Notifier service URL http://localhost:9002
REDIS_HOST Redis host localhost
REDIS_PORT Redis port 6379
JWT_SECRET JWT signing secret Required
RATE_LIMIT_ENABLED Enable rate limiting true
RATE_LIMIT_RPS Requests per second 100
CIRCUIT_ENABLED Enable circuit breaker true
TRACING_ENABLED Enable OpenTelemetry true

API Routes

Authentication Routes (Proxied to Auth Service)

Method Path Description
POST /api/v1/auth/register User registration
POST /api/v1/auth/login User login
POST /api/v1/auth/refresh Refresh token
POST /api/v1/auth/logout User logout
GET /api/v1/auth/me Get current user

Notification Routes (Proxied to Notifier Service)

Method Path Description
POST /api/v1/notifications/send Send notification
GET /api/v1/notifications List notifications

Gateway Routes

Method Path Description
GET /health Gateway health check
GET /metrics Prometheus metrics

Makefile Commands

make build         # Build binary
make run           # Run locally
make test          # Run tests
make lint          # Run linter
make docker-build  # Build Docker image
make docker-up     # Start with docker-compose
make docker-down   # Stop containers

Adding New Routes

  1. Add service configuration in config/config.go
  2. Create handler in internal/handler/
  3. Add proxy configuration in internal/proxy/
  4. Register routes in internal/router/router.go

Middleware Stack

  1. Recovery - Panic recovery
  2. Request ID - Add unique request ID
  3. Logger - Request logging
  4. CORS - Cross-origin resource sharing
  5. Rate Limiter - Request rate limiting
  6. Auth - JWT validation (protected routes)
  7. Circuit Breaker - Failure isolation

Docker

# Build image
docker build -t minisource/gateway .

# Run container
docker run -p 8080:8080 --env-file .env minisource/gateway

Environment Files

  • .env.example - Template configuration
  • .env - Local development (git ignored)
  • .env.production - Production settings

Project Structure

gateway/
β”œβ”€β”€ cmd/
β”‚   └── main.go              # Entry point
β”œβ”€β”€ config/
β”‚   └── config.go            # Configuration loading
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ handler/             # Request handlers
β”‚   β”œβ”€β”€ middleware/          # Custom middleware
β”‚   β”œβ”€β”€ proxy/               # Reverse proxy logic
β”‚   └── router/              # Route definitions
β”œβ”€β”€ docker-compose.yml       # Base compose
β”œβ”€β”€ docker-compose.dev.yml   # Development compose
β”œβ”€β”€ docker-compose.prod.yml  # Production compose
β”œβ”€β”€ Dockerfile               # Container build
└── Makefile                 # Build commands

License

MIT

About

API gateway and edge routing for Minisource services

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors