# matrix-profile-foundation/tsmp architecture

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

- Interactive diagram: https://gitdiagram.com/matrix-profile-foundation/tsmp
- Repository: https://github.com/matrix-profile-foundation/tsmp

## Overview

##### Project Type and Purpose
- tsmp is an R package (library) with performance‐critical routines in C++ (via Rcpp).
- It implements a suite of time‐series algorithms (STAMP, STOMP, SCRIMP++, etc.) and provides plotting, data loading, and a test harness.
- It targets both interactive R users and automated CI/CD (CRAN submission, pkgdown site).

##### Break Down Top‐Level Components
A. R API Layer
- Directory: R/
- Exposes user‐facing functions (tsmp(), find_motif(), sdts_train(), plot(), etc.).
- Uses RcppExports.R to call into C++ routines.
B. C++ Core Library
- Directory: src/
- Contains performance functions (math.cpp, mpx.cpp, windowfunc.cpp).
- Compiled into a shared library loaded by RcppExports.
C. Data & Resources
- Directory: data/ and inst/
- Prebuilt .rda datasets (mptoy, mp_test_data, motifs_discords_small) and API versioned examples.
- Schema files, word lists, and raw resources for examples.
D. Documentation
- Directory: man/, vignettes/, README.md, pkgdown/
- Rd manuals (man/*.Rd), tutorial vignettes, and pkgdown site config.
E. Testing & Quality
- Directory: tests/ (testthat, prints, figs, spelling)
- Ensures correctness of R API and C++ bindings.
F. Build & CI/CD
- Files: DESCRIPTION, NAMESPACE, Makevars, renv.lock
- CI workflows: .github/workflows/codeql-analysis.yml, .circleci/config.yml, appveyor.yml.
- Code coverage and CRAN checks (codecov.yml, .Rbuildignore, .covrignore).
G. Deployment Targets
- CRAN (R package repository)
- GitHub (source, CI badges)
- pkgdown site (matrixprofile.org/tsmp)

##### Relationships & Data Flows
- R API → RcppExports.R → C++ Shared Library → core algorithms
- tsmp functions → data/ → in‐memory objects
- tests drive R API, which in turn drives C++ code paths
- CI triggers: GitHub push → CI pipelines → test suite & coverage → pkgdown build → CRAN submission checks

##### Architectural Patterns
- Layered architecture:
- Presentation/API Layer (R code)
- Core Engine Layer (C++ via Rcpp)
- Data/Resources Layer (inst/, data/)
- Infrastructure Layer (CI, renv, package metadata)
- Modularization: each algorithm in its own R file, each C++ feature in its own source file.
- Automated build & deployment pipeline.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Layers and Components
    subgraph "API Layer (R)" 
        R_API["R/ (R API Layer)"]:::rapi
    end

    subgraph "C++ Core Library"
        Cpp_Core["src/ (C++ Core Library)"]:::cpp
    end

    subgraph "Data & Resources"
        Data["data/"]:::data
        Inst["inst/"]:::data
    end

    subgraph "Documentation"
        Man["man/"]:::docs
        Vign["vignettes/"]:::docs
        Readme["README.md"]:::docs
        Pkgdown_docs["_pkgdown/"]:::docs
    end

    subgraph "Testing & Quality"
        Tests["tests/"]:::test
    end

    subgraph "Build & CI/CD Infrastructure"
        PackageMeta["DESCRIPTION, NAMESPACE,\n.Rbuildignore, .covrignore"]:::infra
        Renv["renv/"]:::infra
        GH["GitHub Actions"]:::infra
        Circle["CircleCI"]:::infra
        Appv["AppVeyor"]:::infra
        Codecov["Codecov"]:::infra
    end

    subgraph "Deployment Targets"
        GitHub["GitHub (source & CI badges)"]:::external
        CRAN["CRAN"]:::external
        Pkgsite["pkgdown site"]:::external
    end

    %% Relationships
    R_API -->|"Rcpp call"| Cpp_Core
    R_API -->|"loads data"| Data
    R_API -->|"uses resources"| Inst
    Tests <-->|"unit tests"| R_API
    GH -->|"push trigger"| Circle
    GH -->|"push trigger"| Appv
    GH -->|"push trigger"| Codecov
    Circle -->|"run tests"| Tests
    Appv -->|"run tests"| Tests
    Codecov -->|"collect coverage"| Tests
    Tests -->|"feedback"| R_API
    Circle -->|"build docs"| Man
    Circle -->|"build docs"| Vign
    Circle -->|"build docs"| Readme
    Circle -->|"build site"| Pkgdown_docs
    Circle -->|"deploy"| CRAN
    Circle -->|"deploy"| Pkgsite
    GitHub -->|"host repo"| R_API
    Renv -->|"pins deps for"| PackageMeta
    PackageMeta -->|"configures build"| Cpp_Core

    %% Deployment arrows
    GitHub -->|"push"| GH

    %% Click Events
    click R_API "https://github.com/matrix-profile-foundation/tsmp/tree/master/R/"
    click Cpp_Core "https://github.com/matrix-profile-foundation/tsmp/tree/master/src/"
    click Data "https://github.com/matrix-profile-foundation/tsmp/tree/master/data/"
    click Inst "https://github.com/matrix-profile-foundation/tsmp/tree/master/inst/"
    click Man "https://github.com/matrix-profile-foundation/tsmp/tree/master/man/"
    click Vign "https://github.com/matrix-profile-foundation/tsmp/tree/master/vignettes/"
    click Readme "https://github.com/matrix-profile-foundation/tsmp/blob/master/README.md"
    click Pkgdown_docs "https://github.com/matrix-profile-foundation/tsmp/tree/master/pkgdown/"
    click Tests "https://github.com/matrix-profile-foundation/tsmp/tree/master/tests/"
    click Renv "https://github.com/matrix-profile-foundation/tsmp/tree/master/renv/"
    click GH "https://github.com/matrix-profile-foundation/tsmp/blob/master/.github/workflows/codeql-analysis.yml"
    click Circle "https://github.com/matrix-profile-foundation/tsmp/blob/master/.circleci/config.yml"
    click Appv "https://github.com/matrix-profile-foundation/tsmp/blob/master/appveyor.yml"
    click Codecov "https://github.com/matrix-profile-foundation/tsmp/blob/master/codecov.yml"

    %% Styles
    classDef rapi fill:#D0E8FF,stroke:#0066CC,color:#000;
    classDef cpp fill:#D0FFD8,stroke:#009900,color:#000;
    classDef data fill:#FFE8B0,stroke:#CC6600,color:#000;
    classDef docs fill:#F0F0F0,stroke:#666666,color:#000;
    classDef test fill:#FFD0D0,stroke:#CC0000,color:#000;
    classDef infra fill:#E8D0FF,stroke:#660099,color:#000;
    classDef external fill:#EFEFEF,stroke:#888888,color:#000;
```
