Enterprise-grade notifications microservice for the Codeway Online Courses Platform. Handles multi-channel delivery (in-app, email, push) with event-driven architecture, outbox pattern, and comprehensive user preference management.
Centralized notification hub that orchestrates multi-channel communication across the Codeway platform. Supports REST APIs and event-driven integration via RabbitMQ.
Core Capabilities:
- Multi-channel delivery (In-app, Email, Push)
- User preference management per notification type
- Event-driven architecture (MassTransit + RabbitMQ)
- Outbox pattern for reliable delivery
- Scheduled notifications
- Direct messaging between users
- Device management for push notifications
External Services β REST API / RabbitMQ Events
β
Controllers β CQRS (MediatR) β Services β Repositories β SQL Server
β
Background Workers (EmailOutbox, PushOutbox, Scheduled)
Data Flow:
- Request/Event β Validation β User Verification
sp_CreateNotification(stored procedure) creates notification + outbox items atomically- Background workers process outbox items asynchronously
- Delivery tracking across all channels
- .NET 8.0 + ASP.NET Core Web API
- EF Core 8.0 + SQL Server (stored procedures with TVPs)
- MassTransit 8.2 + RabbitMQ
- MediatR 14.0 (CQRS)
- FluentValidation 12.1
- Firebase Admin SDK (FCM push notifications)
- .NET 8.0 SDK
- SQL Server 2022+
- RabbitMQ (for events)
- Firebase project (for push)
-
Restore & Configure
dotnet restore OnlineCourseSystem.sln
Update
appsettings.jsonwith connection strings and credentials. -
Database Setup
dotnet ef database update --project OnlineCourseSystem.NotificationsExecute
Infrastructure/Database/SP_CreateNotification.sql -
Run
dotnet run --project OnlineCourseSystem.NotificationsSwagger UI:
https://localhost:5001/swagger
| Setting | Description |
|---|---|
ConnectionStrings:DefaultConnection |
SQL Server connection string |
RabbitMq:Host/Username/Password |
RabbitMQ connection |
EmailSettings:* |
SMTP configuration |
Firebase:CredentialsPath |
Firebase service account JSON path |
WorkerSettings:* |
Batch sizes and polling intervals |
Override via environment variables: ConnectionStrings__DefaultConnection=...
POST /api/notifications
{
"notificationType": "Course",
"title": "New lesson available!",
"content": "Lesson 5 is now available.",
"courseId": "5f2c8c2c-18d8-46b0-b4e9-f0e4dc8e6a61",
"userIds": ["c8c49232-4c8a-4f8c-8de1-4a70c7ad1140"]
}GET /api/notifications?userId={userId}&isRead=false&pageNumber=1&pageSize=20POST /api/notificationpreferences/{userId}
{
"notificationType": "Reminder",
"email": true,
"push": false,
"inApp": true
}POST /api/schedulednotifications
{
"notificationType": "Reminder",
"title": "Assignment due soon",
"content": "Your assignment is due in 2 days",
"userIds": ["user-id-1"],
"scheduledFor": "2024-12-25T10:00:00Z"
}- EmailOutboxWorker: Processes pending emails (batch size: 10, interval: 30s)
- PushOutboxWorker: Sends push notifications via FCM (batch size: 10, interval: 30s)
- ScheduledNotificationWorker: Processes scheduled notifications (batch size: 10, interval: 60s)
All workers include retry logic with exponential backoff.
Consumes events via RabbitMQ:
- NotificationRequestedEvent: Creates notifications for specified users
- UserEnrolledEvent: Auto-creates welcome notifications
- PaymentSucceededEvent: Creates payment confirmation notifications
Events are automatically consumed via MassTransit consumers registered in Program.cs.
Core Tables: Notifications, UserNotifications, NotificationPreferences, UserReferences, UserNotificationDeliveries
Outbox Tables: EmailOutbox, PushOutbox, ScheduledNotifications
Stored Procedures:
sp_CreateNotification: Atomic notification creation with TVPsp_GetUserNotifications: Paginated user notification retrieval
- FluentValidation: Automatic validation via MediatR pipeline behaviors
- ExceptionMiddleware: Global exception handler with structured logging
- Custom Exceptions:
BadRequestException,NotFoundException - Standardized Responses: Via
GlobalResponse.Shared
# Run tests
dotnet test OnlineCourseSystem.sln
# Format code
dotnet format OnlineCourseSystem.Notifications
# Create migration
dotnet ef migrations add <Name> --project OnlineCourseSystem.Notifications
# Apply migration
dotnet ef database update --project OnlineCourseSystem.Notificationsdotnet publish OnlineCourseSystem.Notifications -c Release -o ./publish/notificationsChecklist:
- Production connection strings configured
- RabbitMQ cluster setup (if using events)
- Firebase credentials configured
- SMTP credentials configured
- Database migrations applied
- Stored procedures executed
- Logging/monitoring configured
- Worker settings tuned
OnlineCourseSystem.Notifications/
βββ Controllers/ # REST endpoints
βββ Consumers/ # MassTransit event consumers
βββ Features/ # CQRS feature modules (Commands/Queries/Handlers)
βββ Infrastructure/
β βββ Database/ # Stored procedures
β βββ Repositories/ # Data access (Unit of Work)
β βββ Services/ # Domain services
βββ Workers/ # Background services
βββ Models/ # Entities, DbContext, Enums
βββ Validators/ # FluentValidation rules
- Fork & create feature branch
- Follow coding standards (nullable ref types, async/await, logging)
- Add tests for new functionality
- Run
dotnet formatanddotnet test - Submit PR with detailed description
Built with β€οΈ for the Codeway Online Courses Platform