Skip to content

Sentinel: An Intelligent Alert Escalation and Resolution System designed for fleet monitoring. It ingests alerts from multiple sources, applies dynamic, configurable rules for auto-escalation and performs auto-closure via an idempotent background job. Features a minimal dashboard for real-time visibility and analytics. Built using the MERN/Node.js.

Notifications You must be signed in to change notification settings

manirht/Sentinel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sentinel - Intelligent Alert Escalation & Resolution System

Sentinel Banner License Version

πŸ“‹ Table of Contents

🎯 Overview

Sentinel is an intelligent alert management system designed for MoveInSync fleet operations. It automatically escalates, de-escalates, and closes alerts based on dynamic, configurable rules, providing real-time visibility through a comprehensive dashboard.

Problem Statement

MoveInSync operates multiple fleet-monitoring modules (Safety, Compliance, Feedback) that generate alerts like overspeeding, expiring documents, or poor driver feedback. These alerts currently require manual review, creating operational bottlenecks. Sentinel solves this by:

  • Automating alert escalation based on configurable rules
  • Auto-closing alerts when conditions are met
  • Providing real-time dashboards for monitoring
  • Tracking complete alert lifecycle history

✨ Features

1. Centralized Alert Management

  • βœ… Unified API for ingesting alerts from multiple sources
  • βœ… Normalized storage format: {alertId, sourceType, severity, timestamp, status, metadata}
  • βœ… State transitions: OPEN β†’ ESCALATED β†’ AUTO-CLOSED β†’ RESOLVED

2. Lightweight Rule Engine

  • βœ… Configurable DSL-like rule system
  • βœ… Dynamic rule evaluation without hardcoding
  • βœ… Support for time-window based conditions
  • βœ… Example rules:
    • Overspeed: Escalate if 3+ events within 60 minutes
    • Compliance: Auto-close when document renewed
    • Feedback: Escalate if 2+ negative feedbacks in 24 hours

3. Auto-Close Background Job

  • βœ… Periodic worker (cron-based) scanning alerts
  • βœ… Idempotent operations (safe to re-run)
  • βœ… Automatic state transitions based on conditions
  • βœ… Audit trail of all auto-closure events

4. Interactive Dashboard

  • βœ… Real-time severity and status distribution
  • βœ… Top 5 drivers with most alerts
  • βœ… Recent alert lifecycle events
  • βœ… Auto-closed alerts transparency
  • βœ… 7-day trend analysis charts
  • βœ… Alert drill-down with full history

5. Robust Authentication

  • βœ… JWT-based authentication
  • βœ… Role-based access control (User, Operator, Admin)
  • βœ… Secure password hashing (bcrypt)
  • βœ… Protected API routes

6. Advanced Features

  • βœ… Caching: In-memory caching for dashboard data (node-cache)
  • βœ… Error Handling: Comprehensive error recovery procedures
  • βœ… Logging: Winston logger with structured logging
  • βœ… Monitoring: System health endpoints and statistics
  • βœ… Security: Helmet, CORS, rate limiting

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     FRONTEND (React + Vite)                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚Dashboard β”‚ β”‚ Alerts   β”‚ β”‚  Rules   β”‚ β”‚   Auth   β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ HTTP/REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  BACKEND (Node.js + Express)                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              API Routes & Controllers                 β”‚   β”‚
β”‚  β”‚  β€’ Auth   β€’ Alerts   β€’ Dashboard   β€’ Rules          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                         β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Services Layer                           β”‚   β”‚
β”‚  β”‚  β€’ Rule Engine     β€’ Background Jobs                 β”‚   β”‚
β”‚  β”‚  β€’ Cache Manager   β€’ Logger                          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                         β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Middleware                               β”‚   β”‚
β”‚  β”‚  β€’ Authentication  β€’ Error Handler  β€’ Validation     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MongoDB Database                          β”‚
β”‚  β€’ Users Collection    β€’ Alerts Collection                   β”‚
β”‚  β€’ Rules Collection    β€’ AlertHistory Collection             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • MongoDB - NoSQL database
  • Mongoose - ODM for MongoDB
  • JWT - Authentication
  • bcryptjs - Password hashing
  • node-cron - Background jobs
  • Winston - Logging
  • node-cache - In-memory caching
  • Helmet - Security headers
  • express-rate-limit - Rate limiting

Frontend

  • React 19 - UI framework
  • Vite - Build tool
  • React Router - Routing
  • Axios - HTTP client
  • Recharts - Data visualization
  • Tailwind CSS - Styling
  • Lucide React - Icons
  • React Hot Toast - Notifications
  • date-fns - Date formatting

πŸš€ Getting Started

Prerequisites

- Node.js >= 16.x
- MongoDB >= 5.x
- npm or yarn

Installation

1. Clone the repository

git clone https://github.com/manirht/Sentinel.git
cd Sentinel

2. Backend Setup

cd backend
npm install

# Create .env file
cp .env.example .env

# Update .env with your MongoDB URI
# MONGODB_URI=mongodb://localhost:27017/sentinel

# Seed database with sample data
node seed.js

# Start backend server
npm run dev
# Server runs on http://localhost:5000

3. Frontend Setup

cd frontend
npm install

# Start frontend development server
npm run dev
# Frontend runs on http://localhost:5173

πŸ” Default Credentials

Admin User:
Email: admin@sentinel.com
Password: admin123

Operator User:
Email: operator@sentinel.com
Password: operator123

πŸ“š API Documentation

Authentication Endpoints

POST /api/auth/register
POST /api/auth/login
GET  /api/auth/me
PUT  /api/auth/profile

Alert Endpoints

GET    /api/alerts              # Get all alerts with filters
POST   /api/alerts              # Create new alert
GET    /api/alerts/:id          # Get single alert
PUT    /api/alerts/:id          # Update alert
PUT    /api/alerts/:id/resolve  # Resolve alert
DELETE /api/alerts/:id          # Delete alert (Admin only)

Dashboard Endpoints

GET /api/dashboard/overview      # Get severity and status counts
GET /api/dashboard/top-offenders # Get top 5 drivers with most alerts
GET /api/dashboard/recent-events # Get recent alert lifecycle events
GET /api/dashboard/auto-closed   # Get recently auto-closed alerts
GET /api/dashboard/trends        # Get 7-day alert trends
GET /api/dashboard/by-source     # Get alerts grouped by source type

Rule Endpoints

GET    /api/rules          # Get all rules
POST   /api/rules          # Create rule (Admin only)
GET    /api/rules/:id      # Get single rule
PUT    /api/rules/:id      # Update rule (Admin only)
DELETE /api/rules/:id      # Delete rule (Admin only)
PATCH  /api/rules/:id/toggle # Toggle rule enabled/disabled (Admin only)

Alert Creation Example

POST /api/alerts
{
  "sourceType": "overspeed",
  "severity": "WARNING",
  "metadata": {
    "driverId": "DRV001",
    "driverName": "John Doe",
    "vehicleNumber": "MH-01-AB-1234",
    "speed": 85,
    "speedLimit": 60,
    "location": "Highway NH-48"
  }
}

Rule Creation Example

POST /api/rules
{
  "ruleId": "RULE_OVERSPEED_001",
  "sourceType": "overspeed",
  "name": "Overspeed Escalation Rule",
  "description": "Escalate to Critical if 3 overspeed events within 1 hour",
  "enabled": true,
  "priority": 10,
  "conditions": {
    "escalate_if_count": 3,
    "window_mins": 60,
    "auto_close_after_mins": 1440
  },
  "actions": {
    "escalate_to_severity": "CRITICAL",
    "notify": true,
    "notificationChannels": ["email", "sms"]
  }
}

πŸ” System Design

Time & Space Complexity Analysis

Alert Operations

  • Create Alert: O(log n) - Indexed insertion
  • Find Alert by ID: O(log n) - Index lookup
  • Filter Alerts: O(log n + k) - Index scan + result set
  • Update Alert: O(log n) - Index lookup + update

Rule Engine

  • Evaluate Single Alert: O(a) where a = alerts in time window
  • Batch Processing: O(n Γ— a) where n = alerts to process
  • Rule Lookup: O(1) - Hash map lookup

Dashboard Aggregations

  • Overview Stats: O(n) - Full collection scan with aggregation
  • Top Offenders: O(n log n) - Sort operation
  • Trends: O(n) - Time-based aggregation
  • Cache Hit: O(1) - In-memory lookup

Space Complexity

  • Per Alert Document: O(1) - Fixed size
  • Alert History: O(h) where h = history entries
  • Cache Storage: O(k) where k = cached items
  • Rule Storage: O(r) where r = number of rules

Database Indexes

// Alert Collection
{ alertId: 1 }                           // Unique
{ status: 1, timestamp: -1 }             // Compound
{ 'metadata.driverId': 1, status: 1 }    // Compound
{ sourceType: 1, status: 1, timestamp: -1 } // Compound
{ severity: 1, status: 1 }               // Compound
{ expiresAt: 1 }                         // TTL Index

// User Collection
{ email: 1 }                             // Unique

// Rule Collection
{ ruleId: 1 }                            // Unique
{ sourceType: 1, enabled: 1 }            // Compound

// AlertHistory Collection
{ alertId: 1, timestamp: -1 }            // Compound

Trade-offs

1. Caching Strategy

  • Choice: In-memory caching (node-cache)
  • Pros: Fast access O(1), No external dependencies
  • Cons: Data loss on restart, Not distributed
  • Production Alternative: Redis for distributed caching

2. Background Jobs

  • Choice: node-cron (in-process)
  • Pros: Simple setup, No external dependencies
  • Cons: Single instance only
  • Production Alternative: Bull queue with Redis

3. Rule Engine

  • Choice: In-memory rule storage with DB sync
  • Pros: Fast evaluation, Reduced DB calls
  • Cons: Rules reload on server restart
  • Mitigation: Periodic rule reload (every 5 minutes)

4. Database Choice

  • Choice: MongoDB (NoSQL)
  • Pros: Flexible schema, Fast reads, Horizontal scaling
  • Cons: No complex joins
  • Justification: Alert metadata varies by source type

🎨 Screenshots

Dashboard

Dashboard Overview Dashboard Graph

Alerts Management

Alerts Page

Rules Configuration

Rules Page Rules Page

Login Page

Login

πŸŽ₯ Demo

Demo Scenarios:

  1. Rule-based Escalation

    • Create 3 overspeed alerts for same driver within 1 hour
    • System automatically escalates to CRITICAL
  2. Auto-Close

    • Post compliance alert
    • Update document status to valid
    • System auto-closes the alert
  3. Dashboard Analytics

    • Real-time severity distribution
    • Top offenders leaderboard
    • 7-day trend visualization

πŸ” Error Handling & Monitoring

Error Handling

  • Global error middleware catches all exceptions
  • Meaningful error messages for debugging
  • Mongoose validation errors formatted
  • JWT errors handled gracefully
  • 404 handler for unknown routes

Logging

// Winston Logger Configuration
- error.log: Only errors
- combined.log: All logs
- Console: Development mode
- Structured JSON logging

Monitoring Endpoints

GET /health                 # Server health check
GET /api/monitoring/stats   # Cache & job statistics

πŸš€ Deployment

Environment Variables

# Server
PORT=5000
NODE_ENV=production

# Database
MONGODB_URI=mongodb://localhost:27017/sentinel

# JWT
JWT_SECRET=your_secure_secret_key
JWT_EXPIRE=7d

# Jobs
AUTO_CLOSE_JOB_INTERVAL=*/5 * * * *
RULE_EVALUATION_INTERVAL=*/2 * * * *

# Cache
CACHE_TTL=300

# Alerts
ALERT_EXPIRY_DAYS=30

Production Deployment

# Backend
cd backend
npm run build  # If using TypeScript
npm start

# Frontend
cd frontend
npm run build
# Serve dist folder with nginx or similar

πŸ“Š Performance Optimizations

  1. Database Indexing: Strategic indexes for common queries
  2. Caching: Dashboard data cached for 1-5 minutes
  3. Batch Processing: Alerts processed in batches of 100
  4. Connection Pooling: MongoDB connection pool (min: 5, max: 10)
  5. Compression: Response compression middleware
  6. Rate Limiting: 100 requests per 15 minutes per IP

πŸ›‘οΈ Security Features

  1. Authentication: JWT with httpOnly cookies option
  2. Password Hashing: bcrypt with salt rounds = 10
  3. Helmet: Security headers
  4. CORS: Configured for specific origins
  5. Rate Limiting: Prevents brute force attacks
  6. Input Validation: express-validator for all inputs
  7. SQL Injection: Mongoose parameterized queries

πŸ§ͺ Testing

# Backend tests (if implemented)
cd backend
npm test

# Frontend tests (if implemented)
cd frontend
npm test

πŸ“ Project Structure

Sentinel/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── database.js
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ alertController.js
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ dashboardController.js
β”‚   β”‚   └── ruleController.js
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ errorHandler.js
β”‚   β”‚   └── validator.js
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Alert.js
β”‚   β”‚   β”œβ”€β”€ AlertHistory.js
β”‚   β”‚   β”œβ”€β”€ Rule.js
β”‚   β”‚   └── User.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ alertRoutes.js
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ dashboardRoutes.js
β”‚   β”‚   └── ruleRoutes.js
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ backgroundJobs.js
β”‚   β”‚   └── ruleEngine.js
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ cache.js
β”‚   β”‚   └── logger.js
β”‚   β”œβ”€β”€ .env
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ seed.js
β”‚   └── server.js
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Layout.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.jsx
β”‚   β”‚   β”‚   └── PrivateRoute.jsx
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.jsx
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Alerts.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Register.jsx
β”‚   β”‚   β”‚   └── Rules.jsx
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ alertService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ api.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboardService.js
β”‚   β”‚   β”‚   └── ruleService.js
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ index.css
β”‚   β”‚   └── main.jsx
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ postcss.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── vite.config.js
β”‚
└── README.md

πŸ‘¨β€πŸ’» Contributors

πŸ“„ License

This project is licensed under the MIT License.

πŸ™ Acknowledgments

  • MoveInSync for the problem statement
  • MERN Stack community
  • Open source contributors

Built with ❀️ using MERN Stack

About

Sentinel: An Intelligent Alert Escalation and Resolution System designed for fleet monitoring. It ingests alerts from multiple sources, applies dynamic, configurable rules for auto-escalation and performs auto-closure via an idempotent background job. Features a minimal dashboard for real-time visibility and analytics. Built using the MERN/Node.js.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published