How worldfishcenter/coasts works
Project Type and Purpose
• This is a static, single-page geospatial visualization app built with React (via Vite) that fetches time-series/grid data from MongoDB (via a GitHub Actions workflow) and renders it on a Mapbox GL map. It uses “isomorphic-i18n” to provide internationalization support both at build and runtime.
High-Level Architecture Components
A. Data Pipeline
• GitHub Actions workflow (.github/workflows/fetch-mongodb-data.yml) connects to MongoDB using MONGODB_URI, runs scripts/data/fetchMongoData.js, and writes JSON into public/data/.
• Static JSON files (pds_grids.json, wio_map.json, time_series.json) are served with the built app.
B. Data Service Layer
• src/services/dataService.js: abstracts fetch calls to /data/*.json.
• src/utils/pdsDataProcessor.js & src/utils/metricCalculations.js: transform raw JSON into formats suitable for charting and analysis.
C. State & Logic (Hooks)
• useMapData: loads and caches raw + processed data.
• useMapLayers: configures Mapbox layers using src/utils/gridLayerConfig.js.
• useMapTooltip: manages hover/click tooltip state.
D. Presentation / UI Components
1. Root
• src/main.jsx & src/App.jsx: bootstraps React, wraps the app in the isomorphic-i18n provider, global CSS, and renders <App />.
2. Layout
• Header.jsx: top navigation and title (i18n-aware text).
• Sidebar.jsx: container for control panels.
3. Area
• Map.jsx: Mapbox canvas, integrates layers & tooltips.
• <DistributionHistogram/>: histogram overlay for selected grid cells
• <GridInfoPanel/>: detailed info on hovered cell
• <MapStyleToggle/>: switch between Mapbox styles
4. Control Panels (in Sidebar)
• SelectionPanel.jsx: UI controls (filters, date pickers) to adjust data scope
• AnalysisPanel.jsx: displays derived metrics, charts
5. Shared UI
• ui/button.jsx: reusable button component for forms/controls
E. Configuration & Build
• vite.config.js, postcss.config.js, tailwind.config.js: build-time configs.
• vercel.json: deployment settings.
• jsconfig.json, eslint.config.js: dev tooling.
External Services & Integrations
• MongoDB (via GitHub Actions scheduled fetch)
• Mapbox (requires VITE_MAPBOX_TOKEN)
• isomorphic-i18n (handles translation files and runtime locale resolution)
Component Function & Structure
• UI component with its core responsibility (e.g., “SelectionPanel – manages filter state and invokes hook to update map”).
• How isomorphic-i18n wraps the entire React tree and injects translated strings into Header, Sidebar, panels, and buttons.