Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added scripts/redis-backup.sh
Empty file.
79 changes: 79 additions & 0 deletions src/Hospital-Infracstructure-Setup/# .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Hospital Management System Environment Variables

# Database Configuration
DB_PASSWORD=your_secure_database_password_here
POSTGRES_PASSWORD=your_secure_database_password_here

# Redis Configuration
REDIS_PASSWORD=your_secure_redis_password_here

# Application Security
JWT_SECRET=your_jwt_secret_key_here
ENCRYPTION_KEY=your_32_character_encryption_key_here

# Monitoring
GRAFANA_PASSWORD=your_grafana_admin_password_here

# Backup Configuration
BACKUP_ENCRYPTION_PASSPHRASE=your_backup_encryption_passphrase_here

# SSL Certificate paths (generate before deployment)
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
# -keyout certs/server.key -out certs/server.crt

---
# Setup Instructions

## 1. Initial Setup
```bash
# Create required directories
sudo mkdir -p /opt/hospital/{data/{postgres,redis},backups/{postgres,redis},logs}
sudo chown -R $USER:$USER /opt/hospital

# Create certificate directory
mkdir -p certs

# Generate SSL certificates
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout certs/server.key -out certs/server.crt \
-subj "/C=US/ST=State/L=City/O=Hospital/CN=hospital.local"

# Copy environment file and configure
cp .env.example .env
# Edit .env with your secure passwords
```

## 2. Deploy the System
```bash
# Build and start all services
docker-compose up -d

# Verify all services are healthy
docker-compose ps

# Check logs
docker-compose logs -f hospital-app
```

## 3. Access Points
- Hospital App: https://localhost (redirects to HTTPS)
- Grafana Monitoring: http://localhost:3001
- Prometheus: http://localhost:9090
- AlertManager: http://localhost:9093

## 4. Security Features
- PostgreSQL with TLS encryption and SCRAM-SHA-256 authentication
- Row-level security and audit logging
- Redis with password authentication
- Automated encrypted backups
- SSL/TLS termination at proxy level
- Security headers and rate limiting

## 5. Monitoring Features
- Application metrics and health checks
- Database performance monitoring
- System resource monitoring
- Medical-grade alerting with email notifications
- Automated backup verification

This configuration provides a production-ready hospital management system with enterprise-grade security, monitoring, and backup capabilities.
40 changes: 40 additions & 0 deletions src/Hospital-Infracstructure-Setup/# monitoring/alertmanager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
global:
smtp_smarthost: 'localhost:587'
smtp_from: 'alerts@hospital.local'

route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'medical-alerts'
routes:
- match:
severity: critical
receiver: 'critical-medical-alerts'

receivers:
- name: 'medical-alerts'
email_configs:
- to: 'admin@hospital.local'
subject: 'Hospital System Alert: {{ .GroupLabels.alertname }}'
body: |
Alert: {{ .GroupLabels.alertname }}
Severity: {{ .CommonLabels.severity }}
Instance: {{ .CommonLabels.instance }}
Summary: {{ .CommonAnnotations.summary }}
Description: {{ .CommonAnnotations.description }}

- name: 'critical-medical-alerts'
email_configs:
- to: 'critical@hospital.local'
subject: 'CRITICAL Hospital System Alert: {{ .GroupLabels.alertname }}'
body: |
CRITICAL ALERT - IMMEDIATE ACTION REQUIRED

Alert: {{ .GroupLabels.alertname }}
Instance: {{ .CommonLabels.instance }}
Summary: {{ .CommonAnnotations.summary }}
Description: {{ .CommonAnnotations.description }}

This is a critical medical system alert requiring immediate attention.
38 changes: 38 additions & 0 deletions src/Hospital-Infracstructure-Setup/# monitoring/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

rule_files:
- "hospital_alerts.yml"

alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093

scrape_configs:
- job_name: 'hospital-app'
static_configs:
- targets: ['hospital-app:3000']
metrics_path: '/metrics'
scrape_interval: 30s

- job_name: 'postgres'
static_configs:
- targets: ['postgres-exporter:9187']
scrape_interval: 30s

- job_name: 'redis'
static_configs:
- targets: ['redis-exporter:9121']
scrape_interval: 30s

- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
scrape_interval: 30s

- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
63 changes: 63 additions & 0 deletions src/Hospital-Infracstructure-Setup/# nginx/hospital.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
upstream hospital_app {
server hospital-app:3000;
}

server {
listen 80;
server_name hospital.local;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl http2;
server_name hospital.local;

ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

# Security headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';";

# Rate limiting
limit_req_zone $binary_remote_addr zone=hospital:10m rate=10r/m;
limit_req zone=hospital burst=20 nodelay;

location / {
proxy_pass http://hospital_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;

# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}

location /health {
access_log off;
proxy_pass http://hospital_app/health;
}

# Monitoring endpoints
location /metrics {
allow 172.20.0.0/16;
deny all;
proxy_pass http://hospital_app/metrics;
}
}
25 changes: 25 additions & 0 deletions src/Hospital-Infracstructure-Setup/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Multi-stage Dockerfile for NestJS Hospital Management System
FROM node:18-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force

FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:18-alpine AS production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nestjs -u 1001
WORKDIR /app
COPY --from=base /app/node_modules ./node_modules
COPY --from=build --chown=nestjs:nodejs /app/dist ./dist
COPY --from=build --chown=nestjs:nodejs /app/package*.json ./
USER nestjs
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node dist/health-check.js
CMD ["node", "dist/main.js"]
Loading