How gregorykogan/jwt-microservice works
Main Components
• Client: Represents any external consumer (browser, mobile app, etc.) making API requests.
• NGINX Reverse Proxy: Handles incoming requests and forwards them to the backend using Docker DNS-based load balancing.
• Docker DNS / Load Balancer: Registers multiple instances of the JWT service (illustrated as JWT Service 1, JWT Service 2, …, JWT Service n).
• JWT Authentication Service: The core service running the Go application (found in cmd/jwt-microservice and its supporting packages under pkg/). This component contains:
• Authentication logic (pkg/auth)
• Cache handling (pkg/cache)
• Logging (pkg/logging)
• Configuration (pkg/config)
• Secrets management (pkg/secrets)
• Health-checks (pkg/ping)
• Redis: Acts as a shared state repository for caching (used for efficient token validation, rotation, and auto-logout support).
• Optional: Load Testing Components – The load-tests directory indicates usage of Grafana K6 for performance evaluation.
File Structure for Architectural Clues
• The top-level directories (cmd, pkg, load-tests) indicate separation of concerns:
• “cmd” holds the entry point (main.go) for the JWT microservice.
• “pkg” contains the various internal libraries/modules such as authentication logic, caching, logging, etc.
• “load-tests” holds Docker and test-scripts for performance testing.
• Configuration files (config.yml, docker-compose.yml, nginx.conf) signal that the architecture is not only containerized but also geared for horizontal scalability through Docker’s orchestration.
Architectural Patterns
• The project follows a microservice pattern focused on authentication.
• There is a separation between core business logic (authentication, caching, repos) and infrastructure (NGINX, Docker, Redis).
• The usage of token rotation, auto-logout, and structured logging implies strong security and observability design principles.
• Horizontal scaling is built-in with Docker, where multiple instances are managed using DNS-based load balancing.
• Expand on it by incorporating additional components (such as configuration management and logging) that are present in the file structure.
• That every major module (client, reverse proxy, load balancer, multiple service instances, Redis, and load testing components) is represented and clearly connected.