Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9c8a346
all done
Godsmiracle001 Jul 23, 2025
b7942a5
implementatio of Advanced-Portfolio-Analytics-with-Market-Intelligence
shamoo53 Jul 23, 2025
8aa4305
feat(api-gateway): implement enterprise-grade gateway with tiered acc…
phertyameen Jul 23, 2025
3850381
feat: implement secrets management with HashiCorp Vault
Ibinola Jul 23, 2025
5069be9
transaction monitoring implementation
nafiuishaaq Jul 24, 2025
9958284
implemented the comprehensive transaction monitoring
nafiuishaaq Jul 24, 2025
343035e
Merge pull request #140 from Godsmiracle001/Professional-Market-Analy…
Cedarich Jul 24, 2025
74bd358
Merge pull request #141 from shamoo53/Advanced-Portfolio-Analytics-wi…
Cedarich Jul 24, 2025
7e2212d
Merge pull request #142 from phertyameen/feat/api-gateway/enterprise-…
Cedarich Jul 24, 2025
2550fdf
Merge pull request #144 from nafiuishaaq/feat-trans-monitoring
Cedarich Jul 24, 2025
5ebcfbc
Implement Cross-Chain Intelligence Aggregation
RUKAYAT-CODER Jul 25, 2025
795b2b6
feat: implement adaptive rate limiting with admin monitoring dashboard
Jayking40 Jul 26, 2025
f7c4557
feat: implement DecentralizedNewsAggregatorService with multi-source …
clintjeff2 Jul 26, 2025
7915eec
feat: implement AdvancedMLProcessor with institutional-grade algorithms
clintjeff2 Jul 26, 2025
e6dc315
test: add comprehensive test suite for AdvancedMLProcessor
clintjeff2 Jul 26, 2025
0ffc0f6
test: add comprehensive test suite for DecentralizedNewsAggregator
clintjeff2 Jul 26, 2025
fcb6b8b
test: add additional aggregator service test suite for validation
clintjeff2 Jul 26, 2025
2bfaa92
feat: enhance DecentralizedSource DTOs with comprehensive validation
clintjeff2 Jul 26, 2025
41c29c0
feat: update DecentralizedSource entity with enhanced properties
clintjeff2 Jul 26, 2025
1ff5304
feat: update ContentVerification entity for decentralized validation
clintjeff2 Jul 26, 2025
dc41b59
docs: add implementation summary for decentralized news engine
clintjeff2 Jul 26, 2025
9d247c2
feat: add ML processing DTOs for content analysis
clintjeff2 Jul 26, 2025
398fcc7
test: update test environment configuration
clintjeff2 Jul 26, 2025
9fc2efa
test: add additional ML processor test suite
clintjeff2 Jul 26, 2025
d647fa1
test: add simple aggregator test suite
clintjeff2 Jul 26, 2025
c3e3a78
test: add comprehensive aggregator test suite
clintjeff2 Jul 26, 2025
81c5645
test: add working aggregator test suite
clintjeff2 Jul 26, 2025
d284373
made sure md file demonstrates exactly was has been implemented
clintjeff2 Jul 26, 2025
cd0044c
Merge pull request #146 from Jayking40/main
Cedarich Jul 26, 2025
555bedc
created the content validation system
yusuftomilola Jul 27, 2025
00515c7
Merge pull request #147 from clintjeff2/main
Cedarich Jul 27, 2025
617091b
Merge pull request #145 from RUKAYAT-CODER/feat-cross-chain-intelligence
Cedarich Jul 27, 2025
a5cb75f
Merge pull request #148 from yusuftomilola/main
Cedarich Jul 27, 2025
a1ee47f
major fixes
Divineifed1 Jul 30, 2025
d88f24e
Merge pull request #150 from Pulsefy/parody
Divineifed1 Jul 30, 2025
5547cb5
Implement Comprehensive Caching Strategy
KuchiMercy Aug 2, 2025
7599884
Disaster Recovery RBAC System
KuchiMercy Aug 2, 2025
f20eb1a
Implemented Token Based incensive and governance
KAMALDEEN333 Aug 2, 2025
3e7612b
Merge pull request #152 from KuchiMercy/feat/issue#108
Cedarich Aug 2, 2025
0789978
Merge pull request #153 from KAMALDEEN333/Token-Based
Cedarich Aug 2, 2025
a5f4bc1
fixes
ifediorahsamuels Aug 5, 2025
ca36d88
Merge branch 'main' into olive
ifediorahsamuels Aug 6, 2025
c82c085
Merge pull request #154 from ifediorahsamuels/olive
Divineifed1 Aug 6, 2025
e28d025
Merge remote-tracking branch 'origin/feat/secrets-management-vault'
Ibinola Aug 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install && npm run build
command: npm run start


210 changes: 210 additions & 0 deletions ADAPTIVE_RATE_LIMITING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Adaptive Rate Limiting & Monitoring Dashboard

This document describes the implementation of adaptive rate limiting based on system load and the admin monitoring dashboard for issue #90.

## Features Implemented

### 1. Adaptive Rate Limiting Based on System Load

The system now dynamically adjusts rate limits based on real-time CPU and memory usage:

- **CPU Monitoring**: Tracks CPU usage percentage and load average
- **Memory Monitoring**: Monitors heap and system memory usage
- **Adaptive Multiplier**: Automatically adjusts rate limits using a multiplier (0.1x to 2.0x)
- **Safe Intervals**: Adaptive checks run every 30 seconds to avoid performance impact
- **Configurable Thresholds**: CPU and memory thresholds are configurable via environment variables

#### How It Works

1. **System Health Monitoring**: The `EnhancedSystemHealthService` continuously monitors system metrics
2. **Load Detection**: When CPU > 85% or Memory > 80%, the system reduces rate limits
3. **Recovery**: When load is low, rate limits gradually return to normal
4. **Multiplier Adjustment**: Uses a configurable adjustment factor (default: 0.1) for smooth transitions

#### Configuration

```env
# Enable adaptive rate limiting
ADAPTIVE_RATE_LIMITING_ENABLED=true

# Thresholds
ADAPTIVE_CPU_THRESHOLD=85
ADAPTIVE_MEMORY_THRESHOLD=80

# Adjustment settings
ADAPTIVE_ADJUSTMENT_FACTOR=0.1
ADAPTIVE_MIN_MULTIPLIER=0.1
ADAPTIVE_MAX_MULTIPLIER=2.0

# Base limits
ADAPTIVE_BASE_LIMIT=100
ADAPTIVE_MAX_LIMIT=1000
ADAPTIVE_MIN_LIMIT=10
```

### 2. Rate-Limiting Analytics & Monitoring Dashboard

A secure admin-only dashboard provides real-time insights into rate limiting:

#### Endpoints

- `GET /admin/rate-limit/stats` - Get comprehensive rate limit statistics
- `GET /admin/rate-limit/system/health` - Get current system health metrics
- `GET /admin/rate-limit/adaptive/status` - Get adaptive rate limiting status

#### Protected Access

All endpoints are protected with:
- JWT Authentication (`JwtAuthGuard`)
- Admin Role Authorization (`AdminGuard`)

#### Response Data

The `/admin/rate-limit/stats` endpoint returns:

```json
{
"systemMetrics": {
"totalUsers": 150,
"totalRequests": 12500,
"totalDeniedRequests": 45,
"averageCpuLoad": 65.2,
"averageMemoryLoad": 72.8,
"averageAdaptiveMultiplier": 0.85,
"currentSystemMetrics": {
"cpuUsage": 68.5,
"memoryUsage": 75.2,
"systemLoad": 1.2,
"cores": 8
}
},
"userStats": [
{
"userId": 123,
"key": "user:123",
"bucketSize": 100,
"refillRate": 10,
"tokensLeft": 85,
"lastRequestTime": "2024-01-15T10:30:00Z",
"deniedRequests": 2,
"totalRequests": 45,
"systemCpuLoad": 68.5,
"systemMemoryLoad": 75.2,
"adaptiveMultiplier": 0.85,
"createdAt": "2024-01-15T09:00:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
],
"timestamp": "2024-01-15T10:30:00Z"
}
```

## Architecture

### Core Components

1. **EnhancedSystemHealthService**: Monitors CPU, memory, and system load
2. **RateLimitMetricsStore**: In-memory store for rate limiting metrics
3. **AdminRateLimitController**: Admin-only endpoints for monitoring
4. **AdminGuard**: Role-based authorization for admin endpoints
5. **Enhanced RateLimitService**: Integrates adaptive logic and metrics recording

### Data Flow

1. **Request Processing**:
```
Request → RateLimitGuard → RateLimitService → Adaptive Logic → Metrics Recording
```

2. **System Monitoring**:
```
SystemHealthService → CPU/Memory Monitoring → Adaptive Multiplier → Rate Limit Adjustment
```

3. **Admin Dashboard**:
```
Admin Request → JWT Auth → Admin Role Check → Metrics Retrieval → Dashboard Response
```

## Performance Considerations

- **Memory Usage**: Metrics store limited to 10,000 entries with automatic cleanup
- **CPU Impact**: System monitoring runs every 30 seconds with minimal overhead
- **Storage**: In-memory storage for fast access with 24-hour retention
- **Scalability**: Designed to handle high-traffic scenarios with configurable limits

## Security Features

- **Admin-Only Access**: All monitoring endpoints require admin role
- **JWT Authentication**: Secure token-based authentication
- **Role-Based Authorization**: Explicit admin role checking
- **Input Validation**: Comprehensive DTO validation for all endpoints
- **Rate Limiting**: Admin endpoints also respect rate limits

## Usage Examples

### Enable Adaptive Rate Limiting

```typescript
// In your .env file
ADAPTIVE_RATE_LIMITING_ENABLED=true
ADAPTIVE_CPU_THRESHOLD=85
ADAPTIVE_MEMORY_THRESHOLD=80
```

### Access Admin Dashboard

```bash
# Get all rate limit statistics
curl -H "Authorization: Bearer YOUR_ADMIN_JWT" \
http://localhost:3000/admin/rate-limit/stats

# Get system health
curl -H "Authorization: Bearer YOUR_ADMIN_JWT" \
http://localhost:3000/admin/rate-limit/system/health

# Get adaptive status
curl -H "Authorization: Bearer YOUR_ADMIN_JWT" \
http://localhost:3000/admin/rate-limit/adaptive/status
```

### Filter by User

```bash
# Get stats for specific user
curl -H "Authorization: Bearer YOUR_ADMIN_JWT" \
"http://localhost:3000/admin/rate-limit/stats?userId=123&limit=50"
```

## Testing

Run the test suite to verify functionality:

```bash
npm test -- --testPathPattern=adaptive-rate-limit
```

The test suite covers:
- Adaptive rate limiting logic
- System health monitoring
- Metrics recording and retrieval
- Admin endpoint security

## Monitoring and Alerting

The system provides comprehensive monitoring capabilities:

- **Real-time Metrics**: Live system health and rate limiting statistics
- **Historical Data**: 24-hour retention of metrics for trend analysis
- **Load Detection**: Automatic detection of high system load
- **Adaptive Response**: Dynamic rate limit adjustment based on system conditions

## Future Enhancements

Potential improvements for future iterations:

1. **Database Storage**: Persistent storage for historical metrics
2. **Advanced Analytics**: Trend analysis and predictive rate limiting
3. **Custom Thresholds**: Per-user or per-endpoint adaptive thresholds
4. **Integration**: Prometheus/Grafana integration for advanced monitoring
5. **Machine Learning**: ML-based load prediction and rate limit optimization
76 changes: 38 additions & 38 deletions BACKUP_RESTORE.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Backup Restoration Procedures

This guide explains how to restore database and configuration backups created by the automated backup system.

## Prerequisites
- Access to the backup `.enc` files (encrypted and compressed)
- The AES-256 encryption key used for backup (see your config)
- `openssl`, `gunzip`, and `psql` (for database restore)

## 1. Locate the Backup File
Find the desired backup file in your backup directory (e.g., `backups/db-backup-YYYY-MM-DDTHH-MM-SS.sql.gz.enc`).

## 2. Decrypt the Backup
Replace `<ENCRYPTION_KEY>` and `<BACKUP_FILE>` with your values:

```
openssl enc -d -aes-256-cbc -K $(echo -n '<ENCRYPTION_KEY>' | xxd -p) -iv 00000000000000000000000000000000 -in <BACKUP_FILE> -out decrypted.gz
```

## 3. Decompress the Backup
```
gunzip decrypted.gz
```
This will produce a `.sql` file (for database) or `.ts` file (for config).

## 4. Restore the Database
```
psql <DATABASE_URL> < decrypted.sql
```
Replace `<DATABASE_URL>` with your PostgreSQL connection string.

## 5. Restore the Configuration
Replace your config file with the decompressed `.ts` file as needed.

## Notes
- Always verify the integrity of the restored data.
- Never share your encryption key.
- For production, test the restore process regularly.
# Backup Restoration Procedures
This guide explains how to restore database and configuration backups created by the automated backup system.
## Prerequisites
- Access to the backup `.enc` files (encrypted and compressed)
- The AES-256 encryption key used for backup (see your config)
- `openssl`, `gunzip`, and `psql` (for database restore)
## 1. Locate the Backup File
Find the desired backup file in your backup directory (e.g., `backups/db-backup-YYYY-MM-DDTHH-MM-SS.sql.gz.enc`).
## 2. Decrypt the Backup
Replace `<ENCRYPTION_KEY>` and `<BACKUP_FILE>` with your values:
```
openssl enc -d -aes-256-cbc -K $(echo -n '<ENCRYPTION_KEY>' | xxd -p) -iv 00000000000000000000000000000000 -in <BACKUP_FILE> -out decrypted.gz
```
## 3. Decompress the Backup
```
gunzip decrypted.gz
```
This will produce a `.sql` file (for database) or `.ts` file (for config).
## 4. Restore the Database
```
psql <DATABASE_URL> < decrypted.sql
```
Replace `<DATABASE_URL>` with your PostgreSQL connection string.
## 5. Restore the Configuration
Replace your config file with the decompressed `.ts` file as needed.
## Notes
- Always verify the integrity of the restored data.
- Never share your encryption key.
- For production, test the restore process regularly.
30 changes: 15 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Stage 1: Build
FROM node:18-alpine3.19 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:18-alpine3.19 AS production
WORKDIR /app
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
EXPOSE 3000
# Stage 1: Build
FROM node:18-alpine3.19 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
RUN npm run build
# Stage 2: Production
FROM node:18-alpine3.19 AS production
WORKDIR /app
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/main.js"]
Loading
Loading