A comprehensive full-stack real-time device monitoring solution built with .NET microservices backend, Next.js frontend, and interactive architecture visualization.
- Overview
- Architecture
- Features
- Project Structure
- Prerequisites
- Getting Started
- Projects
- Technology Stack
- Configuration
- Development
- Deployment
- API Documentation
- Contributing
- License
The Device Monitoring System is a modern, scalable solution for real-time device monitoring and alerting. Built with microservices architecture, it provides:
- Real-time device monitoring with configurable data sources
- Intelligent alarm system with rule-based threshold evaluation
- Centralized event streaming through WebSocket gateway
- Interactive web interface with live updates
- Flexible data persistence with SQLite and JSON support
- Visual architecture documentation with interactive diagrams
View Interactive Architecture Visualization β
Explore the system architecture with our interactive GoJS-powered diagram deployed on Vercel.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Layer β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Next.js Application (Pages Router) β β
β β β’ SignalR Client β’ TanStack Table β’ Chakra UI/RSuite β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β WebSocket (SignalR)
ββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
β Backend Services β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ β
β β Gateway Service β β Device Monitor β β Alarm Service β β
β β β’ WebSocket Hub β β β’ Data Loading β β β’ Rules Engine β β
β β β’ Event Router β β β’ Bg Updates β β β’ Alert Mgmt β β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββ
β Data Layer β
β ββββββββββββββββββββ ββββββββββββββββββββββββββββ β
β β SQLite Database β β JSON Files (Optional) β β
β β β’ EF Core β β β’ Device Data β β
β β β’ Alarm Rules β β β’ Fallback Source β β
β β β’ Device Data β ββββββββββββββββββββββββββββ β
β ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-
Device Monitoring Service
- Manages device data from SQLite or JSON files (configurable via AppSettings)
- Periodic background updates for device states
- Emits live device updates to Gateway and Alarm services
- RESTful API for device management
-
Alarm Service
- Receives real-time device updates from Device Monitoring Service
- Evaluates device metrics against predefined threshold rules
- Generates and persists alarms to SQLite database
- Triggers alarm notifications to Gateway Service
- Manages alarm rules and history
-
Gateway Service
- Central SignalR WebSocket hub for real-time communication
- Aggregates events from all backend services
- Routes live updates to connected frontend clients
- Single connection point for frontend (simplified architecture)
- Main Application
- React-based UI with Next.js Pages Router
- SignalR integration for real-time updates
- TanStack Table for efficient data rendering
- Chakra UI and RSuite component libraries
- SCSS modules for styling
-
SQLite Database
- Entity Framework Core integration
- Stores alarm rules, alarm history, and device data
- Configurable as primary data source
-
JSON Files
- Alternative device data source
- Useful for testing and development
- Switchable via AppSettings configuration
- Architecture Diagram Tool
- Interactive system architecture visualization
- Built with GoJS React for professional diagrams
- Shows real-time data flow and component relationships
- Separate Next.js application for documentation
- β‘ Live device status updates via WebSocket
- π Dynamic data visualization with TanStack Table
- π Automatic background data refresh
- π± Responsive design for desktop and mobile
- π¨ Rule-based threshold evaluation
- π― Configurable alarm rules per device
- π Alarm history and audit trail
- π Real-time alarm notifications
- βοΈ Switchable data sources (SQLite/JSON)
- π§ AppSettings-based configuration
- π¦ Easy deployment and setup
- π Secure and scalable architecture
- π Interactive architecture diagrams
- π Comprehensive documentation
- π§ͺ Easy testing with JSON fallback
- π Clear separation of concerns
device-monitoring-system/
βββ backend/
β βββ DeviceMonitoringService/
β β βββ Controllers/
β β βββ Services/
β β βββ Models/
β β βββ Data/
β β β βββ DbContext/
β β β βββ JsonFiles/
β β βββ BackgroundServices/
β β βββ appsettings.json
β β
β βββ AlarmService/
β β βββ Controllers/
β β βββ Services/
β β β βββ AlarmEvaluationService.cs
β β β βββ RuleEngineService.cs
β β βββ Models/
β β β βββ Alarm.cs
β β β βββ AlarmRule.cs
β β βββ Data/
β β βββ appsettings.json
β β
β βββ GatewayService/
β βββ Hubs/
β β βββ EventHub.cs
β βββ Services/
β βββ Models/
β βββ appsettings.json
β
βββ frontend/
β βββ device-monitoring-ui/
β β βββ src/
β β β βββ pages/
β β β β βββ _app.tsx
β β β β βββ index.tsx
β β β β βββ devices/
β β β β βββ alarms/
β β β βββ components/
β β β β βββ DeviceTable/
β β β β βββ AlarmPanel/
β β β β βββ common/
β β β βββ services/
β β β β βββ signalRService.ts
β β β β βββ apiService.ts
β β β βββ hooks/
β β β βββ styles/
β β β β βββ globals.scss
β β β β βββ components/
β β β βββ utils/
β β βββ public/
β β βββ package.json
β β
β βββ device-monitoring-viz/
β βββ src/
β β βββ components/
β β β βββ diagrams/
β β βββ pages/
β β βββ styles/
β β βββ utils/
β βββ package.json
β
βββ database/
β βββ migrations/
β βββ DeviceMonitoring.db
β βββ seed-data.sql
β
βββ docs/
β βββ architecture/
β βββ api/
β βββ deployment/
β βββ development/
β
βββ .gitignore
βββ README.md
βββ docker-compose.yml
- .NET SDK: 8.0 or higher
- Node.js: 16.x or higher
- npm/yarn: Latest version
- SQLite: 3.x (included with .NET)
- Git: For version control
- Visual Studio 2022 or VS Code with C# extension
- Postman or similar for API testing
- Docker (for containerized deployment)
-
Clone the repository
git clone https://github.com/yourusername/device-monitoring-system.git cd device-monitoring-system -
Setup Backend Services
cd backend/DeviceMonitoringService dotnet restore dotnet ef database update dotnet run # In separate terminals, start other services cd ../AlarmService dotnet run cd ../GatewayService dotnet run
-
Setup Frontend
cd frontend/device-monitoring-ui npm install npm run dev -
Access the Application
- Main UI: http://localhost:3000
- Device Service API: http://localhost:5001
- Alarm Service API: http://localhost:5002
- Gateway Service: http://localhost:5003
Edit appsettings.json in each service:
DeviceMonitoringService/appsettings.json
{
"DataSource": {
"UseDatabase": true, // true for SQLite, false for JSON
"ConnectionString": "Data Source=../../../database/DeviceMonitoring.db",
"JsonFilePath": "./Data/JsonFiles/devices.json"
},
"BackgroundService": {
"UpdateIntervalSeconds": 30
},
"GatewayService": {
"Url": "http://localhost:5003"
}
}AlarmService/appsettings.json
{
"ConnectionString": "Data Source=../../../database/DeviceMonitoring.db",
"ThresholdRules": {
"Temperature": {
"Min": 0,
"Max": 100
},
"Pressure": {
"Min": 0,
"Max": 500
}
},
"GatewayService": {
"Url": "http://localhost:5003"
}
}GatewayService/appsettings.json
{
"Cors": {
"AllowedOrigins": ["http://localhost:3000"]
},
"SignalR": {
"EnableDetailedErrors": true
}
}Create .env.local in frontend/device-monitoring-ui:
NEXT_PUBLIC_API_URL=http://localhost:5001
NEXT_PUBLIC_GATEWAY_URL=http://localhost:5003
NEXT_PUBLIC_ENABLE_MOCK_DATA=falseLocation: backend/DeviceMonitoringService
Purpose: Core service for managing and monitoring device data.
Key Features:
- Configurable data source (SQLite/JSON)
- Background data updates
- RESTful API endpoints
- Real-time data emission
Endpoints:
GET /api/devices- Get all devicesGET /api/devices/{id}- Get device by IDPOST /api/devices- Create new devicePUT /api/devices/{id}- Update deviceDELETE /api/devices/{id}- Delete device
Location: backend/AlarmService
Purpose: Intelligent alarm evaluation and management.
Key Features:
- Rule-based threshold evaluation
- Real-time device monitoring
- Alarm persistence and history
- Configurable alarm rules
Endpoints:
GET /api/alarms- Get all alarmsGET /api/alarms/{id}- Get alarm by IDGET /api/alarms/active- Get active alarmsPOST /api/alarms/rules- Create alarm rulePUT /api/alarms/{id}/acknowledge- Acknowledge alarm
Location: backend/GatewayService
Purpose: Central hub for real-time communication.
Key Features:
- SignalR WebSocket hub
- Event aggregation from services
- Real-time broadcasting to clients
SignalR Hub Methods:
SubscribeToDeviceUpdates()SubscribeToAlarms()UnsubscribeFromDeviceUpdates()UnsubscribeFromAlarms()
Location: frontend/device-monitoring-ui
Purpose: Primary user interface for monitoring and management.
Key Features:
- Real-time device dashboard
- Alarm management panel
- Device configuration
- Historical data views
Tech Stack:
- Next.js (Pages Router)
- TypeScript
- SignalR Client
- TanStack Table
- Chakra UI / RSuite
- SCSS Modules
Location: frontend/device-monitoring-viz
Purpose: Interactive system architecture documentation.
Key Features:
- GoJS-powered diagrams
- Interactive node exploration
- Professional visualization
- Export capabilities
See: Visualization README
- .NET 8.0 - Framework
- ASP.NET Core - Web API
- Entity Framework Core - ORM
- SignalR - Real-time communication
- SQLite - Database
- Serilog - Logging
- Next.js 13+ - React framework
- TypeScript - Type safety
- SignalR Client - WebSocket connection
- TanStack Table - Data tables
- Chakra UI - Component library
- RSuite - UI components
- SCSS Modules - Styling
- GoJS React - Diagramming (visualization project)
- Git - Version control
- Docker - Containerization
- GitHub Actions - CI/CD (optional)
Toggle between SQLite and JSON data sources in appsettings.json:
{
"DataSource": {
"UseDatabase": true // Set to false to use JSON files
}
}SQLite (Recommended for Production):
{
"ConnectionString": "Data Source=./DeviceMonitoring.db"
}JSON Files (Development/Testing):
{
"JsonFilePath": "./Data/JsonFiles/devices.json"
}Configure allowed origins in GatewayService/appsettings.json:
{
"Cors": {
"AllowedOrigins": [
"http://localhost:3000",
"https://yourdomain.com"
]
}
}Option 1: Manual (Separate Terminals)
# Terminal 1 - Device Service
cd backend/DeviceMonitoringService
dotnet run
# Terminal 2 - Alarm Service
cd backend/AlarmService
dotnet run
# Terminal 3 - Gateway Service
cd backend/GatewayService
dotnet run
# Terminal 4 - Frontend
cd frontend/device-monitoring-ui
npm run devOption 2: Docker Compose
docker-compose upcd backend/DeviceMonitoringService
dotnet ef migrations add InitialCreate
dotnet ef database updateGenerate API client for frontend:
cd frontend/device-monitoring-ui
npm run generate-api-clientBackend Tests:
cd backend/DeviceMonitoringService.Tests
dotnet testFrontend Tests:
cd frontend/device-monitoring-ui
npm testBackend:
cd backend/DeviceMonitoringService
dotnet publish -c Release -o ./publishFrontend:
cd frontend/device-monitoring-ui
npm run build
npm startdocker-compose -f docker-compose.prod.yml up -dProduction Backend:
export ASPNETCORE_ENVIRONMENT=Production
export ConnectionStrings__DefaultConnection="Data Source=/data/DeviceMonitoring.db"Production Frontend:
export NEXT_PUBLIC_API_URL=https://api.yourdomain.com
export NEXT_PUBLIC_GATEWAY_URL=https://gateway.yourdomain.comAccess interactive API documentation:
- Device Service: http://localhost:5001/swagger
- Alarm Service: http://localhost:5002/swagger
- Gateway Service: http://localhost:5003/swagger
Get All Devices:
curl http://localhost:5001/api/devicesCreate Alarm Rule:
curl -X POST http://localhost:5002/api/alarms/rules \
-H "Content-Type: application/json" \
-d '{
"deviceId": "device-001",
"parameter": "temperature",
"threshold": 80,
"operator": "GreaterThan"
}'SignalR Connection (JavaScript):
const connection = new signalR.HubConnectionBuilder()
.withUrl("http://localhost:5003/eventHub")
.build();
connection.on("DeviceUpdate", (data) => {
console.log("Device updated:", data);
});
await connection.start();
await connection.invoke("SubscribeToDeviceUpdates");We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a 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
- Backend: Follow C# coding conventions and use async/await
- Frontend: Use TypeScript, follow ESLint rules
- Commits: Use conventional commit messages
- Documentation: Update README and code comments
- .NET Team for the amazing framework
- Next.js team for the incredible React framework
- GoJS for powerful diagramming capabilities
- SignalR for real-time communication
- Open source community
Current Version: 1.0.0
Status: Active Development