A robust, production-ready authentication microservice built with Go, following clean architecture principles and best security practices.
Features include JWT-based authentication, email/phone verification, password reset, role and permission-based authorization, and more.
.
├── cmd/ # Main application entry points
│ └── server/ # HTTP server
├── internal/ # Private application code
│ ├── auth/ # JWT, OAuth, crypto, and cookie logic
│ ├── api/ # API handlers, middleware, and routes
│ ├── domain/ # Domain models and enums
│ ├── service/ # Business logic (auth, email, sms, etc.)
│ └── infrastructure/ # Database, migrations, repository
├── pkg/ # Public utilities (token, password, etc.)
├── configs/ # Configuration files
├── templates/ # Email templates (welcome, verification, reset)
├── docker/ # Dockerfile for containerization
├── scripts/ # Helper scripts
├── test/ # Test files and examples
├── .github/ # GitHub workflows and configs
├── .golangci.yml # Linting configuration
├── auth.http # Example HTTP requests for API testing
├── Makefile # Common development commands
└── README.md # Project documentation
- Clone the repository
- Copy and edit the config:
cp config.example.json config.json # Edit config.json with your settings - Install dependencies:
go mod download
- Run the service:
Or for development mode:
make run
make run-dev
make build— Build the application binary intobin/make run— Run the applicationmake run-dev— Run in development modemake test— Run all testsmake lint— Run code linter (golangci-lint)make clean— Remove build artifactsmake docker-build— Build the Docker image using the Dockerfilemake docker-run— Run the Docker container (exposes port 8080)make docker-push— Push the Docker image to Docker Hub (requires DOCKER_USERNAME)make docker-build-push— Build and push the Docker image to Docker Hub in one commandmake migrate-up— Run database migrationsmake migrate-down— Roll back database migrationsmake generate-mocks— Generate mocks for testingmake health— Health check endpoint
You can build and run the service in a container using the provided Dockerfile:
make docker-build
make docker-runOr manually:
docker build -t auth:latest -f docker/Dockerfile .
docker run -p 8080:8080 auth:latestTo build and push the Docker image to Docker Hub:
-
Login to Docker Hub (if not already logged in):
docker login
-
Build and push in one command:
make docker-build-push DOCKER_USERNAME=yourusername
Or build and push separately:
# Build with your Docker Hub username make docker-build DOCKER_USERNAME=yourusername # Push to Docker Hub make docker-push DOCKER_USERNAME=yourusername
-
Use a custom tag (optional):
make docker-build-push DOCKER_USERNAME=yourusername DOCKER_TAG=v1.0.0
The image will be tagged as
yourusername/auth:v1.0.0on Docker Hub.
Note: Replace yourusername with your actual Docker Hub username. The default tag is latest if not specified.
- Use the
auth.httpfile with VS Code REST Client or JetBrains HTTP Client to test endpoints. - Example requests for signup, login, verification, etc. are included.
- Lint your code with:
make lint
- Configuration is in
.golangci.yml.
templates/welcome.htmltemplates/email_verification.htmltemplates/password_reset.html
- Use
make testto run tests. - Use
make lintto check code quality. - Follow Go best practices and keep PRs focused.
MIT