# wwylab/lfspro architecture

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

- Interactive diagram: https://gitdiagram.com/wwylab/lfspro
- Repository: https://github.com/wwylab/lfspro

## Overview

##### Project type and purpose
- This is an R package (“LFSPRO”) that computes Li-Fraumeni syndrome carrier probabilities and future cancer risks based on family history.
- It exposes R‐level functions (e.g., lfspro(), lfsClassic(), lfsChompret2015()) to end users, while heavy numerical routines are implemented in C++ under src/.

##### File structure
- Top‐level files: DESCRIPTION, NAMESPACE, README.md → standard R package metadata.
- R/: R‐level wrappers and data‐preparation functions (FormatChange.R, convert.data.R, lfspro.R, etc.).
- src/: Core computational modules in C++ (e.g., Mendel.cpp/.h, pedigree.cpp/.h, peelingC.cpp).
- data/: Preprocessed data sets (penetrances, cancer.type, fam.data, etc.) exposed as .rda/.RData.
- man/: Documentation for every R function.
- No separate tests/ or frontend/ directories — package is a library.

##### README for additional insights
- Describes main features: mutation‐carrier probabilities, future cancer risk, second primary cancer risk.
- Shows typical usage pattern: users call R functions with family and cancer data frames.

a. Components
- User R session / CLI
- R API layer (R/*.R)
- Data resources (data/*.rda, .RData)
- Computational core (C++ modules in src/)
- Documentation (man/*.Rd)
- Build/deploy toolchain (R CMD build/install, devtools, GitHub)
b. Relationships & data flow
1. User invokes R function (e.g., lfspro()) in their R console or script.
2. R API layer loads required data from data/*.rda.
3. R function marshals inputs and calls compiled C++ routines via R’s native interface.
4. C++ core performs numerical algorithms (Mendelian transmission, peeling, likelihood computations).
5. Results are returned to R, formatted into R objects (vectors, data frames).
6. User inspects output or downstream plots/tables.
c. Architectural patterns and principles
- “Wrapper” pattern: thin R interface → computational C++ backend.
- Modular C++ design: separate headers and source modules for Mendel, PCCP, pedigree, “peeling” algorithm.
- Data‐driven: static data in package loaded at runtime.
d. Key technologies & frameworks
- R (package framework: DESCRIPTION, NAMESPACE, man/)
- C++ (portable code compiled into a shared library via R CMD INSTALL)
- devtools/GitHub for distribution

##### Elements
- Clear labels:
- “User R Session”
- “R API Layer”
- “Data Resources”
- “C++ Computational Core”
- “Documentation”
- “Build & Deployment”
- User → R API Layer (function calls)
- R API → Data Resources (load)
- R API → C++ Core (native call)
- C++ Core → R API (return results)
- GitHub → Build & Deployment → Installed Package
- Blue rectangles for code components (R, C++)
- Green for data resources
- Orange for documentation
- Gray for external systems (GitHub, R CMD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User R Session"]:::external

    subgraph "R API Layer"
        R_API["R API Layer"]:::code
    end

    subgraph "Data Resources"
        Data["Data Resources"]:::data
    end

    subgraph "C++ Computational Core"
        Mendel["Mendel Module"]:::code
        PCCP["PCCP Module"]:::code
        Pedigree["Pedigree Module"]:::code
        Peeling["Peeling Algorithm"]:::code
        Utils["Utility Routines"]:::code
    end

    Doc["Documentation (man/)"]:::doc

    subgraph "Build & Deployment"
        GitHub["GitHub"]:::external
        DESCRIPTION["DESCRIPTION"]:::build
        NAMESPACE["NAMESPACE"]:::build
        README["README.md"]:::build
        RCMD["R CMD build/install"]:::build
        Install["Installed Package"]:::build
    end

    User -->|"calls"| R_API
    R_API -->|"loads"| Data
    R_API -->|"calls native"| Mendel
    R_API -->|"calls native"| PCCP
    R_API -->|"calls native"| Pedigree
    R_API -->|"calls native"| Peeling
    R_API -->|"calls native"| Utils
    Mendel -->|"returns results"| R_API
    PCCP -->|"returns results"| R_API
    Pedigree -->|"returns results"| R_API
    Peeling -->|"returns results"| R_API
    Utils -->|"provides functions"| Mendel
    GitHub -->|"source"| DESCRIPTION
    GitHub -->|"source"| NAMESPACE
    GitHub -->|"source"| README
    GitHub -->|"triggers"| RCMD
    RCMD -->|"produces"| Install

    click R_API "https://github.com/wwylab/lfspro/tree/master/R/"
    click Data "https://github.com/wwylab/lfspro/tree/master/data/"
    click Mendel "https://github.com/wwylab/lfspro/blob/master/src/Mendel.cpp"
    click PCCP "https://github.com/wwylab/lfspro/blob/master/src/PCCP.cpp"
    click Pedigree "https://github.com/wwylab/lfspro/blob/master/src/pedigree.cpp"
    click Peeling "https://github.com/wwylab/lfspro/blob/master/src/peelingC.cpp"
    click Utils "https://github.com/wwylab/lfspro/blob/master/src/normal.cpp"
    click Doc "https://github.com/wwylab/lfspro/tree/master/man/"
    click DESCRIPTION "https://github.com/wwylab/lfspro/tree/master/DESCRIPTION"
    click NAMESPACE "https://github.com/wwylab/lfspro/tree/master/NAMESPACE"
    click README "https://github.com/wwylab/lfspro/blob/master/README.md"

    classDef code fill:#cfe2f3,stroke:#036;
    classDef data fill:#d9ead3,stroke:#090;
    classDef doc fill:#f9cb9c,stroke:#e69138;
    classDef external fill:#e0e0e0,stroke:#888;
    classDef build fill:#dddddd,stroke:#666;
```
