# jbhopkins/bioxtasraw architecture

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

- Interactive diagram: https://gitdiagram.com/jbhopkins/bioxtasraw
- Repository: https://github.com/jbhopkins/bioxtasraw

## Overview

##### Project Type and Purpose
- BioXTAS RAW is a Python‑based desktop application (full‑stack in the sense of GUI + core library + external tool integration) for processing solution Small‑Angle Scattering (SAS) data.
- It exposes both a graphical front‑end (RAW GUI) and a programmatic API (RAWAPI and core `bioxtasraw` modules), integrates with external binaries (GNOM, DAMMIF, DENSS, ATSAS), reads/writes many file formats, and is packaged for Linux, macOS, and Windows.

##### File Structure
Top‑level directories:
- `bioxtasraw/` – core Python package. Contains:
– GUI modules (RAW.py, RAWCustomDialogs.py, RAWPlot.py, RAWReport.py, RAWOptions.py, etc.)
– API/core compute modules (SASCalc.py, SASProc.py, DENSS.py, BIFT.py, REGALS.py, etc.)
– File I/O and parsers (SASFileIO.py, SASParser.py, RAWAPI.py)
– Resource definitions (denss_resources/, definitions/hdf5/)
- `installer/` – PyInstaller spec and hooks, platform‑specific packaging scripts.
- `docs/` – Sphinx documentation sources.
- `Tests/` – pytest suite and sample data.
- `LinuxLib/` – Linux launcher scripts and desktop entry.
- Packaging files: `setup.py`, `pyproject.toml`, `requirements.txt`.

##### README for Insights
- Describes main features (2D→1D integration, Guinier fits, Rg, MW, GNOM, DAMMIF, DENSS, EFA, REGALS).
- Mentions dependencies (ATSAS, hdf5plugins, PyFAI) and install targets (Linux, macOS, Windows).

##### Main Components
a. User Interface Layer
– RAW GUI (PyQt/PySide front‑end)
– Dialogs & Controls (RAWCustomDialogs, RAWCustomCtrl)
– Plotting components (RAWPlot)
b. Core Processing Layer
– RAWAPI & RAWAnalysis (or programmatic entry points)
– SASCalc, SASProc, SASUtils, DENSS, BIFT, REGALS modules (business logic)
c. Data I/O Layer
– File parsers (SASFileIO, SASParser)
– HDF5 definitions (definitions/hdf5)
d. External Tools & Services
– ATSAS suite (GNOM, DAMMIF, DAMAVER, DAMCLUST, AMBIMETER)
– DENSS binary
– PyFAI plugins (calibrant)
– HDF5 plugins
e. Packaging & Deployment
– PyInstaller spec (`installer/RAW.spec`) and hooks
– Linux launcher (`LinuxLib/`)
– Installer scripts per platform

##### Relationships & Data Flows
– User clicks in GUI → GUI controller invokes RAWAPI or directly calls SASCalc/SASProc → Data parser reads 2D image → produces 1D profile → business logic modules run fits or external binaries → results returned to GUI → plotted or saved.
– For external tools: Data written to temp file → external binary invoked (subprocess) → output file parsed back into Python → update in-memory model → displayed.
– Packaging flow (build time only): source + resources + hooks → PyInstaller → standalone executables → installer scripts wrap them into OS‑native packages.

##### Architectural Patterns & Principles
– Layered architecture: UI → API/Controller → Business logic → Data I/O → External services
– Modular design: each analysis algorithm (SASCalc, DENSS, BIFT, REGALS) is isolated in its own module.
– Plugin‑style resource loading (denss_resources JSON, HDF5 definitions).
– Separation of concerns: parsing, computation, and presentation are distinct.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::user

    %% UI Layer
    subgraph "User Interface Layer"
        RAW_GUI["RAW GUI"]:::ui
        RAWCustomDialogs["Dialogs & Controls"]:::ui
        RAWCustomCtrl["Custom Controls"]:::ui
        RAWPlot["Plotting"]:::ui
        RAWReport["Report Generation"]:::ui
        RAWOptions["Options & Settings"]:::ui
        RAWSettings["Settings"]:::ui
        RAWImage["Image Handling"]:::ui
    end

    %% Controller/API Layer
    subgraph "Programmatic API / Controller Layer"
        RAWAPI["RAWAPI"]:::core
        RAWAnalysis["RAWAnalysis"]:::core
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        SASCalc["SASCalc Module"]:::core
        SASProc["SASProc Module"]:::core
        SASUtils["SASUtils Module"]:::core
        DENSS_Module["DENSS Interface"]:::core
        BIFT_Module["BIFT Interface"]:::core
        REGALS_Module["REGALS Interface"]:::core
    end

    %% Data I/O Layer
    subgraph "Data I/O Layer"
        SASFileIO["SASFileIO"]:::io
        SASParser["SASParser"]:::io
        HDF5_Def["HDF5 Definitions"]:::io
        Denss_Res["DENSS Resource Loader"]:::io
        Icons["Icon & Resource Assets"]:::io
    end

    %% External Tools
    subgraph "External Tools & Services"
        ATSAS["ATSAS Suite"]:::ext
        DENSS_Bin["DENSS Binary"]:::ext
        PyFAI["PyFAI Plugins"]:::ext
        HDF5_Plugins["HDF5 Plugins"]:::ext
    end

    %% Results
    Results["Results: Plots, Reports, Exported Files"]:::result

    %% Packaging & Deployment
    subgraph "Packaging & Deployment"
        PyInstaller["PyInstaller Spec & Hooks"]:::build
        LinuxDeploy["Linux Launcher & Desktop Entry"]:::build
        Utils["Utilities"]:::build
    end

    %% Connections
    User --> RAW_GUI
    RAW_GUI --> RAWCustomDialogs
    RAW_GUI --> RAWCustomCtrl
    RAW_GUI --> RAWOptions
    RAW_GUI --> RAWSettings
    RAW_GUI --> RAWImage
    RAW_GUI --> RAWPlot
    RAW_GUI --> RAWReport
    RAW_GUI --> RAWAPI

    RAWAPI --> RAWAnalysis
    RAWAnalysis --> SASCalc
    RAWAnalysis --> SASProc
    RAWAnalysis --> SASUtils
    RAWAnalysis --> DENSS_Module
    RAWAnalysis --> BIFT_Module
    RAWAnalysis --> REGALS_Module

    SASCalc --> SASFileIO
    SASProc --> SASFileIO
    DENSS_Module --> Denss_Res
    SASFileIO --> SASParser
    SASParser --> HDF5_Def
    Icons --> SASGUI[RAW GUI] 

    SASParser --> ATSAS
    DENSS_Module --> DENSS_Bin
    SASCalc --> PyFAI
    SASParser --> HDF5_Plugins

    ATSAS --> SASParser
    DENSS_Bin --> SASParser
    PyFAI --> SASParser
    HDF5_Plugins --> SASParser

    SASParser --> Results
    SASCalc --> Results
    SASProc --> Results
    REGALS_Module --> Results

    %% Packaging flow
    PyInstaller -->|"builds"| LinuxDeploy
    PyInstaller -->|"includes"| Utils

    %% Click Events
    click RAW_GUI "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAW.py"
    click RAWCustomDialogs "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWCustomDialogs.py"
    click RAWCustomCtrl "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWCustomCtrl.py"
    click RAWPlot "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWPlot.py"
    click RAWReport "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWReport.py"
    click RAWOptions "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWOptions.py"
    click RAWSettings "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWSettings.py"
    click RAWImage "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWImage.py"
    click RAWAPI "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWAPI.py"
    click RAWAnalysis "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWAnalysis.py"
    click SASCalc "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/SASCalc.py"
    click SASProc "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/SASProc.py"
    click SASUtils "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/SASUtils.py"
    click DENSS_Module "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/DENSS.py"
    click BIFT_Module "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/BIFT.py"
    click REGALS_Module "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/REGALS.py"
    click SASFileIO "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/SASFileIO.py"
    click SASParser "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/SASParser.py"
    click HDF5_Def "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/definitions/hdf5/lix_hdf5.txt"
    click Denss_Res "https://github.com/jbhopkins/bioxtasraw/tree/master/bioxtasraw/denss_resources/"
    click Icons "https://github.com/jbhopkins/bioxtasraw/blob/master/bioxtasraw/RAWIcons.py"
    %% For assets directory, choose directory path
    click Icons "https://github.com/jbhopkins/bioxtasraw/tree/master/bioxtasraw/resources/"

    click PyInstaller "https://github.com/jbhopkins/bioxtasraw/blob/master/installer/RAW.spec"
    click LinuxDeploy "https://github.com/jbhopkins/bioxtasraw/tree/master/LinuxLib/start_raw"

    %% Styles
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px
    classDef core fill:#90ee90,stroke:#333,stroke-width:1px
    classDef io fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef ext fill:#ffa500,stroke:#333,stroke-width:1px
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef result fill:#ffffff,stroke:#333,stroke-width:1px
    classDef user fill:#ffffff,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
```
