Skip to content

Premal2002/DeviceMonitoringProject

Repository files navigation

Device Monitoring System

A comprehensive full-stack real-time device monitoring solution built with .NET microservices backend, Next.js frontend, and interactive architecture visualization.

.NET Next.js TypeScript SQLite SignalR

πŸ“‹ Table of Contents

🎯 Overview

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

🌐 Live Demo

View Interactive Architecture Visualization β†’

Explore the system architecture with our interactive GoJS-powered diagram deployed on Vercel.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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    β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

System Components

Backend Services (.NET 8)

  1. 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
  2. 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
  3. 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)

Frontend (Next.js)

  • 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

Data Layer

  • 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

Visualization (Next.js + GoJS)

  • 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

✨ Features

Real-time Monitoring

  • ⚑ Live device status updates via WebSocket
  • πŸ“Š Dynamic data visualization with TanStack Table
  • πŸ”„ Automatic background data refresh
  • πŸ“± Responsive design for desktop and mobile

Intelligent Alerting

  • 🚨 Rule-based threshold evaluation
  • 🎯 Configurable alarm rules per device
  • πŸ“ Alarm history and audit trail
  • πŸ”” Real-time alarm notifications

Flexible Configuration

  • βš™οΈ Switchable data sources (SQLite/JSON)
  • πŸ”§ AppSettings-based configuration
  • πŸ“¦ Easy deployment and setup
  • πŸ” Secure and scalable architecture

Developer Tools

  • πŸ“ Interactive architecture diagrams
  • πŸ“š Comprehensive documentation
  • πŸ§ͺ Easy testing with JSON fallback
  • πŸ” Clear separation of concerns

πŸ“ Project Structure

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

πŸ“¦ Prerequisites

Development Environment

  • .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

Optional Tools

  • Visual Studio 2022 or VS Code with C# extension
  • Postman or similar for API testing
  • Docker (for containerized deployment)

πŸš€ Getting Started

Quick Start

  1. Clone the repository

    git clone https://github.com/yourusername/device-monitoring-system.git
    cd device-monitoring-system
  2. 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
  3. Setup Frontend

    cd frontend/device-monitoring-ui
    npm install
    npm run dev
  4. Access the Application

Configuration

Backend Configuration

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
  }
}

Frontend Configuration

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=false

🎯 Projects

1. Device Monitoring Service

Location: 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 devices
  • GET /api/devices/{id} - Get device by ID
  • POST /api/devices - Create new device
  • PUT /api/devices/{id} - Update device
  • DELETE /api/devices/{id} - Delete device

2. Alarm Service

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 alarms
  • GET /api/alarms/{id} - Get alarm by ID
  • GET /api/alarms/active - Get active alarms
  • POST /api/alarms/rules - Create alarm rule
  • PUT /api/alarms/{id}/acknowledge - Acknowledge alarm

3. Gateway Service

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()

4. Main Frontend Application

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

5. Architecture Visualization

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

πŸ› οΈ Technology Stack

Backend

  • .NET 8.0 - Framework
  • ASP.NET Core - Web API
  • Entity Framework Core - ORM
  • SignalR - Real-time communication
  • SQLite - Database
  • Serilog - Logging

Frontend

  • 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)

DevOps

  • Git - Version control
  • Docker - Containerization
  • GitHub Actions - CI/CD (optional)

βš™οΈ Configuration

Data Source Configuration

Toggle between SQLite and JSON data sources in appsettings.json:

{
  "DataSource": {
    "UseDatabase": true  // Set to false to use JSON files
  }
}

Connection Strings

SQLite (Recommended for Production):

{
  "ConnectionString": "Data Source=./DeviceMonitoring.db"
}

JSON Files (Development/Testing):

{
  "JsonFilePath": "./Data/JsonFiles/devices.json"
}

CORS Configuration

Configure allowed origins in GatewayService/appsettings.json:

{
  "Cors": {
    "AllowedOrigins": [
      "http://localhost:3000",
      "https://yourdomain.com"
    ]
  }
}

πŸ’» Development

Running All Services

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 dev

Option 2: Docker Compose

docker-compose up

Database Migrations

cd backend/DeviceMonitoringService
dotnet ef migrations add InitialCreate
dotnet ef database update

Code Generation

Generate API client for frontend:

cd frontend/device-monitoring-ui
npm run generate-api-client

Testing

Backend Tests:

cd backend/DeviceMonitoringService.Tests
dotnet test

Frontend Tests:

cd frontend/device-monitoring-ui
npm test

🚒 Deployment

Production Build

Backend:

cd backend/DeviceMonitoringService
dotnet publish -c Release -o ./publish

Frontend:

cd frontend/device-monitoring-ui
npm run build
npm start

Docker Deployment

docker-compose -f docker-compose.prod.yml up -d

Environment Variables

Production 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.com

πŸ“š API Documentation

Swagger UI

Access interactive API documentation:

API Examples

Get All Devices:

curl http://localhost:5001/api/devices

Create 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");

🀝 Contributing

We welcome contributions! Please follow these guidelines:

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

Coding Standards

  • 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

πŸ™ Acknowledgments

  • .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

πŸ“Š Project Status

Current Version: 1.0.0
Status: Active Development

About

Project structure visualization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors