# bachlab/pspm architecture

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

- Interactive diagram: https://gitdiagram.com/bachlab/pspm
- Repository: https://github.com/bachlab/pspm

## Overview

##### Main Components
The system architecture should be organized into these primary components:

a. Data Import Layer
- Multiple format importers (src/Import/)
- Support for various data formats (Spike, Biopac, EDF, etc.)
- File conversion utilities

b. Core Processing Layer
- Signal processing modules
- Model implementations (GLM, DCM)
- Preprocessing pipelines

c. Analysis Layer
- Statistical analysis tools
- Model fitting components
- Data extraction modules

d. User Interface Layer
- GUI components (pspm_guide.fig/m)
- Batch processing interface
- Configuration management

##### Key Relationships

- Raw Data → Import Layer → Core Processing → Analysis → Results
- User Interface ↔ All Other Components (control flow)
- Configuration System → All Components (settings flow)

##### Specific Implementation Details

Specialized modules:
- Signal-specific processors (SCR, ECG, EMG, etc.)
- Model implementations (src/f_SCR.m, src/f_SF.m)
- Helper functions (src/helper/)
- External dependencies (src/ext/)

##### Hierarchical Structure

In layers from bottom to top:

##### Integration Points

Interfaces with:
- External file formats
- MATLAB environment
- Python integration points
- Third-party toolboxes

##### Key Features to Emphasize

- Modular design for extensibility
- Support for multiple data formats
- Model-based analysis pipeline
- Batch processing capabilities
- GUI and programmatic interfaces

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef import fill:#FFE5CC,stroke:#FF9933
    classDef core fill:#CCE5FF,stroke:#3399FF
    classDef analysis fill:#E5CCFF,stroke:#9933FF
    classDef ui fill:#CCFFCC,stroke:#33FF33
    classDef config fill:#FFE6E6,stroke:#FF3333
    classDef external fill:#E6E6E6,stroke:#666666

    %% Legend
    subgraph Legend
        L1[Import Components]:::import
        L2[Core Processing]:::core
        L3[Analysis Components]:::analysis
        L4[User Interface]:::ui
        L5[Configuration]:::config
        L6[External Dependencies]:::external
    end

    %% Data Import Layer
    subgraph ImportLayer
        Import["Import Interface"]:::import
        Importers["Format Importers"]:::import
    end
    click Import "https://github.com/bachlab/pspm/blob/develop/src/pspm_import.m"
    click Importers "https://github.com/bachlab/pspm/tree/develop/src/Import/"

    %% Core Processing Layer
    subgraph CoreLayer
        SCR["SCR Model"]:::core
        SF["SF Model"]:::core
        SCRP["SCR Processing"]:::core
        PreProc["Preprocessing Pipeline"]:::core
        SCRPP["SCR Preprocessing"]:::core
    end
    click SCR "https://github.com/bachlab/pspm/blob/develop/src/f_SCR.m"
    click SF "https://github.com/bachlab/pspm/blob/develop/src/f_SF.m"
    click SCRP "https://github.com/bachlab/pspm/blob/develop/src/g_SCR.m"
    click PreProc "https://github.com/bachlab/pspm/blob/develop/src/pspm_pp.m"
    click SCRPP "https://github.com/bachlab/pspm/blob/develop/src/pspm_scr_pp.m"

    %% Analysis Layer
    subgraph AnalysisLayer
        GLM["GLM Analysis"]:::analysis
        DCM["DCM Analysis"]:::analysis
        SFA["SF Analysis"]:::analysis
        Helper["Analysis Helpers"]:::analysis
    end
    click GLM "https://github.com/bachlab/pspm/blob/develop/src/pspm_glm.m"
    click DCM "https://github.com/bachlab/pspm/blob/develop/src/pspm_dcm.m"
    click SFA "https://github.com/bachlab/pspm/blob/develop/src/pspm_sf.m"
    click Helper "https://github.com/bachlab/pspm/tree/develop/src/helper/"

    %% User Interface Layer
    subgraph UILayer
        MainGUI["Main GUI"]:::ui
        DataEditor["Data Editor"]:::ui
        Display["Display Interface"]:::ui
    end
    click MainGUI "https://github.com/bachlab/pspm/blob/develop/src/pspm_guide.m"
    click DataEditor "https://github.com/bachlab/pspm/blob/develop/src/pspm_data_editor.m"
    click Display "https://github.com/bachlab/pspm/blob/develop/src/pspm_display.m"

    %% Configuration System
    subgraph ConfigSystem
        Config["Configuration"]:::config
        Init["Initialization"]:::config
        Options["Options Management"]:::config
    end
    click Config "https://github.com/bachlab/pspm/tree/develop/src/pspm_cfg/"
    click Init "https://github.com/bachlab/pspm/blob/develop/src/pspm_init.m"
    click Options "https://github.com/bachlab/pspm/blob/develop/src/pspm_options.m"

    %% External Dependencies
    subgraph ExternalDeps
        Ext["External Dependencies"]:::external
        SPM["SPM Toolbox"]:::external
        VBA["VBA Toolbox"]:::external
    end
    click Ext "https://github.com/bachlab/pspm/tree/develop/src/ext/"
    click SPM "https://github.com/bachlab/pspm/tree/develop/src/ext/SPM/"
    click VBA "https://github.com/bachlab/pspm/tree/develop/src/ext/VBA/"

    %% Relationships
    Importers --> Import
    Import --> PreProc
    PreProc --> SCR & SF & SCRP & SCRPP
    SCR & SF & SCRP & SCRPP --> GLM & DCM & SFA
    Helper --> GLM & DCM & SFA
    MainGUI --> Import
    MainGUI --> PreProc
    MainGUI --> GLM & DCM & SFA
    DataEditor --> Import
    Display --> GLM & DCM & SFA
    Config --> Import & PreProc & GLM & DCM & SFA
    Init --> Config
    Options --> Config
    SPM & VBA --> GLM & DCM
```
