# 🌊 HADEX DEPLOYMENT GUIDE

This guide covers deployment options for the HADEX framework, including the live dashboard, API services, documentation, and real-time data pipelines.

---

## Quick Deployments

### Netlify (Dashboard)

The HADEX interactive dashboard is pre-configured for Netlify deployment at [hadex.netlify.app](https://hadex.netlify.app).

#### Automatic Deployment

1. Connect your Git repository to Netlify
2. Use these settings:
   - Build command: `mkdocs build`
   - Publish directory: `site`
   - Environment variables: none required

3. Or use the `netlify.toml` configuration:

```toml
[build]
  command = "mkdocs build"
  publish = "site"

[build.environment]
  PYTHON_VERSION = "3.11"
  MKDOCS_CONFIG = "mkdocs.yml"

[[redirects]]
  from = "/api/*"
  to = "https://hadex.netlify.app/api/:splat"
  status = 200
  force = true

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"
    X-XSS-Protection = "1; mode=block"
    X-Content-Type-Options = "nosniff"
    Access-Control-Allow-Origin = "https://hadex.netlify.app"
```

Manual Deployment

```bash
# Install Netlify CLI
npm install -g netlify-cli

# Deploy
netlify deploy --prod --dir=site
```

Live dashboard: https://hadex.netlify.app
API endpoint: https://hadex.netlify.app/api

---

ReadTheDocs (Documentation)

Deploy technical documentation to ReadTheDocs.

Configuration

1. Connect your Git repository to readthedocs.org
2. Use the .readthedocs.yaml configuration in this repository
3. Build documentation automatically on push

Documentation: https://hadex.readthedocs.io

---

PyPI (Python Package)

Deploy the core HADEX package to PyPI.

Preparation

```bash
# Install build tools
pip install build twine

# Update version in setup.py/pyproject.toml
# Version: 1.0.0

# Create distribution files
python -m build
```

Upload to PyPI

```bash
# Upload to production PyPI
twine upload dist/*

# Install
pip install hadex
```

PyPI package: https://pypi.org/project/hadex

---

Docker Deployment

Build Image

```dockerfile
# Dockerfile
FROM python:3.10-slim

LABEL maintainer="gitdeeper@gmail.com"
LABEL version="1.0.0"
LABEL description="HADEX - Hadal Abyss Dynamics & Extreme-Pressure Intelligence"

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HADEX_HOME=/opt/hadex \
    HADEX_CONFIG=/etc/hadex/config.yaml \
    TZ=UTC

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    g++ \
    libgomp1 \
    curl \
    && rm -rf /var/lib/apt/lists/*

RUN useradd -m -u 1000 -s /bin/bash hadex && \
    mkdir -p /opt/hadex && \
    mkdir -p /etc/hadex && \
    mkdir -p /data/bathymetry && \
    mkdir -p /data/sediment && \
    mkdir -p /data/ctd && \
    mkdir -p /data/results && \
    chown -R hadex:hadex /opt/hadex /etc/hadex /data

USER hadex
WORKDIR /opt/hadex

COPY --chown=hadex:hadex requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt

COPY --chown=hadex:hadex . .

RUN pip install --user -e .

EXPOSE 8000 8501 9090

CMD ["hadex", "serve", "--all"]
```

Build and Run

```bash
# Build image
docker build -t hadex:1.0.0 .

# Run container
docker run -d \
  --name hadex-prod \
  -p 8000:8000 \
  -p 8501:8501 \
  -p 9090:9090 \
  -v /host/data:/data \
  -v /host/config:/etc/hadex \
  -e HADEX_CONFIG=/etc/hadex/config.yaml \
  -e NOAA_BATHYMETRY_KEY=your_key_here \
  -e JAMSTEC_API_KEY=your_key_here \
  --restart unless-stopped \
  hadex:1.0.0
```

Docker Compose

Use the provided docker-compose.yml for full-stack deployment:

```bash
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down
```

---

Configuration

Production Configuration

```yaml
# config/hadex.prod.yaml
# HADEX Production Configuration

version: 1.0
environment: production

server:
  host: 0.0.0.0
  api_port: 8000
  dashboard_port: 8501
  metrics_port: 9090
  workers: 4
  timeout: 120

database:
  host: postgres
  port: 5432
  name: hadex
  user: hadex_user
  password: ${DB_PASSWORD}
  pool_size: 20
  hypertable_chunk: 7  # days

redis:
  host: redis
  port: 6379
  db: 0
  maxmemory: 512mb

monitoring:
  sensor_update_interval: 60  # seconds
  swarm_update_interval: 30   # seconds
  forecast_horizon: 24  # hours
  ensemble_members: 10
  metrics_enabled: true

security:
  jwt_secret: ${JWT_SECRET}
  jwt_expiry_hours: 24
  rate_limit: 100/minute
  cors_origins:
    - https://hadex.netlify.app
    - https://hadex.readthedocs.io

api:
  public_url: https://hadex.netlify.app/api
  docs_url: https://hadex.readthedocs.io/api
  version: v1

external_apis:
  noaa_bathymetry:
    url: https://www.ncei.noaa.gov/maps/bathymetry/
    api_key: ${NOAA_BATHYMETRY_KEY}
    
  jamstec:
    url: https://www.godac.jamstec.go.jp/
    api_key: ${JAMSTEC_API_KEY}
    endpoints:
      cruises: /darwin/cruise
      data: /darwin/data
    
  gebco:
    url: https://www.gebco.net/data_and_products/
    token: ${GEBCO_TOKEN}
    resolution: "15-arcsecond"
    
  iodp:
    url: https://web.iodp.tamu.edu/
    api_key: ${IODP_API_KEY}
    expeditions: all

data:
  bathymetry_dir: /data/bathymetry
  sediment_dir: /data/sediment
  ctd_dir: /data/ctd
  results_dir: /data/results
  max_file_size: 10GB
  retention_days:
    raw: 90
    hourly: 365
    daily: 730
    monthly: permanent

trenches:
  monitored:
    - name: "Mariana"
      depth: 10911
      coordinates: [11.373, 142.591]
    - name: "Tonga"
      depth: 10882
      coordinates: [-23.0, -174.0]
    - name: "Philippine"
      depth: 10540
      coordinates: [10.0, 126.0]
    - name: "Kermadec"
      depth: 10047
      coordinates: [-32.0, -177.0]
    - name: "Japan"
      depth: 9000
      coordinates: [40.0, 144.0]

alerts:
  levels:
    critical: 39
    warning: 59
    watch: 79
    caution: 94
  notification_endpoints:
    email: alerts@hadex.space
    webhook: https://hooks.slack.com/services/...
```

---

Real-Time Data Pipeline

Data Sources Configuration

```yaml
# config/data_sources.yaml
sources:
  gebco:
    type: ftp
    url: ftp://ftp.gebco.net/
    interval: 86400  # daily
    format: netcdf
    resolution: "15s"
    
  noaa_ctd:
    type: rest_api
    url: https://www.ncei.noaa.gov/access/
    interval: 3600  # hourly
    format: json
    parameters:
      - temperature
      - salinity
      - pressure
      - depth
      
  jamstec:
    type: rest_api
    url: https://www.godac.jamstec.go.jp/
    interval: 86400
    format: json
    datasets:
      - cruise
      - sediment
      - ctd
      
  iodp:
    type: ftp
    url: ftp://web.iodp.tamu.edu/
    interval: 604800  # weekly
    format: csv
    expeditions:
      - 386  # Japan Trench
      - 352  # Izu-Bonin
```

Data Ingestion Service

```bash
# Start data ingestion service
hadex ingest --config config/data_sources.yaml --daemon

# Monitor ingestion status
hadex status --sources all

# Force update for specific trench
hadex update --trench mariana --force
```

---

Swarm Deployment

Vehicle Configuration

```yaml
# config/swarm.yaml
swarm:
  vehicles: 12
  type: "nano-AUV"
  depth_rating: 11000  # meters
  
  specifications:
    hull_material: "ceramic-matrix composite"
    dimensions: [0.45, 0.18, 0.18]  # meters
    mass_in_water: 8.2  # kg
    cruise_speed: 0.25  # m/s
    max_speed: 0.5  # m/s
    
  sensors:
    - type: "oxygen_microsensor"
      resolution: 1  # μM
    - type: "bioluminescence_detector"
      range: [400, 600]  # nm
    - type: "pressure_sensor"
      range: [0, 120]  # MPa
    - type: "acoustic_transceiver"
      frequency: 12000  # Hz
      accuracy: 0.5  # ms
      
  energy:
    battery: 180  # Wh (Li-ion)
    endurance: 72  # hours
    harvester:
      type: "piezoelectric"
      area: 10  # cm²
      material: "PZT-5H"
      expected_power: 3.2  # mW
      
  navigation:
    algorithm: "cooperative_acoustic"
    accuracy_target: 0.8  # meters RMS
    update_frequency: 30  # seconds
    max_range: 500  # meters
```

Swarm Launch

```bash
# Initialize swarm
hadex swarm init --config config/swarm.yaml

# Deploy to trench
hadex swarm deploy --trench mariana --depth 10911

# Monitor swarm status
hadex swarm status --vehicles all

# Retrieve swarm data
hadex swarm download --output /data/swarm_mission.json
```

---

Backup & Recovery

Automated Backup Script

```bash
#!/bin/bash
# backup.sh - HADEX Backup Script

DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backups/hadex"

# Create backup directory
mkdir -p $BACKUP_DIR

# Database backup (TimescaleDB)
pg_dump -h postgres -U hadex_user hadex | gzip > $BACKUP_DIR/db_$DATE.sql.gz

# Bathymetry data backup
tar -czf $BACKUP_DIR/bathymetry_$DATE.tar.gz /data/bathymetry

# Sediment core data backup
tar -czf $BACKUP_DIR/sediment_$DATE.tar.gz /data/sediment

# CTD profiles backup
tar -czf $BACKUP_DIR/ctd_$DATE.tar.gz /data/ctd

# Configuration backup
tar -czf $BACKUP_DIR/config_$DATE.tar.gz /etc/hadex

# Results backup
tar -czf $BACKUP_DIR/results_$DATE.tar.gz /data/results

# Clean old backups (keep 30 days)
find $BACKUP_DIR -type f -mtime +30 -delete

# Upload to cloud (optional)
# aws s3 sync $BACKUP_DIR s3://hadex-backups/

echo "Backup completed: $DATE"
```

Cron Setup

```bash
# Daily backup at 2 AM
0 2 * * * /usr/local/bin/hadex-backup.sh

# Hourly database snapshot
0 * * * * /usr/local/bin/hadex-snapshot.sh
```

Recovery

```bash
# Restore database
gunzip -c db_20260306_020000.sql.gz | psql -h postgres -U hadex_user hadex

# Restore data files
tar -xzf bathymetry_20260306_020000.tar.gz -C /data
```

---

Monitoring

Prometheus Configuration

```yaml
# prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'hadex-api'
    static_configs:
      - targets: ['api:8000']
    metrics_path: /metrics
    scrape_interval: 10s
    
  - job_name: 'hadex-dashboard'
    static_configs:
      - targets: ['dashboard:8501']
    metrics_path: /metrics
    
  - job_name: 'hadex-swarm'
    static_configs:
      - targets: ['swarm:9090']
    
  - job_name: 'postgres'
    static_configs:
      - targets: ['postgres:9187']
```

Grafana Dashboard

Import the HADEX dashboard template (ID: 12346) to visualize:

· Real-time hadal parameters with 1-minute resolution
· 8-parameter composite HADEX index
· Swarm navigation accuracy and vehicle positions
· Pressure, temperature, and density profiles
· Oxygen flux maps of benthic zones
· Turbidity current detection and tracking
· Bioluminescence event mapping
· Energy harvesting status
· Alert status (5-tier)
· System health metrics
· Data ingestion latency
· Trench comparison views

Alerting Rules

```yaml
# alerts/hadex.rules.yml
groups:
  - name: hadex_critical
    rules:
      - alert: HADEXCritical
        expr: hadex_index < 40
        for: 5m
        annotations:
          summary: "HADEX Index in CRITICAL range (<40%)"
          description: "Extreme pressure fluctuations detected"
          
      - alert: SwarmPositionDrift
        expr: swarm_accuracy > 5.0
        for: 10m
        annotations:
          summary: "Swarm position drift >5m"
          
      - alert: PressureAnomaly
        expr: pressure_amplitude > 2000
        for: 5m
        annotations:
          summary: "Pressure fluctuation >2kPa detected"
          
      - alert: TurbidityCurrent
        expr: ttc_velocity > 1.5
        for: 15m
        annotations:
          summary: "Turbidity current >1.5 m/s detected"
          
      - alert: EnergyLow
        expr: peh_power < 1.0
        for: 30m
        annotations:
          summary: "Energy harvesting below 1mW"
```

---

Scaling

Horizontal Scaling

```yaml
# docker-compose.scale.yml
version: '3.8'

services:
  api:
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: '2'
          memory: 4G
          
  swarm-processor:
    deploy:
      replicas: 2
      resources:
        limits:
          cpus: '4'
          memory: 8G
          
  redis:
    image: redis:7-alpine
    command: redis-server --cluster-enabled yes
```

Load Balancing

```nginx
# nginx.conf
upstream hadex_api {
    least_conn;
    server api1:8000;
    server api2:8000;
    server api3:8000;
}

upstream hadex_dashboard {
    server dashboard1:8501;
    server dashboard2:8501;
}

server {
    listen 443 ssl;
    server_name hadex.netlify.app;
    
    location /api/ {
        proxy_pass http://hadex_api/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    location / {
        proxy_pass http://hadex_dashboard/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```

---

Quick Reference

```bash
# Netlify Dashboard
https://hadex.netlify.app
https://hadex.netlify.app/api

# PyPI Package
pip install hadex

# Docker
docker pull gitlab.com/gitdeeper8/hadex:latest

# Documentation
https://hadex.readthedocs.io

# Source Code
https://gitlab.com/gitdeeper8/HADEX
https://github.com/gitdeeper8/HADEX

# Data Sources
https://www.gebco.net
https://www.jamstec.go.jp
https://www.iodp.org
https://www.ncei.noaa.gov
```

---

Support

For deployment assistance:

· Dashboard: https://hadex.netlify.app
· Documentation: https://hadex.readthedocs.io
· Issues: https://gitlab.com/gitdeeper8/HADEX/-/issues
· Email: deploy@hadex.space
· Principal Investigator: gitdeeper@gmail.com

---

🌊 The hadal zone is Earth's final frontier. HADEX illuminates the abyss.

DOI: 10.5281/zenodo.18883858
