A production-ready, real-time network intrusion detection system powered by XGBoost machine learning, featuring a modern Next.js dashboard and comprehensive threat analytics.
Features β’ Quick Start β’ Architecture β’ Documentation β’ Contributing
- Overview
- Features
- Architecture
- Tech Stack
- Prerequisites
- Installation
- Quick Start
- Project Structure
- Machine Learning Models
- API Documentation
- Frontend Dashboard
- Configuration
- Usage Examples
- Development
- Contributing
- License
RT-GIDS (Real-Time GPU-Accelerated Intrusion Detection System) is an advanced network security monitoring platform that combines machine learning-based threat detection with real-time visualization and analytics. The system processes network traffic in real-time, identifies malicious patterns using XGBoost classifiers, and provides comprehensive threat intelligence through an intuitive web dashboard.
- Real-Time Detection: Sub-second threat identification with WebSocket streaming
- Dual ML Models: Full-feature and lightweight realtime models for different use cases
- Modern Dashboard: Next.js 14 with Three.js 3D visualizations and real-time charts
- Production Ready: CPU-only mode with in-memory state management (no Docker/GPU required)
- Comprehensive Analytics: Threat trends, attack frequency, top attackers, and incident overview
- AI-Powered Narratives: GPT-4o-mini integration for intelligent threat summaries
- SHAP Explainability: Model interpretability for security analysts
- Real-time packet analysis with XGBoost-based classification
- Multi-attack type detection: Port scans, brute force, SQL injection, DDoS, malware C2 traffic
- Confidence scoring with severity classification (Low/Medium/High/Critical)
- Automated threat blocking and IP tracking
- Anomaly detection with statistical analysis
- Live threat radar with 3D globe visualization
- Attack frequency charts with time-series trends
- Top attackers geolocation mapping
- Incident overview with critical event tracking
- System diagnostics with health monitoring
- Model insights with SHAP feature importance
- Dark/Light theme support
- Responsive design with mobile compatibility
- Real-time WebSocket updates
- Audio notifications for critical threats
- Smooth animations with Framer Motion
- Accessibility features (reduced motion, low performance mode)
- Local simulation mode (no external dependencies)
- Hot reload for both frontend and backend
- TypeScript for type safety
- Comprehensive API with OpenAPI documentation
- Attack seeder for testing and demos
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RT-GIDS Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Frontend ββββββββββΊβ Backend ββββββββββΊβ ML Models β
β (Next.js) β HTTP β (FastAPI) β Load β (XGBoost) β
β β + WS β β β β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Dashboard β β Telemetry β β Threat β
β Components β β Service β β Metrics β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β
β β β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β FakeRedis β
β (In-Memory) β
β or Real Redis β
βββββββββββββββββββ
- Data Ingestion: Network events posted to
/ingestendpoint - ML Inference: XGBoost models classify threats in real-time
- Telemetry Processing: Events aggregated and normalized
- WebSocket Streaming: Real-time updates pushed to frontend
- Dashboard Rendering: React components visualize threats
- Analytics: Historical trends and patterns analyzed
- FastAPI 0.109+ - Modern async Python web framework
- XGBoost 2.1.0 - Gradient boosting for threat classification
- Pandas 2.1+ - Data manipulation and preprocessing
- NumPy 1.26+ - Numerical computations
- SHAP 0.41+ - Model explainability
- OpenAI 1.12+ - AI-powered threat narratives
- Uvicorn - ASGI server with WebSocket support
- Prometheus Client - Metrics collection
- Next.js 14.2 - React framework with App Router
- TypeScript 5.0 - Type-safe development
- React 19 - UI library
- Three.js 0.169 - 3D visualizations (Threat Globe)
- Recharts 2.15 - Data visualization
- Framer Motion 11 - Animations
- Tailwind CSS 3.4 - Utility-first styling
- Radix UI - Accessible component primitives
- Axios 1.7 - HTTP client
- Zustand/SWR - State management and data fetching
- XGBoost - Primary ML framework
- scikit-learn - Model evaluation and preprocessing
- SHAP - Feature importance and explainability
- Matplotlib/Seaborn - Visualization
- ESLint - Code linting
- Playwright - E2E testing
- Lighthouse - Performance auditing
- Stylelint - CSS linting
- Python 3.10 or higher
- Node.js 18+ and
npmorpnpm - Git for cloning the repository
- Optional:
OPENAI_API_KEYfor AI narrative summaries
- OS: Windows 10+, Linux, or macOS
- RAM: 4GB minimum (8GB recommended)
- Storage: 2GB free space
- Network: Local network access for testing
git clone https://github.com/yourusername/rt-gids.git
cd rt-gids# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv .venv
# Activate virtual environment
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# or
pnpm installIf you want to train your own models:
# Navigate to ML training directory
cd RealTime_IDS/scripts
# Preprocess CICIDS2017 dataset
python preprocess_gpu.py
# Train models
python train_gpu.pyPre-trained models are included in RealTime_IDS/models/.
# From project root
python run.pyThis starts both backend (port 8000) and frontend (port 3000) automatically.
cd backend
.venv\Scripts\activate # Windows
# or
source .venv/bin/activate # Linux/macOS
set SIM_MODE=true # Windows
# or
export SIM_MODE=true # Linux/macOS
uvicorn backend.app.main:app --reload --port 8000cd frontend
npm run dev
# or
pnpm dev# From project root
python attack_seeder.py --count 200- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/api/health
rt-gids/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ main.py # Application entry point
β β βββ routers/ # API route handlers
β β β βββ analytics.py # Analytics endpoints
β β β βββ logs.py # Log streaming
β β β βββ metrics.py # System metrics
β β β βββ threats.py # Threat detection
β β β βββ ...
β β βββ services/ # Business logic
β β β βββ ml_service.py # ML inference
β β β βββ telemetry_service.py # Telemetry
β β β βββ model_service.py # Model management
β β β βββ ...
β β βββ utils/ # Utilities
β β β βββ local_runtime.py # FakeRedis, SIM_MODE
β β β βββ model_loader.py # Model loading
β β βββ schemas/ # Pydantic models
β βββ requirements.txt # Python dependencies
β βββ models/ # ML model storage
β
βββ frontend/ # Next.js frontend
β βββ app/ # Next.js App Router
β β βββ page.tsx # Home page
β β βββ command-center/ # Main dashboard
β β βββ threat-analytics/ # Threat analytics page
β β βββ ...
β βββ components/ # React components
β β βββ command-center/ # Dashboard components
β β βββ threat/ # Threat visualization
β β βββ system/ # System diagnostics
β β βββ ui/ # UI primitives
β βββ hooks/ # React hooks
β β βββ useThreatTelemetry.ts # Telemetry hook
β β βββ useThreatAnalytics.ts # Analytics hook
β β βββ ...
β βββ lib/ # Utilities
β β βββ api.ts # API client
β βββ package.json # Node dependencies
β
βββ RealTime_IDS/ # ML training pipeline
β βββ scripts/
β β βββ preprocess_gpu.py # Data preprocessing
β β βββ train_gpu.py # Model training
β βββ models/ # Trained models
β β βββ xgb_gpu_ids.json # Full model
β β βββ xgb_realtime_ids.json # Realtime model
β βββ data/ # Processed datasets
β
βββ attack_seeder.py # Synthetic attack generator
βββ run.py # Unified launcher
βββ README.md # This file
RT-GIDS uses XGBoost Gradient Boosting classifiers for threat detection:
- Purpose: Comprehensive threat detection with all features
- Features: All CICIDS2017 dataset features
- Accuracy: ~99.92%
- Training Time: ~25 seconds
- Use Case: Deep analysis, high accuracy requirements
- Purpose: Fast real-time packet classification
- Features: 5 lightweight features
packet_lengthprotocolsrc_portdst_portip_version
- Accuracy: ~87.76%
- Training Time: ~6 seconds
- Use Case: Live network monitoring, low latency
cd RealTime_IDS/scripts
python preprocess_gpu.pyProcess:
- Load CICIDS2017 CSV files
- Clean and encode categorical features
- Handle missing values and outliers
- Create binary labels (Benign=0, Attack=1)
- Output:
features.csvandlabels.csv
python train_gpu.pyProcess:
- Load preprocessed data
- Train/test split (80/20, stratified)
- Train full model with all features
- Extract realtime features (5 features)
- Train lightweight realtime model
- Evaluate and save models
- Generate metrics and visualizations
Output Files:
xgb_gpu_ids.json- Full modelxgb_realtime_ids.json- Realtime modelmetrics.json- Training metricsconfusion_matrix_full.png- Confusion matrixfeature_importance_full.csv- Feature rankings
Full Model:
n_estimators=200
max_depth=8
learning_rate=0.1
subsample=0.8
colsample_bytree=0.8
tree_method="hist" # CPU modeRealtime Model:
n_estimators=150
max_depth=6
learning_rate=0.1
tree_method="hist"Models are automatically loaded by:
- ModelService: Loads
xgb_realtime_ids.jsonfor real-time inference - MLService: Loads realtime model (preferred) or full model (fallback)
Models support:
- Batch inference for performance
- SHAP explainability for feature importance
- Confidence scoring for threat severity
http://localhost:8000
POST /ingest- Ingest network eventsGET /api/threats/stats- Get threat statisticsGET /api/threats/recent?n=100- Get recent threatsWebSocket /ws/logs?token=api::dev-token-abc- Real-time log stream
GET /api/analytics/incidents-overview- Incident summaryGET /api/analytics/top-attackers?limit=5- Top attacker IPsGET /api/analytics/trends- Attack trends (15 minutes)GET /api/analytics/attack-frequency?window=5m- Attack frequency
GET /api/metrics/system- System metricsGET /api/metrics/threat- Threat metricsGET /api/metrics/anomalies- Anomaly detection
GET /api/model/info- Model informationPOST /api/model/reload- Reload ML modelGET /api/shap/explain- SHAP feature importance
GET /api/health- Health checkGET /api/health/scan- System diagnosticsWebSocket /ws/telemetry- Real-time telemetry stream
Visit http://localhost:8000/docs for Swagger UI with:
- Endpoint documentation
- Request/response schemas
- Try-it-out functionality
- Incident Overview: Total attacks, notifications, critical events
- Top Attackers: IP addresses with attack counts and geolocation
- Attack Frequency Chart: Time-series visualization
- AI Core Status: Model information and reload capability
- System Summary: Real-time metrics bar
- Threat Radar: 3D radar visualization with attack points
- Threat Globe: Interactive 3D globe with attacker locations
- Threat Table: Detailed event log with filtering
- Timeline: Attack timeline visualization
- System Health: CPU, memory, disk usage
- Network Stats: Packet counts, throughput
- Model Status: ML model information
- Service Status: Backend service health
- Feature Importance: SHAP-based feature rankings
- Model Metrics: Accuracy, precision, recall
- Prediction Examples: Sample predictions with explanations
- Real-time Updates: WebSocket streaming for live data
- Responsive Design: Mobile and desktop support
- Dark/Light Theme: System preference detection
- Audio Notifications: Sound alerts for critical threats
- Performance Controls: Reduced motion, low performance mode
- Accessibility: WCAG-compliant components
# Simulation mode (default: true)
SIM_MODE=true
# Model directory
RTGIDS_MODELS_DIR=D:/CN/RealTime_IDS/models
# OpenAI API (optional)
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini
# Batch processing
RTGIDS_BATCH_MAX=32
RTGIDS_BATCH_TIMEOUT=0.05# Backend URL (optional, defaults to http://127.0.0.1:8000)
NEXT_PUBLIC_BACKEND_URL=http://127.0.0.1:8000When SIM_MODE=true (default):
- Uses
FakeRedis(in-memory state) - No external Redis required
- CPU-only ML inference
- Tokenless WebSocket connections
- Perfect for local development
When SIM_MODE=false:
- Requires real Redis instance
- GPU inference if available
- Token-based WebSocket auth
- Production-ready mode
curl -X POST http://localhost:8000/ingest \
-H "Content-Type: application/json" \
-d '{
"timestamp": "2024-01-15T10:30:00Z",
"src_ip": "192.168.1.100",
"dst_ip": "192.168.1.5",
"dst_port": 80,
"proto": "TCP",
"bytes_in": 1024,
"bytes_out": 2048,
"is_attack": true,
"label": "Port Scan"
}'curl http://localhost:8000/api/threats/statscurl http://localhost:8000/api/analytics/top-attackers?limit=10const ws = new WebSocket('ws://127.0.0.1:8000/ws/logs?token=api::dev-token-abc');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Threat detected:', data);
};import requests
# Ingest event
response = requests.post(
'http://localhost:8000/ingest',
json={
'src_ip': '10.0.0.1',
'dst_ip': '192.168.1.1',
'dst_port': 443,
'proto': 'TCP',
'is_attack': True
}
)
# Get analytics
stats = requests.get('http://localhost:8000/api/analytics/incidents-overview').json()
print(f"Total attacks: {stats['total_attacks']}")# Backend with hot reload
cd backend
uvicorn backend.app.main:app --reload --port 8000
# Frontend with hot reload
cd frontend
npm run dev# Backend tests
cd backend
pytest
# Frontend tests
cd frontend
npm run test
# E2E tests
npm run verify:tier0# Lint frontend
cd frontend
npm run lint
# Format Python (using black)
cd backend
black app/
# Type check
cd frontend
npm run type-check# Build frontend
cd frontend
npm run build
# Start production server
npm run startContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Commit with clear messages:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow existing code style and conventions
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass
- Write clear commit messages
- π Bug fixes
- β¨ New features
- π Documentation improvements
- π¨ UI/UX enhancements
- π Performance optimizations
- π§ͺ Test coverage
- π Internationalization
This project is licensed under the MIT License - see the LICENSE file for details.
- CICIDS2017 Dataset - For training data
- XGBoost - Machine learning framework
- FastAPI - Modern Python web framework
- Next.js - React framework
- Three.js - 3D graphics library
- SHAP - Model explainability
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@rt-gids.example.com
Made with β€οΈ by the RT-GIDS Team
β Star this repo if you find it helpful!