Deploy Serverless Dynamic Drought Module (DDM)

Interactive Web Mapping, npm Tooling, and GitHub Pages Deployment

ATNI Climate / DDM Engineering

Serverless Dynamic Drought Module: Architecture & Deployment

Overview & Repository Documents

Product Scope

  • Dynamic Drought Module (DDM): Embeddable, serverless interactive web map.
  • Hazards: Drought, wildfire, heat, and telemetry indicators across North America.
  • Stewardship: Built by ATNI Climate (Affiliated Tribes of Northwest Indians).
  • Maintenance: Zero telemetry and zero backend upkeep.

Core Documentation

  • README.md: Product scope, hazards, iframe embedding.
  • DEVELOPER.md: Layer contracts, data pipelines, test ladders.
  • ROADMAP.md: Phases, branch posture, decision registers.
  • EXPLAIN_NPM.md: Reference guide on npm, Vite, and Pages.

The Paradigm: Server-Driven vs. Static Web Apps

Why can a complex mapping application run on GitHub Pages without a server?

Server-Driven (Shiny / Streamlit)

  • Requires an active R or Python server running 24/7.
  • Server re-calculates data and re-renders plots on every user interaction.
  • Scaling requires provisioning CPU, RAM, and managing worker processes.
  • Fails if the server backend crashes.

Static Client-Side (DDM on Pages)

  • Zero application backend.
  • TypeScript is pre-compiled into static HTML, JavaScript, and CSS.
  • Client GPU renders map vectors via WebGL (MapLibre GL JS).
  • Hosted cheaply and reliably on GitHub Pages’ global CDN.
  • Fetches static vector tiles (.pmtiles) via HTTP range requests.

High-Level System Architecture

%%{init: {
  'theme': 'default',
  'themeVariables': {
    'fontSize': '16px',
    'fontFamily': 'Inter, system-ui, sans-serif'
  },
  'flowchart': {
    'rankSpacing': 36,
    'nodeSpacing': 20,
    'padding': 12,
    'curve': 'basis'
  }
}}%%
flowchart LR
    %% Left: Source
    Dev(["💻 <b>Map Source</b><ul><li>MapLibre UI & signals<li>Layer styles & configs</ul>"])

    %% Top Track: Build & Edge CDN
    subgraph ColBuild ["Build & Edge CDN"]
        direction LR
        Build(["⚙️ <b>Vite + npm Engine</b><ul><li>Strict tsc typecheck<li>Minifies & chunks assets</ul>"])
        CDN{{"🌐 <b>GitHub Pages Edge</b><ul><li>Global HTTPS CDN<li>HTTP Range-request support</ul>"}}
        Build ==>|compiles| CDN
    end

    %% Bottom Track: Community & Telemetry
    subgraph ColData ["Community & Telemetry"]
        direction LR
        Tribal(["🌲 <b>Tribal Climate Partners</b><ul><li>Co-design requirements<li>Hazard indicator zones</ul>"])
        Feeds[("📡 <b>Live Remote Feeds</b><ul><li>USGS streamflow telemetry<li>NIFC wildfire & BCWS<li>NOAA drought</ul>")]
        Tribal ==>|metrics & zones| Feeds
    end

    %% Right: Client WebGL Execution
    Browser(["🖥️ <b>Visitor Browser</b><ul><li>MapLibre GL JS (WebGL GPU)<li>Streams .pmtiles & remote COGs<li>Serverless, zero upkeep</ul>"])

    %% Connections from Dev
    Dev ==>|npm run build| Build
    Dev ==>|partner alignment| Tribal

    %% Connections from CDN and ColData to Browser
    CDN ==>|streams bundle & tiles| Browser
    Feeds ==>|direct browser queries| Browser

    %% Closed loop feedback
    Browser -.->|field insights & telemetry| Dev

    %% Subgraph Styling
    style ColBuild fill:none,stroke:#6366f1,stroke-width:1.5px,stroke-dasharray: 4 4,rx:12,ry:12
    style ColData fill:none,stroke:#3b82f6,stroke-width:1.5px,stroke-dasharray: 4 4,rx:12,ry:12

    %% Node Styling
    style Dev fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc
    style Build fill:#1e1e38,stroke:#818cf8,stroke-width:2px,color:#f8fafc
    style CDN fill:#0f2937,stroke:#2dd4bf,stroke-width:2px,color:#f8fafc
    style Browser fill:#0d3326,stroke:#34d399,stroke-width:2px,color:#f8fafc
    style Feeds fill:#382414,stroke:#fb923c,stroke-width:2px,color:#f8fafc
    style Tribal fill:#27272a,stroke:#a1a1aa,stroke-width:2px,color:#f8fafc

Tooling Rosetta Stone: Runtime & Package Management

Coming from Python (pip/conda) or R (renv/devtools)? Here is the package management mapping:

Tool / File Purpose Python / R Equivalent Role in DDM
Node.js JS runtime outside browser python3 / R runtime Executes build scripts and tests
.nvmrc Pins Node version pyenv (.python-version) / .Rversion Enforces exact Node 24.20.0
npm Package & script manager pip + poetry / renv Manages dependencies & tasks
package.json Project manifest pyproject.toml / DESCRIPTION Defines metadata, deps & scripts
package-lock.json Cryptographic lockfile poetry.lock / renv.lock Guarantees exact dependency tree
npm ci Deterministic install pip install --no-deps / renv::restore() Clean install strictly from lockfile

Tooling Rosetta Stone: Build & Testing Engines

Mapping compilation, bundling, and browser automation to familiar ecosystems:

Tool / File Purpose Python / R Equivalent Role in DDM
TypeScript Static type checking mypy / Type annotations Catches type bugs at build time
Vite Dev server & bundler Webpack / Quarto (pkgdown) Fast HMR & production bundler
Playwright Browser automation pytest-playwright / shinytest2 Headless browser integration tests

Web Tooling Philosophy

Just as renv.lock guarantees R environment reproducibility across collaborators, package-lock.json and .nvmrc eliminate “works on my machine” differences in modern web applications.

Core Configuration: .nvmrc & package.json

1. Node LTS & Dependencies

  • Pinned Version (.nvmrc):
    • Pins Node 24.20.0 (Active LTS).
    • Enforced in local shells (nvm use) and CI (actions/setup-node).
  • Runtime Dependencies (package.json):
    • maplibre-gl: WebGL mapping engine.
    • pmtiles: Cloud-optimized vector tile reader.
    • @preact/signals: Fine-grained reactive UI state.

2. Key npm Task Scripts

  • npm run dev:
    • Local Vite dev server with instant HMR at http://localhost:5173.
  • npm run build:
    • Static typecheck (tsc) and bundle to dist/.
  • npm run preview:
    • Serves dist/ bundle locally at http://localhost:4173.
  • npm run gate:
    • Comprehensive gate: builds, budgets, contracts, and tests.

Bundling & Optimization: vite.config.ts

Key architectural decisions configured in vite.config.ts:

Relative URLs & Stamping

  • Relative Asset URLs (base: './'):
    • Runs seamlessly at domain root, on Pages subpaths (/dynamic-drought-module/), or inside an <iframe>.
  • Build Stamping (DDM_BUILD_SHA):
    • Embeds Git SHA & nonce into the DOM.
    • Allows tests and monitoring to verify the live commit.

Vendor Chunk Splitting

  • Cache Isolation:
    • Isolates maplibre-gl (~800 kB) and pmtiles into separate vendor chunks.
  • Client Cache Preservation:
    • Daily app code updates do not re-download unchanged geospatial engines.
  • Tree-Shaking:
    • Dead code elimination strips unused dependencies from production bundle.

Local Developer Verification Ladder

Verification Ladder

# 1. Clean installation matching lockfile
npm ci

# 2. Interactive dev with instant HMR
npm run dev

# 3. Fast syntax & typecheck (~5s)
npm run verify:quick

# 4. Deterministic quality gate (~40s)
npm run gate

# 5. Full serial browser test suite
npm run test:serial

Quality Principles

  • Local-First Verification:
    • Catch errors before pushing to avoid broken CI.
  • Tiered Feedback Loops:
    • Fast feedback (verify:quick), deep gating (gate).

The Gate Rule

Always run npm run gate before pushing. It validates bundle sizes, budgets, and schema contracts.

GitHub Actions Deployment Pipeline

The workflow in .github/workflows/deploy.yml orchestrates builds and deployments on pushes to main:

flowchart LR
    Push["Push to 'main' Branch<br/>(paths-ignore docs)"] --> Concurrency["Concurrency Gate<br/>group: pages"]

    subgraph DeployWorkflow["deploy.yml (GitHub Actions)"]
        direction TB
        subgraph BuildJob["Job: build (Gate & Build)"]
            direction TB
            Setup["Set up Node 24.20.0<br/>& npm ci"]
            Gate["npm run gate<br/>• tsc typecheck<br/>• vite build (dist/)<br/>• Budgets, tests & strip:sourcemaps"]
            UploadArtifact["actions/upload-pages-artifact<br/>(Publish package)"]
            Setup --> Gate --> UploadArtifact
        end

        subgraph DeployJob["Job: deploy (Pages)"]
            direction TB
            HeadCheck["Confirm HEAD of main"]
            DeployPages["actions/deploy-pages<br/>• Write to CDN (30s retry)"]
            HeadCheck --> DeployPages
        end

        subgraph BrowserJob["Job: browser (Advisory)"]
            direction TB
            Playwright["Playwright Browser Suite<br/>• 8 parallel shards<br/>• Advisory on main"]
        end

        BuildJob -->|needs: build| DeployJob
        BuildJob -.->|parallel advisory| BrowserJob
    end

    subgraph VerifyWorkflow["verify-live.yml (Post-Deploy Proof)"]
        direction TB
        LiveProof["Probe Live Site<br/>• SHA & nonce match<br/>• PMTiles byte-range (206)<br/>• Live browser smoke tests<br/>• File divergence on fail"]
    end

    Concurrency --> BuildJob
    DeployJob ==>|triggers on success| VerifyWorkflow

Release Evidence & Live Verification

In DDM, a merged commit is not proof of a successful release.

1. Proof of Live Deployment

  • Build Nonce & SHA Check:
    • Probes live DOM dataset.ddmBuildSha.
    • Confirms the CDN actively serves the exact commit, not a stale cache.
  • Byte-Range Capability:
    • Asserts HTTP 206 Partial Content on .pmtiles.
    • Ensures global CDN supports streaming tile slices without downloading entire archives.

2. Runtime Integrity & Alerting

  • Live Browser Smoke Boots:
    • Headless browser boots against production URL.
    • Validates initial view state, embed mode, and real-time layer loading.
  • Automated Issue Triage:
    • Automatically files or updates a tracked GitHub issue if live site diverges from commit HEAD.

Architectural Variations Across Projects

Choosing a Serverless Deployment Pattern

%%{init: {
  'theme': 'default',
  'themeVariables': {
    'fontSize': '15px',
    'fontFamily': 'Inter, system-ui, sans-serif'
  },
  'flowchart': {
    'rankSpacing': 32,
    'nodeSpacing': 16,
    'padding': 10,
    'curve': 'basis'
  }
}}%%
flowchart LR
    Start["Delivery Goal"] --> Q0{"Web<br/>Deploy?"}
    Q0 -->|No| Contrast["<b>Local Native CLI</b><br/>ocr-engine-next<br/>Rust + read-only CI guard"]
    Q0 -->|Yes| Q1{"Build<br/>Step?"}

    Q1 -->|No| ZeroA["<b>Pattern A: Direct /docs</b><br/>TieredSovereignDataFramework<br/>main:/docs"]
    Q1 -->|No + Isolated| ZeroB["<b>Pattern A+: Isolated site/</b><br/>TERRA<br/>Actions deploy site/"]

    Q1 -->|Python| PyB["<b>Pattern B: Local Python</b><br/>climate-curriculum<br/>build.py -> main:/docs"]
    Q1 -->|Python + CI Gate| PyC["<b>Pattern C: Gated site/</b><br/>atni-task-force<br/>validate_public.py -> site/"]

    Q1 -->|Node / Vite| NodeBase["<b>Baseline: Cloud CI/CD</b><br/>dynamic-drought-module<br/>Actions -> dist/ + verify-live"]
    Q1 -->|Node + API Keys| NodeD["<b>Pattern D: Edge Proxy</b><br/>policy-sentinel<br/>docs/ + Cloudflare Worker"]

    style Contrast fill:#f1f5f9,stroke:#64748b,stroke-width:2px,color:#0f172a
    style ZeroA fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0f172a
    style ZeroB fill:#e0f2fe,stroke:#0369a1,stroke-width:2px,color:#0f172a
    style PyB fill:#fef3c7,stroke:#d97706,stroke-width:2px,color:#0f172a
    style PyC fill:#fef3c7,stroke:#b45309,stroke-width:2px,color:#0f172a
    style NodeBase fill:#d1fae5,stroke:#059669,stroke-width:2px,color:#0f172a
    style NodeD fill:#eef2ff,stroke:#6366f1,stroke-width:2px,color:#0f172a

Zero-Build Patterns: Direct vs. Isolated Root

Pattern A: Zero-Build Direct

TieredSovereignDataFramework

  • Source: Vanilla HTML5, CSS3, and ES6 JS authored directly in docs/.
  • Deployment: Native GitHub Pages (main:/docs) — no GitHub Actions, no npm, no build runner.
  • Dependencies: Zero JS build dependencies (Google Fonts loaded externally).
  • Best For: Lightweight guides, decision trees, and instant zero-latency publishing.

Pattern A+: Zero-Build Isolated Root

TERRA

  • Source: Pure HTML/JS, self-hosted fonts, photography, and offline gzipped CesiumJS 3D terrain inside site/.
  • Isolation: Root .gitignore allowlist keeps planning docs, agent configs, and raw photos out of Git.
  • Deployment: .github/workflows/pages.yml deploys only path: site with site/.nojekyll (preserving site/iter/_kernel/).
  • External Embeds: Opt-in lazy <iframe data-load="..."> loads Policy Sentinel only on explicit click.

Local Python Generators: Native vs. CI-Gated

Pattern B: Local Python Generator

climate-curriculum

  • Build: python source/build.py injects SVG geometry into docs/index.html; tools/print_pdf.py & handout.py generate PDFs/HTML drafts in docs/downloads/ (unapproved drafts stay in git-ignored private/).
  • Local Gates: tools/check.py (zero external network calls, editorial style) + Playwright tools/probe.js (layout & a11y).
  • Deployment: Native GitHub Pages (main:/docs + docs/.nojekyll).
  • Benefit: 100% offline-capable for classrooms using browser localStorage.

Pattern C: Gated Isolated Root

atni-task-force

  • Build: scripts/rebuild_all.py compiles open Tier 0 claims, data plates, explorers, and briefing PDFs into site/.
  • Leak & Unit Gates: Local scripts/check_t1_leak.py scans site/ against git-ignored Tier 1 folders; .github/workflows/check.yml runs read-only pytest on PRs.
  • Deployment: .github/workflows/pages.yml runs scripts/validate_public.py (Python 3.12 + pymupdf) before actions/deploy-pages publishes path: site (site/.nojekyll).
  • Benefit: Enforces strict sovereign data boundaries before anything reaches public Pages.

Hybrid Edge Proxy & Local-Only Contrast

Pattern D: Static SPA + Edge Proxy

policy-sentinel

  • Frontend & Allowlist: npm run demo:build runs Vite (emptyOutDir: false) into docs/, preserving SHA-256 static shards (docs/demo-data/). finish-demo-build.mjs + check-pages-files.mjs enforce licenses, hashes, .nojekyll, and an exact file allowlist.
  • Cloudflare Worker (worker/wrangler.toml): Proxies keyed api.data.gov and unkeyed official endpoints via POST /api/search, injects DATA_GOV_API_KEY, enforces dual rate limits (RATE + KEY_RATE), and refuses HTTP redirects.
  • Audit: verify-demo-browser.mjs checks request budgets, axe WCAG, and PDF export.

Contrast: When Not to Deploy to Web

ocr-engine-next (private native Rust engine)

  • No GitHub Pages: Source documents never leave the user’s workstation — “deployment” is a local cargo build --workspace with SHA-256-verified pdfium.dll and Tesseract 5.
  • Read-Only CI (ci.yml): Uses permissions: contents: read — publishes nothing. Runs a sovereignty guard (verifying tracked files match synthetic fixture digests) + Cargo/cargo-deny gates.
  • Local Verification: ocr-cli doctor & ocr-cli preflight replace live web probes.

Comparative Architecture Matrix

Repository / Pattern Build Toolchain Publish Target & Method Key Gates & Data Model
DDM (Baseline) Node 24, npm, Vite, tsc (Cloud CI) Ephemeral dist/ via deploy.yml (OIDC) npm run gate, strip:sourcemaps, verify-live.yml; PMTiles, COGs, public APIs
TSDF (Pattern A) None (Zero-build vanilla HTML/JS) Tracked docs/ via native main:/docs Zero JS build deps; embedded static JSON & client-side DOM
TERRA (Pattern A+) None (Zero-build + offline CesiumJS) Tracked site/ via pages.yml (site/.nojekyll) Root .gitignore allowlist; gzipped 3D terrain & lazy <iframe>
Curriculum (Pattern B) Python (build.py, print_pdf.py, handout.py) Tracked docs/ via native main:/docs (.nojekyll) Local check.py & Playwright probe.js; 100% offline (localStorage)
Task Force (Pattern C) Python (rebuild_all.py) Tracked site/ via pages.yml (site/.nojekyll) validate_public.py, check_t1_leak.py, check.yml (pytest); T0/T1 boundary
Policy Sentinel (Pattern D) Vite (demo:build) + Wrangler Tracked docs/ (main:/docs) + Cloudflare Worker finish-demo-build.mjs, check-pages-files.mjs, verify-demo-browser.mjs; SHA-256 shards + edge proxy
OCR Engine (Contrast) Rust (cargo, clippy, cargo-deny) None — local native CLI binary Read-only CI sovereignty guard; ocr-cli doctor/preflight; zero network crates

Summary & Next Steps

Summary of Principles

  • Right-Size the Pipeline: Match complexity to need — from zero-build /docs to CI-gated site/, edge workers, or local-only native binaries.
  • Local-First & CI Verification: Fast local feedback loops backed by automated pre-deploy and live release checks.
  • Sovereign Stewardship: Enforce T0/T1 data boundaries, .nojekyll hygiene, and allowlists so sensitive drafts never leak to public CDNs.
  • Empirical Release Evidence: Automated verification of live CDN bytes, request budgets, and accessibility.

Further Reading