sketch-service-email is a microservice developed in Go, focused on asynchronous email processing and delivery.
Study Project: This repository was created exclusively for learning purposes. The main goal is to explore modern framework integration, dependency management, and concurrency patterns in Go.
The project utilizes a robust stack to simulate a real-world production environment:
- Go (1.25.5): The core language of the project.
- Uber fx: Used for Dependency Injection, facilitating modularization and application lifecycle management.
- Fiber v3: A high-performance web framework for building API routes.
- Gomail: A library for constructing and sending emails via SMTP.
- Concurrency (Worker Pool): Implementation of queues using
channelsfor background email processing, preventing HTTP request blocking.
The project follows a modular structure:
config/: Environment variable management using dotenv.internal/handlers/: The transport layer (HTTP) that handles incoming subscription requests.internal/services/: Business logic layer, where subscription and email preparation reside.pkg/mail/: A utility package responsible for direct SMTP communication and Worker management.
- Go 1.25.5 or higher installed.
- An SMTP server for testing (e.g., Mailtrap).
-
Clone the repository:
git clone https://github.com/rickferrdev/sketch-service-email.git
-
Configure environment variables: Create a
.envfile in the root directory based on the keys defined in the code:MAIL_PORT=587 MAIL_HOST=smtp.example.com MAIL_USERNAME=your_username MAIL_PASSWORD=your_password
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
The server will start on port 8080.
POST /api/v1/subs/
Request Body:
{
"email": "user@example.com"
}Internal Workflow:
- Handler: Validates the request body.
- Service: Generates the email content.
- Mailer: Adds the message to a channel.
- Worker: A background worker consumes the channel and executes the SMTP delivery.
This project is licensed under the MIT License.