The e-commerce-users-service
is a microservice designed to handle user authentication and management in an e-commerce platform. Built with Go, it adheres to Clean Architecture principles to ensure scalability, maintainability, and separation of concerns.
- User Authentication:
- Sign up with email confirmation.
- Sign in with JWT-based token generation.
- Logout with token blacklisting.
- Token refresh functionality.
- Email Confirmation:
- Send confirmation codes to users.
- Resend confirmation codes.
- Confirm user accounts via email.
- Secure Token Management:
- Access and refresh tokens with customizable TTL.
- Blacklist invalid or expired tokens.
This service follows Clean Architecture principles:
- Delivery: Manages incoming requests and interacts with the service layer.
- Service: Contains business logic and orchestrates data flow between layers.
- Repository: Handles interactions with the database, cache, and external APIs.
The service is configurable using a .env
file. Below is an example configuration:
# App configuration
ENV=local
PREFIX=USERS
# HTTP Server Configuration
HTTP_SERVER_HOST=localhost
HTTP_SERVER_PORT=8080
HTTP_SERVER_IDLE_TIMEOUT=4s
# PostgreSQL Database Configuration
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_NAME=postgres
POSTGRES_MAX_CONNS=100
# Redis Configuration
REDIS_ADDRESS=localhost:6379
REDIS_PASSWORD=secret-password
REDIS_DB=0
# SMTP Configuration
SMTP_USERNAME=***
SMTP_PASSWORD=***
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_CODE_TTL=15m
# Tokens Configuration
TOKENS_SECRET=secret-password
TOKENS_ACCESS_TTL=5m
TOKENS_REFRESH_TTL=15m
-
Clone the repository:
git clone https://github.com/your-username/e-commerce-users-service.git cd e-commerce-users-service
-
Set up the
.env
file with your configuration. -
Start the local development environment with Docker Compose:
make sandbox-up
-
To build and run the service inside the Docker container:
make run
The project includes a docker-compose.yml
file for local development:
-
Start the service:
make sandbox-up
-
Stop the service:
make sandbox-down
Run the tests using:
go test -v ./...
A Dockerfile is available to containerize the service:
docker build -t e-commerce-users-service .
docker run -d -p 8080:8080 e-commerce-users-service