# somalogic/somadataio architecture

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

- Interactive diagram: https://gitdiagram.com/somalogic/somadataio
- Repository: https://github.com/somalogic/somadataio

## Overview

##### Main Components
- Core Library Code – Represented by the R/ directory. This is where the bulk of the functionality is implemented (e.g., functions for reading ADAT files, data manipulation, wrangling with dplyr/tidyr S3 methods, and exporting data).
- Testing Framework – Located in the tests/ directory (with testthat scripts, snapshot files, and helper scripts). This represents how functionality is verified.
- Documentation & Vignettes – Refer to the README.md, the vignettes/ directory, and the pkgdown website configuration. These are used to generate user documentation and example workflows.
- Build & Configuration – Files like DESCRIPTION, NAMESPACE, Makefile, and various GitHub workflows within .github/workflows. They manage package metadata, build procedures, CI/CD pipelines, and deployment to CRAN.
- External Data / Examples – The inst/extdata and data/ directories contain example ADAT files and data objects used for demonstrating functionality.
- Dependency Integrations – The package depends on several CRAN packages (e.g., dplyr, tidyr, cli, magrittr, tibble) along with an optional integration with Biobase from Bioconductor for specific functions.

##### Relationships and Interactions
- Core Library functions interact with external dependencies (e.g., dplyr and tidyr for S3 generic methods) to process ‘SomaScan’ data.
- Functions in the R/ folder provide the public API (read_adat, write_adat, pivotExpressionSet, etc.) which are then exercised by both user scripts and tests.
- The tests directory validates these functionalities by running a comprehensive test suite using the testthat framework.
- Documentation (via README, vignettes, and pkgdown) communicates how the core functionalities work and explains workflows (like two-group comparisons, linear regression, etc.).
- CI/CD pipelines (configured via the GitHub workflows) are set to perform recurring checks (build, test, document rendering, version checking, and even CRAN submission check via rhub).

##### Architectural Decisions and Design Patterns
- The package follows a modular design where each R script or function (e.g., read_adat, write_adat, and various utility functions) represents a specific responsibility in the process of importing, processing, and exporting data.
- S3 methods are prominently used to override standard R generics (print, summary, subset, etc.), enabling a clean, idiomatic interface.
- Testing is done using snapshot testing and unit tests to ensure stability of each component before public release.
- Continuous Integration is used for automated testing and documentation rendering to maintain quality.

##### Incorporate Relevant Technologies and Frameworks
- R as the primary language.
- CRAN packages: dplyr, tidyr, magrittr, tibble, cli, and lifecycle.
- Optionally, Bioconductor’s Biobase for transforming data into ExpressionSets.
- Testing: testthat framework.
- Documentation: pkgdown for website generation.
- GitHub Actions for CI/CD workflows.

- Do not hide utilities and helper functions; include them as sub-components in the “Core Library” section.
- Example objects and data transformation flows, such as how an ADAT file is loaded, parsed into a structured R object, manipulated, and then exported.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library Code subgraph
    subgraph "Core Library Code (R/)"
        core1["File I/O: read-adat.R, write-adat.R"]:::core
        core2["Data Wrangling: adat2eSet.R, pivotExpressionSet.R"]:::core
        core3["Utility Functions: cleanNames, addAttributes, merge-clin"]:::core
    end

    %% Testing Framework subgraph
    subgraph "Testing Framework (tests/)"
        test1["Unit & Snapshot Tests"]:::test
    end

    %% Documentation & Examples subgraph
    subgraph "Documentation & Examples"
        doc1["Documentation: README.md, README.Rmd"]:::doc
        doc2["Vignettes & pkgdown: vignettes/articles, pkgdown config"]:::doc
    end

    %% Build & CI/CD subgraph
    subgraph "Build & CI/CD"
        build1["Build Scripts: DESCRIPTION, NAMESPACE, Makefile"]:::build
        build2["CI Pipelines: GitHub Workflows"]:::build
    end

    %% External Dependencies & Data subgraph
    subgraph "External Dependencies & Data"
        ext1["CRAN Packages: dplyr, tidyr, magrittr, tibble, cli, lifecycle"]:::external
        ext2["Optional Dependency: Biobase (Bioconductor)"]:::external
        ext3["Example Data: inst/extdata, data"]:::external
    end

    %% Connections
    core1 -->|"depends_on"| ext1
    core1 -->|"tested_by"| test1
    core2 -->|"documented_by"| doc1
    build2 -->|"triggers_tests"| test1
    build2 -->|"renders_docs"| doc2

    %% Styles
    classDef core fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef test fill:#c6e2ff,stroke:#333,stroke-width:2px;
    classDef doc fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef build fill:#fef9c3,stroke:#333,stroke-width:2px;
    classDef external fill:#d7bde2,stroke:#333,stroke-width:2px;

    %% Click Events
    click core1 "https://github.com/somalogic/somadataio/tree/main/R/"
    click test1 "https://github.com/somalogic/somadataio/tree/main/tests/"
    click doc1 "https://github.com/somalogic/somadataio/blob/main/README.md"
    click doc2 "https://github.com/somalogic/somadataio/tree/main/vignettes/"
    click build1 "https://github.com/somalogic/somadataio/tree/main/DESCRIPTION"
    click build2 "https://github.com/somalogic/somadataio/tree/main/.github/workflows/"
    click ext3 "https://github.com/somalogic/somadataio/tree/main/inst/extdata/"
```
