# dali-lab/pine-beetle-frontend architecture

> Architecture diagram of the GitHub repository dali-lab/pine-beetle-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dali-lab/pine-beetle-frontend
- Repository: https://github.com/dali-lab/pine-beetle-frontend

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Project Pine Beetle”) for visualizing historical and predicted Southern Pine Beetle outbreaks.
- Frontend: React + Redux + React-Router, bundled by webpack, deployed on Netlify.
- Backend: Two Node/Express servers (main CRUD/auth server + automation server). Data stored in MongoDB. Predictive model in R. External data ingestion via Survey123 webhooks.

##### File Structure
- Top-level:
- config files (.env.example, webpack.config.js, babel.config.js, .eslintrc.json)
- package.json / lockfile
- downloads/ (static PDFs and zips)
- mapbox-tiles/ (scripts and README)
- src/:
- components/ (reusable UI components)
- screens/ (page containers, subcomponents)
- services/ (API wrappers using axios)
- state/ (Redux: actions/reducers)
- utils/, constants/, styles/
- index.html + index.js (app entry)

##### Extract Key Architecture Notes from README
- Frontend served as static build by Netlify.
- Frontend calls two backend servers:
- Main backend (CRUD/auth, data queries)
- Automation server (data ingestion/aggregation via Survey123 webhooks)
- Backend servers interact with MongoDB.
- Predictive model executed in R (called by main backend).
- External third-party: Mapbox (tilesets & styles), Chart.js for graphs.

##### Main Components & Relationships
a. Frontend (Client):
- React App (components, screens)
- Redux Store (state/actions/reducers)
- React-Router (route switching)
- Service Layer (axios calls)
- Mapbox GL & Chart.js
b. Static Hosting: Netlify
c. Main Backend (Express/Node):
- API Endpoints (CRUD, auth, data queries)
- R Predictive Model integration
- Calls to MongoDB
d. Automation Server (Express/Node):
- Webhooks from Survey123 (external)
- Data transformation & aggregation
- Writes to MongoDB
e. Database: MongoDB
f. External Services:
- Survey123 (USFS data source)
- Mapbox API (tiles, styles)
g. Users:
- Public users & authenticated researchers (UI interactions)

##### Architectural Patterns & Design Principles
- Frontend: componentized React + Redux for unidirectional data flow.
- Separation of concerns: UI vs. API vs. data ingestion vs. predictive engine.
- Service layer abstracts HTTP calls (services/*.js → state/actions).
- Mapbox and Chart.js handle visualization.
- CI/CD via Netlify workflows (GitHub → dev/release branches).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    Users["Public Users & Authenticated Researchers"]:::external

    %% Deployment
    Users -->|"Access Application"| Netlify["Netlify (Static Hosting)"]:::deployment
    Netlify -->|"Serves build"| ReactApp["React App"]:::frontend

    %% Frontend Subgraph
    subgraph "Frontend Layer" 
        direction TB
        ReactApp
        Router["React-Router"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        Services["Service Layer (axios wrappers)"]:::frontend
        Components["UI Components"]:::frontend
        Screens["Page Containers / Screens"]:::frontend
        Constants["Constants"]:::frontend
        Utils["Utils"]:::frontend
        Styles["Global Styles"]:::frontend
        MapboxGL["Mapbox GL Integration"]:::frontend
        ChartJS["Chart.js Visualization"]:::frontend
    end

    ReactApp -->|"uses"| Router
    ReactApp -->|"connects to"| ReduxStore
    ReactApp -->|"calls"| Services
    ReactApp -->|"renders"| Components
    ReactApp -->|"renders"| Screens
    ReactApp -->|"uses"| Constants
    ReactApp -->|"uses"| Utils
    ReactApp -->|"applies"| Styles
    ReactApp -->|"visualizes map"| MapboxGL
    ReactApp -->|"visualizes charts"| ChartJS

    Services -->|"/api/data, /api/auth"| MainBackend["Main Backend (Node/Express)"]:::backend
    ReactApp -->|"tiles & styles"| MapboxAPI["Mapbox API"]:::external

    %% Backend & Data Stores
    subgraph "Backend & Data Services"
        direction TB
        MainBackend
        AutomationBackend["Automation Server (Node/Express)"]:::backend
        MongoDB["MongoDB"]:::datastore
        RModel["R Predictive Model"]:::datastore
    end

    MainBackend -->|"read/write"| MongoDB
    MainBackend -->|"invoke /predict"| RModel
    AutomationBackend -->|"write"| MongoDB

    %% External Integrations
    subgraph "External Services"
        direction TB
        Survey123["Survey123 Webhooks"]:::external
    end

    Survey123 -->|"Webhook POST"| AutomationBackend

    %% CI/CD
    subgraph "Build & Tooling"
        direction TB
        Webpack["webpack.config.js"]:::tooling
        Babel["babel.config.js"]:::tooling
        ESLint[".eslintrc.json"]:::tooling
        Env[".env.example"]:::tooling
    end

    %% Click Events
    click ReactApp "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/app/index.js"
    click Components "https://github.com/dali-lab/pine-beetle-frontend/tree/dev/src/components/"
    click Screens "https://github.com/dali-lab/pine-beetle-frontend/tree/dev/src/screens/"
    click ReduxStore "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/state/reducers/index.js"
    click Services "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/services/index.js"
    click Constants "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/constants/index.js"
    click Utils "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/utils/index.js"
    click Styles "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/styles/main.scss"
    click MapboxGL "https://github.com/dali-lab/pine-beetle-frontend/tree/dev/src/components/map/"
    click ChartJS "https://github.com/dali-lab/pine-beetle-frontend/tree/dev/src/components/histogram-components/"
    click Router "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/index.js"
    click ReactApp "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/src/index.js"
    click Netlify "https://github.com/dali-lab/pine-beetle-frontend/tree/dev/src/_redirects"
    click Webpack "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/webpack.config.js"
    click Babel "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/babel.config.js"
    click ESLint "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/.eslintrc.json"
    click Env "https://github.com/dali-lab/pine-beetle-frontend/blob/dev/.env.example"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000
    classDef backend fill:#d4edda,stroke:#28a745,color:#000
    classDef datastore fill:#fff3cd,stroke:#ffcd39,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef deployment fill:#d1ecf1,stroke:#17a2b8,color:#000
    classDef tooling fill:#f8d7da,stroke:#dc3545,color:#000
```
