# rcppcore/rcpp architecture

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

- Interactive diagram: https://gitdiagram.com/rcppcore/rcpp
- Repository: https://github.com/rcppcore/rcpp

## Overview

##### Project type and purpose
- This is an open-source R package (“Rcpp”) that provides seamless integration between R and C++.
- It serves as both an R package (R code + registration) and a header-only C++ library (inst/include) to map R’s internal SEXP types to C++ classes, support “sugar,” “modules,” and “attributes.”
- It is distributed via CRAN/GitHub, built with R CMD INSTALL, and tested via tinytest+GitHub Actions+Docker.

##### File-structure analysis
- Top-level directories:
- R/        → R wrapper functions, registration, attribute handlers
- src/      → C++ source, Makevars, module initialization, API glue
- inst/include/ → Header-only C++ library, organized by component (Vector, sugar, stats, etc.)
- man/, vignettes/ → Documentation
- inst/examples/, inst/skeleton/ → Example code & code skeletons
- inst/tinytest/ → Unit tests (C++ & R)
- .github/, docker/ → CI/CD pipelines and Docker images
- Patterns:
- “Attributes” codegen: R/03_prompt.R etc. generate wrappers for C++ functions at install time.
- “Modules”: src/module.cpp + header inst/include/Rcpp/module
- “Sugar”: template-based lazy evaluation in inst/include/Rcpp/sugar
- Build scripts: src/Makevars(.win); Rcpp.package.skeleton.R; Dockerfiles for multiple R versions.

##### Key insights from README
- Single package exposing: Rcpp::wrap / Rcpp::as (conversion templates), Rcpp sugar, Rcpp modules, Rcpp attributes.
- Documentation delivered via ten PDF vignettes, extensive man pages, Rcpp book.
- Testing: tinytest harness, >1000 unit tests.
- CI: GitHub Actions (linux, macOS, ARM), Docker-based clean builds.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% R Layer
    subgraph "R Layer"
        RU("R User"):::user
        subgraph "Rcpp R API"
            R1["R/ (Rcpp R API)"]:::r
            R2["Attributes Codegen"]:::r
            R3["Modules R wrappers"]:::r
            R4["Package skeleton generator"]:::r
        end
        RU -->|"calls"| R1
        R1 -->|"generates wrappers"| R2
        R1 -->|"loads modules"| R3
        R4 -.->|"skeleton for users"| R1
    end

    %% C++ Headers
    subgraph "C++ Headers"
        C1["Core templates"]:::cpp
        C2["Sugar templates"]:::cpp
        C3["Modules support"]:::cpp
        C4["API bones"]:::cpp
    end

    %% Compiled Shared Library
    subgraph "Compiled Shared Library"
        SL["src/"]:::cpp
    end

    %% R Core API
    RAPI["R Core API (SEXP)"]:::external

    %% Build Pipeline
    subgraph "Build Pipeline"
        SFS["Source Files (R/, src/)"]:::infra
        CG["Codegen (Attributes/Modules)"]:::infra
        CMP["Compilation via Makevars"]:::infra
        PB["Package Bundle"]:::infra
        SFS --> CG --> CMP --> PB
    end

    %% Examples & Docs
    subgraph "Examples & Docs"
        EX1["Examples"]:::r
        EX2["Benchmarks"]:::r
        D1["Vignettes"]:::r
        D2["Man pages"]:::r
    end

    %% Testing Harness
    TH["Unit Tests"]:::infra

    %% CI/CD & Distribution
    subgraph "CI/CD & Distribution"
        GH["GitHub"]:::external
        CI["GitHub Actions CI"]:::infra
        DK["Docker builds/tests"]:::infra
        CR["CRAN/Drat"]:::external
        GH --> CI --> DK --> CR
    end

    %% Connections
    R1 -->|".Call/.External"| SL
    SL <--> C1
    SL --> C2
    SL --> C3
    SL --> C4
    SL -->|"calls"| RAPI
    PB --> GH
    PB --> EX1
    PB --> EX2
    PB --> D1
    PB --> D2
    PB --> TH

    %% Click Events
    click R1 "https://github.com/rcppcore/rcpp/tree/master/R/"
    click R2 "https://github.com/rcppcore/rcpp/blob/master/R/03_prompt.R"
    click R2 "https://github.com/rcppcore/rcpp/blob/master/R/02_completion.R"
    click R2 "https://github.com/rcppcore/rcpp/blob/master/R/01_show.R"
    click R3 "https://github.com/rcppcore/rcpp/blob/master/R/Module.R"
    click R3 "https://github.com/rcppcore/rcpp/blob/master/R/loadModule.R"
    click R3 "https://github.com/rcppcore/rcpp/blob/master/R/loadRcppModules.R"
    click R4 "https://github.com/rcppcore/rcpp/blob/master/R/Rcpp.package.skeleton.R"
    click R4 "https://github.com/rcppcore/rcpp/tree/master/inst/skeleton/"
    click C1 "https://github.com/rcppcore/rcpp/tree/master/inst/include/Rcpp/"
    click C2 "https://github.com/rcppcore/rcpp/tree/master/inst/include/Rcpp/sugar/"
    click C3 "https://github.com/rcppcore/rcpp/tree/master/inst/include/Rcpp/module/"
    click C4 "https://github.com/rcppcore/rcpp/tree/master/inst/include/Rcpp/api/"
    click SL "https://github.com/rcppcore/rcpp/tree/master/src/"
    click EX1 "https://github.com/rcppcore/rcpp/tree/master/inst/examples/"
    click EX2 "https://github.com/rcppcore/rcpp/tree/master/inst/examples/ConvolveBenchmarks/"
    click D1 "https://github.com/rcppcore/rcpp/tree/master/vignettes/"
    click D2 "https://github.com/rcppcore/rcpp/tree/master/man/"
    click TH "https://github.com/rcppcore/rcpp/tree/master/inst/tinytest/"

    %% Styles
    classDef user fill:#90ee90,stroke:#333,stroke-width:1px,shape:ellipse
    classDef r fill:#90ee90,stroke:#333,stroke-width:1px
    classDef cpp fill:#add8e6,stroke:#333,stroke-width:1px
    classDef infra fill:#d3d3d3,stroke:#333,stroke-width:1px,shape:hexagon
    classDef external fill:#ffa500,stroke:#333,stroke-width:1px,shape:cloud
```
