# lkaihua/bipeline architecture

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

- Interactive diagram: https://gitdiagram.com/lkaihua/bipeline
- Repository: https://github.com/lkaihua/bipeline

## Overview

##### Project Type and Purpose
- This is a full‐stack R/Shiny web application (“Bipeline”) for visually exploring biclusters in multivariate time series.
- Its pipeline has three main stages: pre‐processing, segmentation, and biclustering, all orchestrated through a Shiny UI.

##### File Structure
Top‐Level Files and Directories:
- server.R & ui.R – Shiny’s server and UI entry points (controller & view).
- Multiple R scripts in root (model components):
– normalize.R, segMerge.R, baselineBiclustering.R, LSDD.R, LSDDbiclustering.R, LSDDsegmentation.R, PDFbiclustering.R, tryLSDDBicluster.R, etc.
- data/ – sample CSVs for input.
- JavaScript assets: download.js, html2canvas.js, shinyjsBi.js, shinyjsSeg.js (enhance UI interactions, screenshot).
- ShinyDashboard.Rproj – project file.

##### README for Additional Insights
- Describes three major UI panels (Importing, Plotting, Pre‐processing, Segmentation, Biclustering).
- Highlights use of R packages (dygraphs, biclust) and custom algorithms (BiclusTS via LSDD).
- Mentions state/history management, dynamic UI (per‐variable segmentation tabs), screenshot functionality.

##### Main Components
a. Client Browser (UI Layer)
– Shiny UI (ui.R): HTML widgets, dygraphs plots, control panels.
– JavaScript helpers: html2canvas.js (screenshots), download.js, shinyjsBi.js, shinyjsSeg.js.
b. Shiny Server (Controller)
– server.R orchestrates inputs from UI, invokes R modules, and returns results.
– State/history manager (progress bar, navigation).
c. R Processing Modules (Model)
– Pre‐processing scripts (normalize.R, baselineBiclustering.R, etc.)
– Segmentation scripts (LSDDsegmentation.R, segMerge.R)
– Biclustering scripts (LSDDbiclustering.R, PDFbiclustering.R, tryLSDDBicluster.R)
– Interaction with biclust R package for baseline methods.
d. Data Storage
– Local CSV files (data/).
– Saved segmentation & biclustering results (RDS or CSV on disk).
e. External Libraries & Services
– R packages: dygraphs, biclust, shiny, shinyjs, etc.
– No external web services; all computation is server‐side in R.

##### Relationships & Data Flows
- User actions in Browser → UI (R + JS) → Shiny Server
- Shiny Server → calls R Processing Modules → reads/writes data (data/) → returns results
- Screenshot flow: UI → html2canvas → file download

##### Architectural Patterns & Principles
- MVC‐like separation: ui.R = view, server.R = controller, R scripts = model
- Pipeline stages represented as a linear or modular pipeline (pre‐processing → segmentation → biclustering)
- Dynamic UI generation for per‐variable segmentation parameters
- History/state pattern for undo/redo

– Cluster of R Modules subdivided into Pre‐processing, Segmentation, Biclustering (scripts named)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser/UI Layer"
        uiR["ui.R"]:::ui
        downloadjs["download.js"]:::ui
        html2canvas["html2canvas.js"]:::ui
        shinyjsBi["shinyjsBi.js"]:::ui
        shinyjsSeg["shinyjsSeg.js"]:::ui
    end

    subgraph "Shiny Server (Controller)"
        serverR["server.R"]:::server
    end

    subgraph "R Processing Modules"
        subgraph "Pre-processing"
            normalize["normalize.R"]:::processing
        end
        subgraph "Segmentation"
            LSDDseg["LSDDsegmentation.R"]:::processing
            segmerge["segMerge.R"]:::processing
        end
        subgraph "Biclustering"
            LSDDbic["LSDDbiclustering.R"]:::processing
            PDFbic["PDFbiclustering.R"]:::processing
            tryLSD["tryLSDDBicluster.R"]:::processing
            baseline["baselineBiclustering.R"]:::processing
        end
        subgraph "Core Algorithm Library"
            LSDD["LSDD.R"]:::processing
        end
    end

    subgraph "Data Storage"
        data1["accelerometry-176k-lines.csv"]:::datastore
        data2["wearable-device-5k-lines.csv"]:::datastore
    end

    subgraph "Project Config & Docs"
        proj["ShinyDashboard.Rproj"]:::external
        readme["README.md"]:::external
    end

    snapshot["screenshot/"]:::external

    subgraph "External Libraries"
        dygraphs["dygraphs"]:::external
        biclustpkg["biclust"]:::external
        shinypkg["shiny"]:::external
        shinyjspkg["shinyjs"]:::external
    end

    uiR -->|invokes| serverR
    downloadjs -->|enhances UI| serverR
    html2canvas -->|captures screenshot| serverR
    shinyjsBi -->|JS interactions| serverR
    shinyjsSeg -->|JS interactions| serverR

    serverR -->|calls| normalize
    serverR -->|calls| LSDDseg
    serverR -->|calls| segmerge
    serverR -->|calls| LSDDbic
    serverR -->|calls| PDFbic
    serverR -->|calls| tryLSD
    serverR -->|calls| baseline
    serverR -->|uses| LSDD

    normalize -->|reads/writes| data1
    normalize -->|reads/writes| data2
    LSDDseg -->|reads/writes| data1
    segmerge -->|reads/writes| data1
    LSDDbic -->|reads/writes| data1
    PDFbic -->|reads/writes| data1
    tryLSD -->|reads/writes| data1
    baseline -->|reads/writes| data1

    data1 -->|returns data| serverR
    data2 -->|returns data| serverR
    serverR -->|renders| uiR

    html2canvas -->|saves| snapshot
    snapshot -->|downloads| uiR

    serverR -->|uses| dygraphs
    serverR -->|uses| biclustpkg
    serverR -->|uses| shinypkg
    serverR -->|uses| shinyjspkg

    click uiR "https://github.com/lkaihua/bipeline/blob/master/ui.R"
    click downloadjs "https://github.com/lkaihua/bipeline/blob/master/download.js"
    click html2canvas "https://github.com/lkaihua/bipeline/blob/master/html2canvas.js"
    click shinyjsBi "https://github.com/lkaihua/bipeline/blob/master/shinyjsBi.js"
    click shinyjsSeg "https://github.com/lkaihua/bipeline/blob/master/shinyjsSeg.js"
    click serverR "https://github.com/lkaihua/bipeline/blob/master/server.R"
    click normalize "https://github.com/lkaihua/bipeline/blob/master/normalize.R"
    click LSDDseg "https://github.com/lkaihua/bipeline/blob/master/LSDDsegmentation.R"
    click segmerge "https://github.com/lkaihua/bipeline/blob/master/segMerge.R"
    click LSDDbic "https://github.com/lkaihua/bipeline/blob/master/LSDDbiclustering.R"
    click PDFbic "https://github.com/lkaihua/bipeline/blob/master/PDFbiclustering.R"
    click tryLSD "https://github.com/lkaihua/bipeline/blob/master/tryLSDDBicluster.R"
    click baseline "https://github.com/lkaihua/bipeline/blob/master/baselineBiclustering.R"
    click LSDD "https://github.com/lkaihua/bipeline/blob/master/LSDD.R"
    click data1 "https://github.com/lkaihua/bipeline/blob/master/data/accelerometry-176k-lines.csv"
    click data2 "https://github.com/lkaihua/bipeline/blob/master/data/wearable-device-5k-lines.csv"
    click proj "https://github.com/lkaihua/bipeline/blob/master/ShinyDashboard.Rproj"
    click readme "https://github.com/lkaihua/bipeline/blob/master/README.md"
    click snapshot "https://github.com/lkaihua/bipeline/tree/master/screenshot/"

    classDef ui fill:#D6E9F8,stroke:#31708F
    classDef server fill:#DFF0D8,stroke:#3C763D
    classDef processing fill:#FCF8E3,stroke:#8A6D3B
    classDef datastore fill:#F2DEDE,stroke:#A94442,shape:cylinder
    classDef external fill:#F5F5F5,stroke:#333,stroke-dasharray:5 5
```
