Skip to content

ArthurDS-tech/Notification-Engine

Repository files navigation

Notification Engine

A scalable, enterprise-grade notification system built with .NET 8, designed for modern applications requiring reliable message delivery across multiple communication channels.

Overview

This notification engine provides a robust, microservices-based architecture for handling multi-channel notifications at scale. Built with clean architecture principles, it offers asynchronous processing, automatic retry mechanisms, and comprehensive monitoring capabilities.

Key Features

Multi-Channel Support

  • Email - SendGrid integration with HTML and plain text support
  • SMS - Twilio integration with international support
  • Push Notifications - Firebase Cloud Messaging integration
  • Webhooks - Customizable HTTP callbacks

Asynchronous Processing

  • RabbitMQ message queuing with MassTransit
  • Specialized workers per channel for independent scaling
  • Automatic retry with exponential backoff
  • Dead letter queue handling for failed messages
  • Message prioritization (High, Medium, Low)

Dynamic Template System

  • Liquid.NET templating engine for flexible content
  • HTML and text support for emails
  • Automatic validation of required variables
  • Complete CRUD operations via REST API

Intelligent Scheduling

  • Quartz.NET for distributed job scheduling
  • Precise minute-level scheduling accuracy
  • Automatic reprocessing of failed notifications
  • Real-time job monitoring

Comprehensive Observability

  • Structured logging with Serilog
  • Detailed metrics by channel and status
  • Health checks for all services
  • Real-time statistics dashboard

Architecture

The system follows a clean architecture pattern with clear separation of concerns:

API Gateway → RabbitMQ → Specialized Workers → External Providers
                ↓
            MongoDB (Templates & Logs)
                ↓
            Quartz Scheduler

Quick Start

Prerequisites

  • Docker and Docker Compose
  • .NET 8 SDK (for local development)

Installation

  1. Clone the repository
git clone https://github.com/ArthurDS-tech/Notification-Engine.git
cd Notification-Engine
  1. Configure environment variables
cp .env.example .env
# Edit .env with your provider credentials
  1. Start the services
# Windows
start.bat

# Linux/Mac
chmod +x start.sh && ./start.sh

# Or manually
docker-compose up -d
  1. Verify installation
# Check service health
curl http://localhost:5000/health

# Send test notification
curl -X POST http://localhost:5000/api/notifications \
  -H "Content-Type: application/json" \
  -d '{
    "recipient": "user@example.com",
    "channel": "Email",
    "templateId": "welcome-email",
    "variables": {"userName": "John Doe"},
    "priority": "High"
  }'

Project Structure

src/
├── NotificationEngine.Domain/          # Core entities and interfaces
├── NotificationEngine.Application/     # Business logic and CQRS handlers
├── NotificationEngine.Infrastructure/  # External service implementations
├── NotificationEngine.Workers/         # Background processing services
├── NotificationEngine.DashboardApi/    # REST API for management
└── NotificationEngine.Tests/           # Unit and integration tests

Configuration

Environment Variables

The system requires the following environment variables (see .env.example):

# Database
MONGODB_CONNECTION_STRING=mongodb://admin:password123@mongodb:27017/notifications?authSource=admin

# Message Queue
RABBITMQ_CONNECTION_STRING=amqp://guest:guest@rabbitmq:5672/

# Email Provider (SendGrid)
SENDGRID_API_KEY=your-sendgrid-api-key

# SMS Provider (Twilio)
TWILIO_ACCOUNT_SID=your-twilio-account-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token

# Push Notifications (Firebase)
FIREBASE_PROJECT_ID=your-firebase-project-id

# Worker Configuration
WORKER_TYPE=All  # Options: All, Email, SMS, Push, Webhook, or combinations like "Email,SMS"

Template Configuration

Templates are stored in MongoDB and managed via the REST API. Example template structure:

{
  "id": "welcome-email",
  "name": "Welcome Email Template",
  "channel": "Email",
  "subject": "Welcome to {{ companyName }}, {{ userName }}!",
  "body": "Hello {{ userName }}, welcome to {{ companyName }}!",
  "htmlBody": "<h1>Welcome, {{ userName }}!</h1><p>Welcome to <strong>{{ companyName }}</strong>!</p>",
  "requiredVariables": ["userName", "companyName"]
}

API Reference

Notifications Endpoints

Method Endpoint Description
POST /api/notifications Send new notification
GET /api/notifications/{id} Get notification by ID
GET /api/notifications/pending List pending notifications
GET /api/notifications/stats Get delivery statistics

Templates Endpoints

Method Endpoint Description
GET /api/templates List all templates
GET /api/templates/{id} Get template by ID
POST /api/templates Create new template
PUT /api/templates/{id} Update existing template
DELETE /api/templates/{id} Delete template

Monitoring and Observability

Available Dashboards

Metrics Collected

  • Throughput per channel (messages/minute)
  • Success/failure rates per provider
  • Average processing latency
  • Queue depths and backlogs
  • Worker and job status

Development

Running Locally

  1. Start infrastructure services
docker-compose up -d mongodb rabbitmq
  1. Run the API
cd src/NotificationEngine.DashboardApi
dotnet run --urls="http://localhost:5000"
  1. Run workers
cd src/NotificationEngine.Workers
dotnet run

Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run integration tests
dotnet test --filter Category=Integration

Scaling and Performance

Worker Scaling

The system supports horizontal scaling of individual workers:

# Scale workers independently based on load
services:
  email-worker:
    deploy:
      replicas: 3  # Scale for high email volume
  
  sms-worker:
    deploy:
      replicas: 1  # Limited by provider rate limits

Queue Configuration

Channel Retry Policy Timeout Dead Letter Queue
Email 3x exponential 30s Yes
SMS 2x exponential 60s Yes
Push 3x exponential 30s Yes
Webhook 5x exponential 120s Yes

Troubleshooting

Common Issues

Workers not processing messages

# Check worker logs
docker-compose logs -f email-worker

# Check RabbitMQ queues
curl -u guest:guest http://localhost:15672/api/queues

MongoDB connection issues

# Test MongoDB connection
docker exec -it notification-mongo mongosh -u admin -p password123

Template rendering problems

# Check templates in database
docker exec -it notification-mongo mongosh -u admin -p password123
use notifications
db.templates.find().pretty()

Contributing

We welcome contributions to improve the Notification Engine. Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/new-feature)
  5. Create a Pull Request

Development Guidelines

  • Follow clean architecture principles
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Ensure all tests pass before submitting PR

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions, issues, or contributions, please:

  • Open an issue on GitHub
  • Check the documentation in the /docs folder
  • Review the implementation summary in IMPLEMENTATION_SUMMARY.md

Developed by Arthur DS - A production-ready notification system for modern applications.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published