# ddsjoberg/gtsummary architecture

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

- Interactive diagram: https://gitdiagram.com/ddsjoberg/gtsummary
- Repository: https://github.com/ddsjoberg/gtsummary

## Overview

##### Project Type and Scope
- This is a full-fledged R package. Its core value is providing a high-level API for summarizing data frames and regression models.
- Its modules cover data processing, table creation, styling modifications, and exporting or rendering of tables using different output engines (e.g., {gt}, kable, or as a tibble).

##### Break Down the File Structure into Major Components
- Source Code (R/ folder): Contains the bulk of the implementation. Nearly every R function is split by its role—from adding statistical info (e.g., add_p, add_ci, add_difference) to formatting (modify_caption, style_pvalue) and output conversion (as_gt, as_kable, as_tibble).
- Documentation & Man Pages (man/ folder and README/vignettes): Provide detailed user guidance, function documentation, and examples.
- Testing (tests/ folder): Contains unit tests that validate each function and overall integrity. This folder shows that the package emphasizes reliability.
- Continuous Integration/Workflow (/.github/workflows): Automated checks (e.g., R-CMD-check, pkgdown builds, code coverage) to ensure consistent quality integration.
- Package Metadata and Configuration: Files like DESCRIPTION, NAMESPACE, LICENSE, and pkgdown configuration files define package metadata, export functions, licensing, and documentation site building.
- Additional Resources: Data examples (data-raw/) and project vignettes (vignettes/) for extended examples and interactive demonstrations.

##### Main Components
– API / User Interface Layer:
- Represents the functions as exposed to users (e.g., tbl_summary, tbl_regression, tbl_merge).
- How these functions provide entry points to the package.
– Core Processing Modules:
- Implementation of core functions split by functionality such as:
◦ Data Summarization: Function files handling tbl_summary construction.
◦ Regression Handling: Modules for tbl_regression and related statistical outputs.
◦ Table Manipulation & Formatting: Files for modifying, styling, merging, and stacking tables.
◦ Helper Functions: Utility files (e.g., inline_text, select_helpers) that support the core functions.
– Output Conversion / Rendering Layer:
– External Dependencies:
- Interactions with external packages such as broom (for tidying up model outputs), gt (for table styling/rendering), and labelled.
– Testing and Validation:
- Encompass the tests which ensure each module’s functioning. This reassures the integrity of data transformation and output.
– Continuous Integration & Documentation:
- That CI workflows (GitHub Actions) and documentation tools (like pkgdown) are part of the system, ensuring that updates and changes pass necessary checks before deployment.

##### Relationships and Data Flow
– Show how data flows from raw inputs through transformation functions, then into formatting/conversion layers before output.
– Represent configuration and documentation generation as side processes that consume the source code information to generate man pages and website documentation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface (API) Layer
    subgraph "User Interface (API) Layer"
        API1["tbl_summary()"]:::api
        API2["tbl_regression()"]:::api
        API3["tbl_uvregression()"]:::api
        API4["tbl_merge()/tbl_nesting()"]:::api
    end

    %% Core Processing Modules
    subgraph "Core Processing Modules"
        subgraph "Data Summarization Module"
            DS1["tbl_summary Implementation"]:::core
            DS2["add_p()"]:::core
            DS3["add_ci()"]:::core
            DS4["add_overall()"]:::core
        end
        subgraph "Regression Handling Module"
            RH1["tbl_regression Implementation"]:::core
            RH2["tbl_regression_methods()"]:::core
            RH3["add_glance()"]:::core
            RH4["add_n_regression()"]:::core
        end
        subgraph "Table Manipulation & Formatting Module"
            TM1["modify_caption()"]:::core
            TM2["modify()"]:::core
            TM3["modify_table_styling()"]:::core
            TM4["style_pvalue()"]:::core
            TM5["bold_p()"]:::core
        end
        subgraph "Helper Functions"
            HF1["inline_text()"]:::core
            HF2["select_helpers()"]:::core
        end
    end

    %% Output Conversion / Rendering Layer
    subgraph "Output Conversion / Rendering Layer"
        OC1["as_gt()"]:::render
        OC2["as_kable()"]:::render
        OC3["as_tibble()"]:::render
        OC4["as_hux_table()"]:::render
        OC5["as_flex_table()"]:::render
    end

    %% External Dependencies
    subgraph "External Dependencies"
        ED1["broom"]:::external
        ED2["gt"]:::external
        ED3["labelled"]:::external
    end

    %% Testing and Validation
    subgraph "Testing and Validation"
        TEST["Test Suite (tests/)"]:::test
    end

    %% Continuous Integration & Documentation
    subgraph "Continuous Integration & Documentation"
        CI["GitHub Workflows"]:::ci
        DOC["Documentation & Man Pages"]:::doc
    end

    %% Package Metadata & Configuration
    subgraph "Package Metadata & Configuration"
        META["Package Metadata (DESCRIPTION, NAMESPACE, LICENSE)"]:::metadata
    end

    %% Additional Resources
    subgraph "Additional Resources"
        RES["Data examples & vignettes"]:::resources
    end

    %% Data Flow Connections
    %% From API Layer to Core Processing Modules
    API1 -->|"calls"| DS1
    API2 -->|"calls"| RH1
    API4 -->|"calls"| TM1
    API1 -->|"supports"| HF1

    %% From Core Processing Modules to Output Conversion Layer
    DS1 -->|"produces"| OC1
    RH1 -->|"produces"| OC1
    TM1 -->|"formats"| OC1
    HF1 -->|"supports"| OC1

    %% Core Modules utilizing External Dependencies
    DS1 ---|"uses"| ED1
    DS1 ---|"uses"| ED2
    DS1 ---|"uses"| ED3

    %% Core Modules covered by Testing
    DS1 ---|"tested by"| TEST
    TM1 ---|"tested by"| TEST

    %% Output Conversion ties into Documentation
    OC1 -->|"renders"| DOC

    %% CI and Documentation linked to Package Metadata
    CI -->|"relies on"| META
    DOC -->|"generated from"| META

    %% Styling
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef render fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef test fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef ci fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef doc fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef metadata fill:#C0C0C0,stroke:#000,stroke-width:1px;
    classDef resources fill:#AFEEEE,stroke:#000,stroke-width:1px;

    %% Click Events for API / User Interface Layer
    click API1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_summary.R"
    click API2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_regression.R"
    click API3 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_uvregression.R"

    %% Click Events for Data Summarization Module
    click DS1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_summary.R"
    click DS2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/add_p.R"
    click DS3 "https://github.com/ddsjoberg/gtsummary/blob/main/R/add_ci.R"
    click DS4 "https://github.com/ddsjoberg/gtsummary/blob/main/R/add_overall.R"

    %% Click Events for Regression Handling Module
    click RH1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_regression.R"
    click RH2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/tbl_regression_methods.R"
    click RH3 "https://github.com/ddsjoberg/gtsummary/blob/main/R/add_glance.R"
    click RH4 "https://github.com/ddsjoberg/gtsummary/blob/main/R/add_n_regression.R"

    %% Click Events for Table Manipulation & Formatting Module
    click TM1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/modify_caption.R"
    click TM2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/modify.R"
    click TM3 "https://github.com/ddsjoberg/gtsummary/blob/main/R/modify_table_styling.R"
    click TM4 "https://github.com/ddsjoberg/gtsummary/blob/main/R/style_pvalue.R"
    click TM5 "https://github.com/ddsjoberg/gtsummary/blob/main/R/bold_p.R"

    %% Click Events for Helper Functions
    click HF1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/inline_text.R"
    click HF2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/select_helpers.R"

    %% Click Events for Output Conversion / Rendering Layer
    click OC1 "https://github.com/ddsjoberg/gtsummary/blob/main/R/as_gt.R"
    click OC2 "https://github.com/ddsjoberg/gtsummary/blob/main/R/as_kable.R"
    click OC3 "https://github.com/ddsjoberg/gtsummary/blob/main/R/as_tibble.R"
    click OC4 "https://github.com/ddsjoberg/gtsummary/blob/main/R/as_hux_table.R"
    click OC5 "https://github.com/ddsjoberg/gtsummary/blob/main/R/as_flex_table.R"

    %% Click Event for Documentation & Man Pages
    click DOC "https://github.com/ddsjoberg/gtsummary/tree/main/man/"

    %% Click Event for Continuous Integration & Workflow
    click CI "https://github.com/ddsjoberg/gtsummary/tree/main/.github/workflows"

    %% Click Event for Package Metadata & Configuration
    click META "https://github.com/ddsjoberg/gtsummary/tree/main/DESCRIPTION"

    %% Click Event for Additional Resources
    click RES "https://github.com/ddsjoberg/gtsummary/tree/main/data-raw/"
```
