A scalable, containerized microservice for sending notifications via Email, SMS, and WebSocket, built using GoFr – a Golang-based backend framework. This project is designed with clean 3-layer architecture and extensibility in mind.
- 📧 Email notifications via SMTP (MailHog)
- 📱 SMS notifications via Kannel gateway
- 🔔 WebSocket-based in-app alerts (real-time)
- 🧩 Dynamic message templating
- 🛠️ Unified API for triggering notifications
- 📦 Containerized with Docker Compose
git clone https://github.com/Kake27/notifygo
cd notification-service
Some default environmental variables have already been included in the code. In case any modification is needed, the environemental variables can be set as follows and used
SMTP_HOST=mailhog
SMTP_PORT=1025
SMTP_SENDER=[email protected]
KANNEL_URL=http://localhost:13013/cgi-bin/sendsms
KANNEL_USERNAME=test
KANNEL_PASSWORD=test123
KANNEL_SENDER=kannel
Make sure docker is installed and then run
docker compose up --build
This will start:
- notification-service (your Go app)
- MailHog for email testing at localhost:8025
- GMail SMTP is used for sending the real emails
- Kannel for SMS delivery on port 13013
POST /notify
{
"type": "email",
"to": "[email protected]",
"subject": "This is a test subject",
"message": "Hello from the Notification Service!"
}
MailHog will capture and display the email at: http://localhost:8025
POST /notify
{
"type": "sms",
"to": "+911234567890",
"message": "This is a test SMS from the Notification Service!"
}
This uses the Kannel HTTP API behind the scenes for delivery. For now, the SMS is only being queued for delivery rather than actually being sent.
POST /notify
{
"type": "push",
"to": "user123",
"subject": "Important Update",
"message": "You have a new notification!"
}
Note: The user must be connected via WebSocket to receive push notifications.
Connect to WebSocket endpoint for real-time push notifications:
ws://localhost:8000/ws/{userID}
The Notification Service supports templated messages with dynamic variables for notifications.
Templates are stored in PostgreSQL and can be created, deleted, and used dynamically via API endpoints or can be stored as .tmpl files in the store/templates/
folder.
Endpoint:
POST /template/create
Body:
{
"name": "template_name",
"content": "Hello {{.variable_name1}}, welcome to our platform! Your account ID is {{.variable_name2}}."
}
Endpoint:
DELETE /template/delete/{template_name}
An example of using a template is: Endpoint:
POST /notify
Body:
{
"type": "email",
"to": "[email protected]",
"template": "template_name",
"vars": {
"name": "John Doe",
"account_id": "ACC12345"
}
}
Altervatively, if the content is stored in a .tmpl file in the above mentioned directory, the name of the file may be passed in the "template:"
field in the request body along with the variables.
Check if service is alive:
GET /health
→ Returns whether the SMTP server for sending emails is online- Basic test route:
GET /greet
→ Returns "Hello World!" if the app is online.
- Language: Golang
- Framework: GoFr, Gorilla WebSocket
- Email Delivery: MailHog (for testing) and GMail SMTP (for actual sending)
- SMS Delivery: Kannel Gateway
- Push Notifications: WebSocket
- Containerization: Docker, Docker Compose
- Database: PostgreSQL (for template storage & management)