NotifyHub is a real-time notification system built with ASP.NET Core and SignalR, designed to provide efficient and scalable group-based notifications. It's perfect for applications that need to send targeted notifications to specific user groups or roles.
- Real-time Notifications: Instant delivery using SignalR
- Group-based Targeting: Send notifications to specific user groups
- Event History: Track and retrieve notification history
- Role-based Access: Secure notifications with role-based permissions
- Scalable Architecture: Built with performance and scalability in mind
- Modern UI: Clean and responsive user interface
- Easy Integration: Simple API for sending and receiving notifications
- .NET 8.0 SDK
- Node.js 18+ (for test client)
- Modern web browser
- Clone the repository:
git clone https://github.com/mberrishdev/NotifyHub.git
cd NotifyHub- Build and run the server:
dotnet build
dotnet run --project src/NotifyHub.Api- Start the test client:
cd test-client
npm install
npm start- Open your browser and navigate to
https://localhost:5000
// Create a notification
var notification = new Notification
{
Type = "UserJoined",
Data = new { userId = "123", username = "John" },
TargetGroups = new List<string> { "group1", "group2" }
};
// Send the notification
await _notificationService.SendNotificationAsync(notification);// Connect to the hub
const connection = new signalR.HubConnectionBuilder()
.withUrl("/notificationHub")
.build();
// Handle incoming notifications
connection.on("ReceiveNotification", (notification) => {
console.log("New notification:", notification);
});
// Connect with specific groups
await connection.start();
await connection.invoke("ConnectWithGroups", ["group1", "group2"]);// Subscribe to groups
await _groupService.SubscribeToGroupsAsync(userId, connectionId, groups);
// Unsubscribe from groups
await _groupService.UnsubscribeFromGroupsAsync(userId, connectionId, groups);NotifyHub follows a clean architecture pattern:
NotifyHub/
├── src/
│ ├── NotifyHub.Api/ # API layer
│ ├── NotifyHub.Application/ # Business logic
│ └── NotifyHub.Domain/ # Domain models
└── test-client/ # Test client application
- NotificationHub: SignalR hub for real-time communication
- GroupSubscriptionService: Manages group subscriptions
- EventHistoryService: Handles notification history
- NotificationService: Core notification logic
- JWT-based authentication
- Role-based authorization
- Secure WebSocket connections
- Input validation and sanitization
Run the test suite:
dotnet testPOST /api/auth/token
Content-Type: application/json
{
"userId": "string",
"role": "string"
}POST /api/notifications
Authorization: Bearer {token}
Content-Type: application/json
{
"type": "string",
"data": object,
"targetGroups": ["string"]
}- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email mikheil.berishvili@outlook.com or open an issue in the repository.
Made with ❤️ by [Mikheil Berishvili]
NotifyHub now uses a flexible group-based notification system. Each event can be sent to specific groups, and users can subscribe to groups dynamically.
- Send a notification to specific groups:
{
"type": "task.created",
"data": "{\"priority\": \"high\", \"message\": \"Important task!\"}",
"targetGroups": ["admin", "developers"],
"saveToHistory": true
}- Send a notification to all groups:
{
"type": "system.update",
"data": "{\"version\": \"1.0.0\", \"message\": \"System updated\"}",
"saveToHistory": true
}The system supports filtering events based on their data. Filters can work with:
- JSON data
- Dictionary data
- Object properties
- Filter by status:
{
"type": "order.created",
"data": "{\"status\": \"completed\", \"orderId\": \"12345\"}"
}- Filter by numeric value:
{
"type": "payment.received",
"data": "{\"amount\": 100.50, \"currency\": \"USD\"}"
}POST /api/auth/token- Get JWT token
POST /api/events- Send a new event
The application uses a SignalR hub for real-time communication:
- Hub URL:
/notificationHub - Client method:
ReceiveNotification - Authentication: JWT token required
- JWT-based authentication
- Role-based access control
- Secure WebSocket connections
- CORS configuration for development
NotifyHub/
├── src/
│ ├── NotifyHub.Api/ # API project
│ ├── NotifyHub.Application/ # Application layer
│ └── NotifyHub.Infrastructure/# Infrastructure layer
└── test-client/ # Test client
dotnet test- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Users can configure their notification preferences through the test client interface. The configuration includes:
FilterField: Field to filter incoming notificationsFilterValue: Value to match against the filter fieldEventTypes: Comma-separated list of event types to receive
{
"filterField": "priority",
"filterValue": "high",
"eventTypes": ["task.created", "order.completed", "system.alert"]
}This configuration will:
- Only show notifications where the
priorityfield equalshigh - Only receive notifications of type
task.created,order.completed, orsystem.alert
- Open
http://localhost:5500in your browser - In the Authentication section:
- Enter a User ID (e.g., "1")
- Enter a Role (e.g., "admin")
- Click "Get Token"
- You should see "Token received" in the status
- Click "Connect" to establish the SignalR connection
- You should see "Connected" in the status
- In the Notification Configuration section:
- Enter a Filter Field (e.g., "priority")
- Enter a Filter Value (e.g., "high")
- Enter Event Types (e.g., "task.created,order.completed")
- Click "Save Configuration"
- You should see a success message
In the test client:
-
For group-specific notification with priority:
- Event Type:
task.created - Event Data:
{"priority": "high", "message": "Important task!"} - Target Groups:
admin,developers
- Event Type:
-
For broadcast notification:
- Event Type:
system.broadcast - Event Data:
{"message": "System broadcast!"}
- Event Type:
The notifications will now include:
- Timestamp
- Event Type
- Username of the sender
- Event Data
-
If you can't connect to SignalR:
- Check that the API is running
- Verify you have a valid token
- Check the browser console for errors
-
If you don't receive notifications:
- Verify you're connected to SignalR
- Check that you've subscribed to the correct groups
- Ensure the event type matches your configuration
- Check the API logs for any errors
-
If you get CORS errors:
- Make sure you're accessing the test client through
http://localhost:5500 - Verify the API is running on
https://localhost:5000
- Make sure you're accessing the test client through
