How unstable-branch/sdm-dashboard works
1. The repository is split into two product lines.
The primary architecture is the modern multi-user platform: Next.js frontend, Hono TypeScript API, Plumber/R compute service, PostgreSQL/PostGIS, Redis/BullMQ, and Garage-compatible object storage. In parallel, the older single-user Shiny desktop app is still present under app.R and www/, but it is not the main architectural path for new work.
2. The browser-facing layer is the Next.js dashboard in frontend/.
It owns route-level UI for authentication, projects, data upload/cleaning, model configuration, run monitoring, results, diagnostics, admin, and settings. The frontend uses client-side hooks/stores and map/visualization components, but it does not talk to the database or compute engine directly; all domain actions go through the API.
3. api/ is the orchestration and BFF layer.
It is a TypeScript/Hono service that centralizes auth, CSRF, rate limiting, caching, admin endpoints, jobs, results, climate, ecology, occurrences, settings, and SDM run management. It also owns the API-to-storage/queue integration, websocket or SSE-style progress delivery, and the boundary to the Plumber service.
4. PostgreSQL/PostGIS is the system of record.
The schema in api/src/db and the migrations in api/drizzle/ show that the API persists users, auth state, profiles, projects, uploads, runs, batches, provenance, resource accounting, storage metadata, and related operational state. PostGIS is material because geospatial data and project/run metadata are first-class, not just blobs.
5. Redis is the short-lived coordination layer.
It is used for queueing, rate limiting, cached responses, and background job state. The architecture relies on Redis/BullMQ-style orchestration to decouple request handling from long-running model computation and result generation.
6. Garage-compatible object storage holds large binary artifacts.
This is where uploaded source files, cleaned datasets, raster outputs, tiles, reports, and exports are stored. The API references storage services rather than embedding large files in the database, which keeps the persistence boundary clear: metadata in Postgres, heavy artifacts in object storage.
7. Plumber/R is the compute boundary for SDM work.
The plumber/ package wraps the modeling engine in an HTTP API and background dispatcher. It is responsible for the expensive science workflows: training, prediction, diagnostics, climate downloads/projections, and export generation. The API calls into this service rather than running models in-process.
8. The root R/ tree is the scientific engine.
It contains the reusable modelling core: covariates, data ingestion/validation, model implementations, cross-validation, calibration, prediction, ecology metrics, explainability, outputs, and legacy Shiny helpers. This is the domain library consumed by both the Plumber service and the desktop app, so it is the core computation layer of the repository.
9. Python model adapters are a secondary compute backend.
python_models/ contains small model-specific fit/predict entrypoints and manifests, including scikit-learn and elapid-based adapters. These sit behind the R/Plumber orchestration and are part of the model execution boundary rather than the user-facing app layer.
10. The main domain flow is upload → validate/clean → configure → run → analyze.
Users upload occurrence data, the API stores metadata and sends files through cleaning/validation workflows, the frontend helps inspect detected columns and geospatial inputs, then a model run is submitted. The run is executed asynchronously by the compute side, progress is streamed back to the dashboard, and outputs/metrics/diagnostics are written to storage for later viewing.
11. Results are treated as a separate read-heavy subsystem.
The frontend has dedicated results pages and components for rasters, diagnostics, projections, overlap/threshold analysis, and downloads. On the backend, results endpoints and manifest/export services expose these artifacts without requiring rerunning the model.
12. The legacy Shiny app remains as a self-contained local mode.
launch_app.R, app.R, and the www/ assets support the old desktop workflow with no multi-user auth layer. It is architecturally separate from the modern platform: useful for continuity and local use, but not the service-oriented path used for the current dashboard.
13. Composition and release tooling reinforce the boundaries.
Dockerfiles and compose files define the modern stack as independently deployable services, while CI and tests cover API contracts, frontend behavior, R model correctness, and end-to-end flows. The repo structure therefore maps cleanly to a diagram with distinct UI, API, compute, persistence, and legacy desktop lanes.
Main entry points: docker-compose.yml Compose files · api API · plumber Plumber · routes Domain routes
Components 20
Modern platform
Primary multi-user dashboard, API, compute, and persistence path.
- Frontend · Browser-facing multi-user UI for auth, projects, data, runs, results, admin, and settings.
frontend - API · TypeScript orchestration layer for auth, jobs, results, domain endpoints, and service integration.
api - Data tools · Route-level screens for file upload, column detection, cleaning, climate inputs, and map previews.
frontend/src/app/(dashboard)/data - Model setup · UI for species, extent, covariates, model selection, parameters, and run history.
frontend/src/app/(dashboard)/model - Results UI · Results pages for rasters, diagnostics, projections, metrics, and downloads.
frontend/src/app/(dashboard)/results - Admin UI · Admin screens for users, system status, diagnostics, logs, and database views.
frontend/src/app/(dashboard)/admin - Auth layer · Authentication, CSRF, rate limiting, and access control for the platform API.
api/src/middleware/auth.ts - Domain routes · Projects, occurrences, ecology, climate, diagnostics, settings, jobs, results, and SDM orchestration endpoints.
api/src/routes - Service layer · Plumber sync, queueing, websocket progress, model payloads, email, encryption, and storage integration.
api/src/services - Schema layer · Database schema and migrations defining platform state and metadata.
api/drizzle
Legacy desktop
Older single-user Shiny mode kept for local continuity.
- Shiny app · Older single-user Shiny workflow for local use and continuity.
app.R - Web assets · Static assets and scripts for the desktop Shiny interface.
www
Scientific engine
Reusable R domain logic and model execution core.
- Plumber · HTTP and background dispatch boundary for expensive SDM workflows and model execution.
plumber - R core · Reusable R science library for data handling, modeling, validation, ecology, and outputs.
R - Python adapters · Secondary model fit/predict entrypoints for scikit-learn and elapid-based adapters.
python_models
Infrastructure
Deployment, storage, and runtime wiring.
- PostgreSQL · Primary relational store for users, auth, projects, uploads, runs, provenance, and operational state.
api/src/db - Redis · Short-lived queueing, rate limiting, cached responses, and background job state.
api/src/services/queue.ts - Object storage · Garage-compatible binary storage for uploads, cleaned datasets, rasters, tiles, reports, and exports.
garage - Pipeline scripts · Release, smoke-test, benchmark, and setup scripts that exercise and package the stack.
scripts - Compose files · Docker and compose definitions for running the modern services together.
docker-compose.yml
Connections 28
- Frontend → API: calls · All domain actions flow through the API boundary.
- Data tools → Domain routes: uploads · Data screens submit cleaning, validation, climate, and file actions through backend endpoints.
- Model setup → Domain routes: configures · Model configuration and run submission are coordinated via API endpoints.
- Results UI → Domain routes: reads · Results pages fetch manifests, metrics, rasters, and diagnostics from the API.
- Admin UI → Domain routes: manages · Admin screens use backend admin and operational endpoints.
- API → PostgreSQL: persists · The API stores users, projects, uploads, runs, provenance, and settings in PostgreSQL/PostGIS.
- API → Redis: queues/cache · The API uses Redis for jobs, caching, and rate limiting.
- API → Object storage: stores artifacts · The API manages large files and generated outputs in object storage.
- API → Plumber: dispatches · The API hands off long-running SDM work to the compute service.
- Auth layer → API: protects · Authentication and request controls wrap the API boundary.
- Domain routes → Service layer: orchestrates · Routes delegate to storage, queue, progress, and integration services.
- Service layer → Plumber: syncs · Service code maintains the integration contract with the R compute service.
- Service layer → Redis: uses · Queue and event services rely on Redis-backed coordination.
- Service layer → Object storage: writes · Artifact and file services place binaries into object storage.
- Schema layer → PostgreSQL: defines · Migrations and schema define the relational system of record.
- Plumber → R core: executes · Plumber invokes the reusable R modeling engine for science workflows.
- Plumber → Python adapters: adapts · Plumber can route selected model execution into Python backends.
- R core → Object storage: produces · Model runs and exports generate artifacts that are stored externally.
- R core → PostgreSQL: reads/writes · The science layer consumes and updates run/data metadata through the platform boundary.
- Shiny app → Web assets: uses · The Shiny desktop app is paired with its static assets.
- Shiny app → R core: reuses · Legacy local mode shares the same R scientific engine.
- Pipeline scripts → Compose files: drives · Automation and release scripts work with the deployment definitions.
- Compose files → Frontend: runs · Compose files define the deployable frontend service.
- Compose files → API: runs · Compose files define the deployable API service.
- Compose files → Plumber: runs · Compose files define the deployable compute service.
- Compose files → PostgreSQL: provisions · Deployment wiring includes the database service or connection target.
- Compose files → Redis: provisions · Deployment wiring includes Redis for coordination.
- Compose files → Object storage: connects · Deployment wiring integrates compatible object storage.