# qepanna/goflux architecture

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

- Interactive diagram: https://gitdiagram.com/qepanna/goflux
- Repository: https://github.com/qepanna/goflux

## Overview

##### Main Components
- Data Input/Acquisition: This includes raw data files (present in inst/extdata and data directories). These files represent the outputs from various instruments (e.g. LI-COR, Los Gatos UGGA, Picarro instruments, etc.).
- Import Module: Represented by many R scripts in the R directory (e.g., various *_import.R files, functions like imp.UGGA-data.R, import2RData.R). They parse the raw instrument data into a standardized in-memory format (most likely R data frames).
- Flux Calculation Module: Contains the main function goFlux and related calculation routines (use of LM and HM models, kappa and flux term calculations, etc.) defined in scripts like goFlux.R and goFlux-package.R.
- Best Flux Selection Module: Functions such as best.flux.R along with diagnostic functions (g.factor, intercept checking, number of observations, etc.) which compare indices (MAE, RMSE, AICc, SE) and determine the “best” flux estimate.
- Visualization Module: Handled by scripts like flux.plot.R and flux2pdf.R, which are used to generate plots and PDF outputs for visual inspection.
- Quality Control & Diagnostics: Interwoven in the calculations with warnings and “diagnose” outputs based on criteria (MDF, p-value, kappa ratios, etc.). These internal checks could be highlighted as part of the flux calculation and evaluation modules.
- External Dependencies: The package relies on many external R packages (dplyr, ggplot2, AICcmodavg, msm, etc.) which could be shown as an “external dependency” node linking into the core functions.
- Continuous Integration / Build: The existence of .github and .Rbuildignore files indicates automated testing and building workflows that integrate with platforms such as GitHub Actions.
- Documentation and Publication: Components like README.md, man, and paper suggest that user guidance and technical documentation are integrated parts of the overall design.

##### Data Flow and Relationships
- The output of the Import Module feeds into the “Flux Calculation Module” where two parallel calculation paths occur: the LM (linear) calculation path and the HM (non-linear) calculation path.
- Both flux estimation outputs then flow into the “Best Flux Selection Module” where statistical indices and diagnostics (g-factor, kappa ratios, AICc etc.) are compared.
- The selected best flux result and potentially the diagnostic outputs then feed into the “Visualization Module” to generate plots and reports.
- In parallel, quality control checks with warnings act as side outputs that inform the user of any limitations (e.g., low number of observation warnings, intercept deviation).

##### Architectural Patterns and Design Principles
- Extensibility: By supporting multiple instruments and different calculation methods, the design clearly uses “plug-and-play” style: new import modules or flux evaluation criteria can be added easily.
- Integration with External Tools: Integration with other R packages and automated testing (via GitHub workflows) indicates adherence to best practices in software development.
- Functional Organization: Each script in the R directory encapsulates a single functional routine (either importing data from one instrument type, performing model fitting, or plotting), which is characteristic of a functionally decomposed architecture.

##### Additional Details to Capture
- That the package supports both manual measurement identification and automatic selection of measurement windows as part of the import and processing flows.
- Documentation as a parallel path or “monitor” process where output is continuously updated (man, paper, README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input/Acquisition Subgraph
    subgraph "Data Input/Acquisition"
        extdata("Raw Data Source 1"):::data
        data("Raw Data Source 2"):::data
    end

    %% Import Module Subgraph
    subgraph "Import Module"
        dx_import("DX4015_import"):::module
        egm5_import("EGM5_import"):::module
        uggadata("imp.UGGA-data"):::module
        import2RData("import2RData"):::module
    end

    %% Standardized Data Node
    stdData("Standardized Data"):::data

    %% Flux Calculation Module Subgraph
    subgraph "Flux Calculation Module"
        goflux("goFlux Engine"):::module
        lm_calc("LM Calculation"):::module
        hm_calc("HM Calculation"):::module
        flux_term("Flux Term Calculations"):::module
    end

    %% Best Flux Selection Module Subgraph
    subgraph "Best Flux Selection Module"
        best_flux("best.flux"):::module
        g_factor("g.factor"):::module
        obs_win("obs.win"):::module
    end

    %% Visualization Module Subgraph
    subgraph "Visualization Module"
        flux_plot("flux.plot"):::module
        flux_pdf("flux2pdf"):::module
    end

    %% External Dependencies
    ext_dep("External R Packages"):::external

    %% Continuous Integration / Build
    ci_cd("CI/CD Workflows"):::external

    %% Documentation and Publication
    doc("Documentation & Publication"):::external

    %% Data Flow Connections
    extdata -->|"data_in"| dx_import
    extdata -->|"data_in"| egm5_import
    extdata -->|"data_in"| uggadata
    extdata -->|"data_in"| import2RData

    data -->|"data_in"| dx_import
    data -->|"data_in"| egm5_import
    data -->|"data_in"| uggadata
    data -->|"data_in"| import2RData

    dx_import --> stdData
    egm5_import --> stdData
    uggadata --> stdData
    import2RData --> stdData

    stdData -->|"flux_data"| goflux
    goflux -->|"invoke_LM"| lm_calc
    goflux -->|"invoke_HM"| hm_calc
    goflux -->|"calc_term"| flux_term

    lm_calc --> best_flux
    hm_calc --> best_flux
    flux_term --> best_flux

    best_flux -->|"flux_output"| flux_plot
    best_flux -->|"flux_output"| flux_pdf
    g_factor --- best_flux
    obs_win --- best_flux

    %% External Dependencies to Core Components
    ext_dep --- goflux
    ext_dep --- flux_plot

    %% CI/CD Connections
    ci_cd --- dx_import
    ci_cd --- egm5_import
    ci_cd --- uggadata
    ci_cd --- import2RData
    ci_cd --- goflux
    ci_cd --- best_flux
    ci_cd --- flux_plot

    %% Documentation Connections
    doc --- best_flux
    doc --- flux_plot

    %% Click Events for Component Mapping
    click extdata "https://github.com/qepanna/goflux/tree/master/inst/extdata"
    click data "https://github.com/qepanna/goflux/tree/master/data"
    click dx_import "https://github.com/qepanna/goflux/blob/master/R/DX4015_import.R"
    click egm5_import "https://github.com/qepanna/goflux/blob/master/R/EGM5_import.R"
    click uggadata "https://github.com/qepanna/goflux/blob/master/R/imp.UGGA-data.R"
    click import2RData "https://github.com/qepanna/goflux/blob/master/R/import2RData.R"
    click goflux "https://github.com/qepanna/goflux/blob/master/R/goFlux.R"
    click lm_calc "https://github.com/qepanna/goflux/blob/master/R/LM.flux.R"
    click hm_calc "https://github.com/qepanna/goflux/blob/master/R/HM.flux.R"
    click flux_term "https://github.com/qepanna/goflux/blob/master/R/flux.term.R"
    click best_flux "https://github.com/qepanna/goflux/blob/master/R/best.flux.R"
    click g_factor "https://github.com/qepanna/goflux/blob/master/R/g.factor.R"
    click obs_win "https://github.com/qepanna/goflux/blob/master/R/obs.win.R"
    click flux_plot "https://github.com/qepanna/goflux/blob/master/R/flux.plot.R"
    click flux_pdf "https://github.com/qepanna/goflux/blob/master/R/flux2pdf.R"
    click ci_cd "https://github.com/qepanna/goflux/tree/master/.github/workflows/"
    click doc "https://github.com/qepanna/goflux/blob/master/README.md"

    %% Styles
    classDef data fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef module fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef external fill:#ffe082,stroke:#ffab00,stroke-width:2px;
```
