# pharmaverse/anca architecture

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

- Interactive diagram: https://gitdiagram.com/pharmaverse/anca
- Repository: https://github.com/pharmaverse/anca

## Overview

##### Project type and purpose
- This is an R package that bundles an R Shiny web application (“aNCA”) plus a library of R functions for performing Non-Compartmental Analysis (NCA) on pharmacokinetic datasets.

##### File structure
- Top-level:
- DESCRIPTION, NAMESPACE, R/ (core R functions) → the package’s analysis engine.
- inst/shiny/ (UI assets, modules, app launcher).
- man/, vignettes/, pkgdown/ → documentation and site-generation.
- tests/, .github/workflows → automated testing and CI.
- Within inst/shiny:
- www/ → CSS/SCSS, JS, images (front-end assets)
- functions/ → shared server functions for UI interactions
- modules/ → Shiny modules for each tab (Data, NCA, TLG, Visuals)
- app.R → Shiny app entry point
- R/: functions wrapping PKNCA core logic, data formatting, plotting helpers.

##### README for additional insights
- The Shiny app is launched via run_app() and auto-loads sample data.
- Key features map to modules: data upload/filtering, NCA setup/run, outputs (plots, tables), export to CDISC.
- External dependency: PKNCA package (for the actual NCA algorithms).

##### Essential architectural elements
- Shiny modules as separate blocks under the frontend/server layer.
- PKNCA package as a dependency of the analysis engine.
- CI/CD pipeline and testing suite to reflect the development workflow.
- Avoid clutter by grouping similar modules (e.g., all UI modules under a single “UI Modules” container, with sub-labels).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Shiny Frontend" 
        direction TB
        AppEntry["Shiny App Entry Point\n(app.R)"]:::frontend
        FrontendAssets["Frontend Assets\n(CSS/JS/Images)"]:::frontend
        DataSamples["Sample Data\n(CSV)"]:::frontend
        UIModules["UI Modules\n(Data, NCA, TLG, Visuals)"]:::frontend
    end

    %% Server Layer
    subgraph "Shiny Server Logic"
        direction TB
        SharedFunctions["Shared Server Functions"]:::server
        DataModule["Data Upload & Filtering Module"]:::server
        NCAModule["NCA Setup & Results Module"]:::server
        TLGModule["TLG Module"]:::server
        VisualModule["Visualization Module"]:::server
        Launcher["Application Launcher\n(run_app())"]:::server
    end

    %% Analysis Engine
    subgraph "Analysis Engine"
        direction TB
        AnalysisCore["Core NCA Wrappers"]:::analysis
        DataUtils["Data Formatting & Utility Functions"]:::analysis
        PlotHelpers["Plotting Helpers"]:::analysis
        ExportLayer["Export Layer\n(CDISC)"]:::analysis
        PKNCA["PKNCA Library"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        UserData["User-Uploaded Data"]:::data
        ReactiveData["In-Memory Reactive Data"]:::data
        CDICData["Internal CDISC Data"]:::data
    end

    %% CI/CD & Documentation
    subgraph "Development Workflow"
        direction TB
        Tests["Unit Tests Suite"]:::external
        CI["CI/CD Workflows"]:::external
        Docs["Documentation & Vignettes"]:::external
    end

    %% Connections
    User -->|opens in| Browser["Web Browser"]:::external
    Browser -->|HTTP↔| AppEntry
    AppEntry --> FrontendAssets
    AppEntry --> DataSamples
    AppEntry --> UIModules

    UIModules -->|invokes| SharedFunctions
    UIModules --> DataModule
    UIModules --> NCAModule
    UIModules --> TLGModule
    UIModules --> VisualModule

    Launcher --> SharedFunctions

    DataModule -->|processes| UserData
    DataModule -->|outputs| ReactiveData

    ReactiveData --> NCAModule
    NCAModule -->|calls| AnalysisCore
    AnalysisCore --> DataUtils
    AnalysisCore --> PlotHelpers
    AnalysisCore -->|depends on| PKNCA

    PlotHelpers --> VisualModule
    NCAModule --> ExportLayer
    ExportLayer --> CDICData

    SharedFunctions -->|orchestrates| AnalysisCore

    CI --> Tests
    CI --> Docs

    %% Click Events
    click AppEntry "https://github.com/pharmaverse/anca/blob/main/inst/shiny/app.R"
    click FrontendAssets "https://github.com/pharmaverse/anca/tree/main/inst/shiny/www/"
    click DataSamples "https://github.com/pharmaverse/anca/tree/main/inst/shiny/data/"
    click SharedFunctions "https://github.com/pharmaverse/anca/tree/main/inst/shiny/functions/"
    click UIModules "https://github.com/pharmaverse/anca/tree/main/inst/shiny/modules/"
    click DataModule "https://github.com/pharmaverse/anca/tree/main/inst/shiny/modules/tab_data/"
    click NCAModule "https://github.com/pharmaverse/anca/tree/main/inst/shiny/modules/tab_nca/"
    click TLGModule "https://github.com/pharmaverse/anca/tree/main/inst/shiny/modules/tab_tlg/"
    click VisualModule "https://github.com/pharmaverse/anca/blob/main/inst/shiny/modules/tab_visuals.R"
    click Launcher "https://github.com/pharmaverse/anca/blob/main/R/run_app.R"
    click AnalysisCore "https://github.com/pharmaverse/anca/tree/main/R/"
    click DataUtils "https://github.com/pharmaverse/anca/blob/main/R/format_data.R"
    click DataUtils "https://github.com/pharmaverse/anca/blob/main/R/utils.R"
    click DataUtils "https://github.com/pharmaverse/anca/blob/main/R/conversions.R"
    click PlotHelpers "https://github.com/pharmaverse/anca/blob/main/R/flexible_violinboxplot.R"
    click PlotHelpers "https://github.com/pharmaverse/anca/blob/main/R/general_lineplot.R"
    click PlotHelpers "https://github.com/pharmaverse/anca/blob/main/R/general_meanplot.R"
    click PlotHelpers "https://github.com/pharmaverse/anca/blob/main/R/lambda_slope_plot.R"
    click ExportLayer "https://github.com/pharmaverse/anca/blob/main/R/export_cdisc.R"
    click CDICData "https://github.com/pharmaverse/anca/blob/main/data/pknca_cdisc_terms.rda"
    click Tests "https://github.com/pharmaverse/anca/tree/main/tests/testthat/"
    click CI "https://github.com/pharmaverse/anca/tree/main/.github/workflows/"
    click Docs "https://github.com/pharmaverse/anca/tree/main/DESCRIPTION"
```
