# kaz-yos/tableone architecture

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

- Interactive diagram: https://gitdiagram.com/kaz-yos/tableone
- Repository: https://github.com/kaz-yos/tableone

## Overview

##### Main Components
- Core R Code (located in the R/ directory): This includes functions for creating different types of tables (e.g., CreateCatTable.R, CreateTableOne.R, svyCreateTableOne.R) along with supporting modules (e.g., modules-ShowRegTable.R, modules-constructors.R, modules-print.R). Each of these files represents a distinct function or set of functions that contribute to the overall table generation process.
- Documentation & Vignettes: The docs/ directory and vignettes/ (e.g., introduction.Rmd, smd.Rmd) provide usage examples, detailed guides, and explanations of the package’s functionalities.
- Manual Pages: In man/ (e.g., print.TableOne.Rd, tableone-package.Rd) which serve as the R help files.
- Testing Suite: The tests/ directory and testthat/ subdirectory contain unit and integration tests that maintain package quality.
- Build and Integration Tools: Files like DESCRIPTION, NAMESPACE, Makefile, and GitHub Actions workflows (.github/workflows/*) handle dependency management, versioning (NEWS), build checks (R-CMD-check.yaml), and package distribution (including CRAN-related files).

##### Relationships and Interactions
- User calls one or more main functions (like CreateTableOne, CreateCatTable, etc.) to generate summary tables.
- These functions internally call various helper modules (modules-constructors.R, modules-print.R, modules-smd.R, etc.) to compute statistics, format outputs, and handle variations such as categorical versus continuous variables and survey data.
- The output is then formatted using print and summary methods (print.TableOne.R, summary.TableOne.R).
- Documentation and vignettes provide sample workflows that demonstrate how these functions integrate.
- The testing suite verifies each function/module works correctly and the project’s CI/CD (via GitHub Actions workflows) ensures continuous integration.

##### Architectural Patterns and Design Principles
- Modularity: The clear separation of functions into individual files and modules (each handling specific aspects like table creation, printing, and summary) exemplifies modular design.
- Layering: Different layers (data processing, formatting, user interface output) are cleanly separated. For example, one layer handles raw data manipulation and calculation, while another layer manages the presentation.
- Reusability: By breaking down functionality into helper modules and separate functions, it enables reusability of code for varied table types (categorical, continuous, survey data).
- Test-Driven Development: A dedicated tests/ directory indicates a strong testing culture that supports stability and continuous integration.

##### Relevant Technologies, Frameworks, and Tools
- R as the core programming language.
- R CMD tools for building and checking the package (e.g., Makefile, DESCRIPTION, NAMESPACE).
- GitHub Actions for Continuous Integration (evident in .github/workflows).
- CRAN guidelines/documentation for package distribution.
- Testing frameworks (testthat) for automated testing.

##### Important Diagramming Details
- Be very detailed—each file or a group of similar files (like all functions related to survey table creation) should be represented to capture the package’s modular nature.
- External library relationships (for example, usage of the survey package for weighted data support).
- Version control and CI/CD flows to show the ongoing integration and deployment setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface/API Layer
    subgraph "User Interface/API Layer"
        UI["User API"]:::ui
    end

    %% Core Logic & Modules
    subgraph "Core Logic/Modules"
        core1["CreateTableOne Function"]:::core
        core2["CreateCatTable Function"]:::core
        core3["svyCreateTableOne Function"]:::core
        helper1["Helper: modules-print.R"]:::helper
        helper2["Helper: modules-constructors.R"]:::helper
        helper3["Helper: modules-smd.R"]:::helper
    end

    %% Documentation & Help
    subgraph "Documentation & Help"
        docs["Pkgdown & Articles (docs/)"]:::docs
        vig["Vignettes (vignettes/)"]:::docs
        man["Manual Pages (man/)"]:::docs
    end

    %% Testing & CI/CD
    subgraph "Testing & CI/CD"
        tests["Testing Suite (tests/)"]:::test
        ci["CI/CD Workflows (.github/workflows/)"]:::test
    end

    %% Build & Distribution
    subgraph "Build & Distribution"
        build1["DESCRIPTION"]:::build
        build2["NAMESPACE"]:::build
        build3["Makefile"]:::build
    end

    %% Connections from User API to Core Functions
    UI -->|"calls"| core1
    UI -->|"calls"| core2
    UI -->|"calls"| core3

    %% Core Function relationships with helper modules
    core1 -->|"uses"| helper1
    core1 -->|"uses"| helper2
    core2 -->|"uses"| helper2
    core3 -->|"uses"| helper3

    %% Documentation links
    core1 -->|"documented_in"| docs
    core2 -->|"documented_in"| docs
    core3 -->|"documented_in"| docs

    docs --> vig
    docs --> man

    %% Testing and CI/CD relationships
    tests -->|"verifies"| core1
    tests -->|"verifies"| core2
    tests -->|"verifies"| core3
    ci --> tests

    %% Build and Distribution relationships
    build1 --> build2
    build2 --> build3
    build3 --> ci

    %% Click Events for Component Mapping
    click core1 "https://github.com/kaz-yos/tableone/blob/master/R/CreateTableOne.R"
    click core2 "https://github.com/kaz-yos/tableone/blob/master/R/CreateCatTable.R"
    click core3 "https://github.com/kaz-yos/tableone/blob/master/R/svyCreateTableOne.R"
    click helper1 "https://github.com/kaz-yos/tableone/blob/master/R/modules-print.R"
    click helper2 "https://github.com/kaz-yos/tableone/blob/master/R/modules-constructors.R"
    click helper3 "https://github.com/kaz-yos/tableone/blob/master/R/modules-smd.R"
    click docs "https://github.com/kaz-yos/tableone/tree/master/docs/"
    click vig "https://github.com/kaz-yos/tableone/tree/master/vignettes/"
    click man "https://github.com/kaz-yos/tableone/tree/master/man/"
    click tests "https://github.com/kaz-yos/tableone/tree/master/tests/"
    click ci "https://github.com/kaz-yos/tableone/tree/master/.github/workflows/"
    click build1 "https://github.com/kaz-yos/tableone/tree/master/DESCRIPTION"
    click build2 "https://github.com/kaz-yos/tableone/tree/master/NAMESPACE"
    click build3 "https://github.com/kaz-yos/tableone/tree/master/Makefile"

    %% Styles
    classDef ui fill:#FFCC80,stroke:#E65100,stroke-width:2px;
    classDef core fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef helper fill:#F8BBD0,stroke:#880E4F,stroke-width:2px;
    classDef docs fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef test fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef build fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;
```
