# mrcanofcatfood/sdm-dashboard-fork architecture

> Architecture diagram of the GitHub repository mrcanofcatfood/sdm-dashboard-fork, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrcanofcatfood/sdm-dashboard-fork
- Repository: https://github.com/mrcanofcatfood/sdm-dashboard-fork

## Overview

1. **Overall shape**
   - This is a **local R/Shiny application** for species distribution modelling (SDM), with a second **non-interactive pipeline/CLI path** for batch execution.
   - The repo is organized around a central modelling workflow: ingest occurrence data, build covariates, fit multiple model backends, evaluate, project, and export results.

2. **Top-level entry points**
   - `app.R` launches the interactive Shiny dashboard.
   - `launch_app.R` is a convenience launcher that starts the app and opens a browser.
   - `pipeline.R` runs the same core workflow headlessly for scripted execution.
   - `scripts/batch_run.R` and related scripts support repeatable batch processing and release automation.

3. **Core orchestration layer**
   - `R/core/` contains the control plane: configuration, bootstrap, logging, validation, and the main `run_sdm` orchestration.
   - This layer is the main boundary between UI/pipeline callers and the modelling engine.
   - It likely coordinates stage order, handles readiness checks, and routes settings into the modelling and output subsystems.

4. **Data ingestion and occurrence handling**
   - `R/data/` handles occurrence records, including general occurrence loading and Darwin Core Archive parsing.
   - The app accepts local CSV input, DwCA archives, and GBIF-derived records, with cleaning and validation before modelling.
   - The README indicates coordinate cleaning, thinning, and source summaries are part of this layer’s responsibility.

5. **Covariate subsystem**
   - `R/covariates/` is responsible for environmental predictor acquisition, caching, stacking, and selection.
   - It covers WorldClim climate layers, elevation, soil, NDVI, vegetation, drought, UV, human footprint, land-use/land-cover, future climate projections, and predictor selection/VIF filtering.
   - This is the main data-preparation boundary where external raster services and local cached rasters enter the workflow.

6. **Modeling engine**
   - `R/models/` is the algorithm registry and training/prediction layer.
   - It includes stable backends such as GLM, GAM, MaxNet, Random Forest, XGBoost, ESM variants, multi-ensemble, plus conditional or legacy paths like DNN, JSDM, rangebag, and biomod2 integration.
   - Cross-validation, calibration, tuning, permutation importance, prediction, and ensemble logic live here, so this folder is the core computational subsystem.

7. **Ecology and post-model analytics**
   - `R/ecology/` contains derived analyses that consume fitted models or suitability surfaces.
   - Functions here cover climate matching, EOO/AOO, AOA, niche overlap, species richness stacking, dispersal simulation, CLIMEX import, extrapolation/MESS-style checks, and range-size change.
   - These are downstream analytical products, separate from model fitting itself.

8. **Shiny UI composition**
   - `R/ui/` defines the dashboard shell: header, main tabs, sidebar controls, and Leaflet-related plugins.
   - `R/modules/` splits the app into screen-level units such as data acquisition, model execution, readiness checks, and results display.
   - The architecture is a modular Shiny app rather than a monolithic server script, which matters for diagramming user interactions and state flow.

9. **Output and reporting**
   - `R/output/` converts model and ecology results into user-facing deliverables: metrics, plots, response curves, manifests, reports, ODMAP output, and script export.
   - This layer is the final transformation boundary from in-memory analysis objects into files, summaries, and reproducible artifacts.
   - The repository also supports batch summaries and structured run logs, which suggests output is designed for both interactive review and offline auditability.

10. **Client-side state and presentation**
   - `www/` holds browser assets such as CSS and JavaScript for theming, settings persistence, and map/plugin behavior.
   - These assets affect UI state management, but not core modelling logic.
   - The app appears to persist some preferences locally in the browser, so user settings are partly client-side and partly server-side.

11. **Execution model and background work**
   - The app supports long-running model runs without blocking the UI, with a cancelable background execution path referenced in the README.
   - That implies a separation between interactive Shiny event handling and asynchronous job execution, likely mediated through process isolation rather than a single synchronous request cycle.
   - This is important for architecture diagrams because “model run” is not just a UI action; it is a separate execution lane.

12. **External dependencies and services**
   - Key external inputs include **GBIF** for occurrence acquisition, **WorldClim** for climate rasters, **OpenTopography** for elevation, and optional user-provided future climate layers and soil rasters.
   - The app depends on a substantial R geospatial/modeling stack, especially packages like `terra`, `shiny`, `leaflet`, `mgcv`, `maxnet`, `ranger`, `xgboost`, `ecospat`, `blockCV`, and optionally `torch`/`cito`, `Hmsc`, and `biomod2`.
   - These dependencies materially shape runtime requirements, especially on desktop, Windows, and Docker.

13. **Operational boundaries**
   - Generated artifacts and sensitive working data are intentionally kept out of version control: outputs, caches, downloaded rasters, logs, and API keys are local-only.
   - The repo is meant to be run as a **desktop-friendly local analysis environment**, not as a hosted multi-user service.
   - Docker and Windows launcher support are packaging layers around the same local architecture, not separate application tiers.

Main entry points: [`R/core/run_sdm.R`](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/run_sdm.R) (run_sdm), [`app.R`](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/app.R) (app.R), [`R/models/prediction.R`](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/prediction.R) (Prediction), [`R/modules/mod_model_run.R`](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/modules/mod_model_run.R) (Modules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_app["app.R<br/>shiny entry<br/>[app.R]"]
  node_launch_app["launch_app.R<br/>launcher<br/>[launch_app.R]"]
  node_pipeline["pipeline.R<br/>batch entry<br/>[pipeline.R]"]
  node_batch_run["batch_run.R<br/>batch script<br/>[batch_run.R]"]
end

subgraph group_core["Core orchestration"]
  node_run_sdm["run_sdm<br/>orchestrator<br/>[run_sdm.R]"]
  node_bootstrap["bootstrap<br/>startup<br/>[bootstrap.R]"]
  node_config["config<br/>settings<br/>[config.R]"]
  node_validation["validation<br/>checks<br/>[validation.R]"]
end

subgraph group_data["Data prep"]
  node_occurrences["Occurrences<br/>ingest<br/>[occurrences.R]"]
  node_dwca["DwCA parse<br/>parser<br/>[occurrences_dwca.R]"]
  node_cov_stack["Covariates<br/>predictors<br/>[covariates_stack.R]"]
  node_cov_future["Future proj<br/>projection"]
end

subgraph group_models["Model engine"]
  node_model_registry["Registry<br/>model catalog<br/>[model_registry.R]"]
  node_cv_engine["CV engine<br/>validation engine<br/>[cv_engine.R]"]
  node_calibration["Calibration<br/>tuning<br/>[calibration.R]"]
  node_prediction["Prediction<br/>scoring<br/>[prediction.R]"]
end

subgraph group_analysis["Analysis"]
  node_ecology["Ecology<br/>post-model analysis<br/>[climate_matching.R]"]
end

subgraph group_ui["Shiny UI"]
  node_mods["Modules<br/>[mod_model_run.R]"]
  node_ui_shell["UI shell<br/>layout<br/>[ui_main_tabs.R]"]
end

subgraph group_output["Outputs"]
  node_reporting["Reporting<br/>exports<br/>[report.R]"]
  node_batch_output["Batch output<br/>run artifacts<br/>[batch_runner.R]"]
end

subgraph group_assets["Assets"]
  node_leaflet_plugins["Map plugins<br/>client ui<br/>[leaflet_plugins.R]"]
end

node_launch_app -->|"starts"| node_app
node_app -->|"builds"| node_ui_shell
node_app -->|"serves"| node_mods
node_pipeline -->|"executes"| node_run_sdm
node_batch_run -->|"runs"| node_run_sdm
node_run_sdm -->|"initializes"| node_bootstrap
node_run_sdm -->|"reads"| node_config
node_run_sdm -->|"checks"| node_validation
node_run_sdm -->|"loads"| node_occurrences
node_occurrences -->|"parses"| node_dwca
node_run_sdm -->|"prepares"| node_cov_stack
node_cov_stack -->|"projects"| node_cov_future
node_run_sdm -->|"selects"| node_model_registry
node_model_registry -->|"orchestrates"| node_cv_engine
node_cv_engine -->|"trains"| node_calibration
node_calibration -->|"produces"| node_prediction
node_prediction -->|"exports"| node_reporting
node_prediction -->|"analyzes"| node_ecology
node_ecology -->|"summarizes"| node_reporting
node_mods -->|"gates"| node_validation
node_mods -->|"triggers"| node_run_sdm
node_ui_shell -->|"uses"| node_leaflet_plugins
node_run_sdm -->|"packages"| node_batch_output
node_reporting -->|"feeds"| node_batch_output

click node_app "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/app.R"
click node_launch_app "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/launch_app.R"
click node_pipeline "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/pipeline.R"
click node_batch_run "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/scripts/batch_run.R"
click node_run_sdm "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/run_sdm.R"
click node_bootstrap "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/bootstrap.R"
click node_config "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/config.R"
click node_validation "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/validation.R"
click node_occurrences "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/data/occurrences.R"
click node_dwca "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/data/occurrences_dwca.R"
click node_cov_stack "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/covariates/covariates_stack.R"
click node_cov_future "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/covariates/future_projection.R"
click node_model_registry "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/model_registry.R"
click node_cv_engine "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/cv_engine.R"
click node_calibration "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/calibration.R"
click node_prediction "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/prediction.R"
click node_ecology "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ecology/climate_matching.R"
click node_mods "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/modules/mod_model_run.R"
click node_ui_shell "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ui/ui_main_tabs.R"
click node_leaflet_plugins "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ui/leaflet_plugins.R"
click node_reporting "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/output/report.R"
click node_batch_output "https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/output/batch_runner.R"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_launch_app,node_pipeline,node_batch_run,node_reporting,node_batch_output toneBlue
class node_run_sdm,node_bootstrap,node_config,node_validation,node_leaflet_plugins toneAmber
class node_occurrences,node_dwca,node_cov_stack,node_cov_future toneMint
class node_model_registry,node_cv_engine,node_calibration,node_prediction toneRose
class node_ecology toneIndigo
class node_mods,node_ui_shell toneTeal
```

## Components

### Entry points

Interactive and headless launch paths

- [app.R](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/app.R): shiny entry · Starts the interactive dashboard · `app.R`
- [launch_app.R](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/launch_app.R): launcher · Convenience wrapper that opens the app · `launch_app.R`
- [pipeline.R](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/pipeline.R): batch entry · Headless execution path for scripted runs · `pipeline.R`
- [batch_run.R](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/scripts/batch_run.R): batch script · Repeatable batch and release-oriented execution · `scripts/batch_run.R`

### Core orchestration

Configuration, validation, bootstrap, and run control

- [run_sdm](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/run_sdm.R): orchestrator · Main workflow coordinator for SDM runs · `R/core/run_sdm.R`
- [bootstrap](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/bootstrap.R): startup · Environment and package initialization · `R/core/bootstrap.R`
- [config](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/config.R): settings · Runtime configuration and app settings · `R/core/config.R`
- [validation](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/core/validation.R): checks · Readiness and input validation · `R/core/validation.R`

### Data prep

Occurrence ingestion and spatial predictors

- [Occurrences](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/data/occurrences.R): ingest · Occurrence loading and cleaning · `R/data/occurrences.R`
- [DwCA parse](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/data/occurrences_dwca.R): parser · Darwin Core Archive ingestion · `R/data/occurrences_dwca.R`
- [Covariates](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/covariates/covariates_stack.R): predictors · Predictor acquisition, caching, stacking, and selection · `R/covariates/covariates_stack.R`
- [Future proj](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/covariates/future_projection.R): projection · Future climate and projection support · `R/covariates/future_projection.R`

### Model engine

Algorithm registry, tuning, validation, and prediction

- [Registry](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/model_registry.R): model catalog · Backend registry and dispatch · `R/models/model_registry.R`
- [CV engine](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/cv_engine.R): validation engine · Cross-validation folds and evaluation flow · `R/models/cv_engine.R`
- [Calibration](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/calibration.R): tuning · Model fitting, tuning, and calibration · `R/models/calibration.R`
- [Prediction](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/models/prediction.R): scoring · Suitability prediction and projection · `R/models/prediction.R`

### Analysis

Derived ecology and post-model calculations

- [Ecology](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ecology/climate_matching.R): post-model analysis · Climate matching, range metrics, niche overlap, and dispersal · `R/ecology/climate_matching.R`

### Shiny UI

Browser interface and screen modules

- [Modules](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/modules/mod_model_run.R): shiny modules · Screen-level UI logic for data, run control, readiness, and results · `R/modules/mod_model_run.R`
- [UI shell](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ui/ui_main_tabs.R): layout · Header, tabs, and sidebar composition · `R/ui/ui_main_tabs.R`

### Outputs

Reports, metrics, exports, and run artifacts

- [Reporting](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/output/report.R): exports · Metrics, plots, reports, manifests, and script export · `R/output/report.R`
- [Batch output](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/output/batch_runner.R): run artifacts · Structured batch summaries and output packaging · `R/output/batch_runner.R`

### Assets

Client-side presentation and settings

- [Map plugins](https://github.com/mrcanofcatfood/sdm-dashboard-fork/blob/main/R/ui/leaflet_plugins.R): client ui · Leaflet and browser-side UI helpers · `R/ui/leaflet_plugins.R`

## Connections

- launch_app.R → app.R: starts · Launch helper invokes the Shiny app
- app.R → UI shell: builds · App composes the dashboard UI
- app.R → Modules: serves · App wires server logic through modules
- pipeline.R → run_sdm: executes · Headless pipeline calls the same orchestration path
- batch_run.R → run_sdm: runs · Batch automation triggers model workflow execution
- run_sdm → bootstrap: initializes · Workflow starts with environment/bootstrap setup
- run_sdm → config: reads · Workflow consumes runtime configuration
- run_sdm → validation: checks · Workflow validates inputs and readiness
- run_sdm → Occurrences: loads · Workflow ingests occurrence data
- Occurrences → DwCA parse: parses · DwCA is one supported occurrence source
- run_sdm → Covariates: prepares · Workflow builds the environmental predictor stack
- Covariates → Future proj: projects · Covariate preparation can include future layers
- run_sdm → Registry: selects · Workflow chooses model backends through the registry
- Registry → CV engine: orchestrates · Registry-backed models use shared CV and evaluation flow
- CV engine → Calibration: trains · Cross-validation feeds model calibration and fitting
- Calibration → Prediction: produces · Fitted models generate predictions and projections
- Prediction → Reporting: exports · Predictions feed metrics, plots, reports, and artifacts
- Prediction → Ecology: analyzes · Post-model ecology consumes suitability surfaces and outputs
- Ecology → Reporting: summarizes · Derived analyses are exported to user-facing deliverables
- Modules → validation: gates · UI readiness checks gate model execution
- Modules → run_sdm: triggers · Modules hand off to the shared orchestration layer
- UI shell → Map plugins: uses · UI shell relies on browser/map helpers
- run_sdm → Batch output: packages · Batch runs collect structured outputs and summaries
- Reporting → Batch output: feeds · Reports and artifacts are collected for batch workflows
