# natydasilva/classbound architecture

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

- Interactive diagram: https://gitdiagram.com/natydasilva/classbound
- Repository: https://github.com/natydasilva/classbound

## Overview

**classbound** is an R package built around a small pipeline for classification-boundary exploration: prepare 2D data, fit a supported classifier, compute predictions on a grid, and visualize the resulting decision surface.

1. **Primary user-facing API**
   The package centers on a few exported functions: `fit_model()`, `predict_model()`, `boundary_compute()`, `plot_boundary()`, and `preprocess_data()`. These form the main architectural path from raw data to boundary plot. The README’s example shows the intended flow clearly: fit a model, generate a prediction grid over a feature range, then plot that grid against the original observations.

2. **Model abstraction layer**
   The codebase is organized around a common adapter interface in `R/adapter_interface.R`, with concrete adapters for multiple classification backends:
   - `rpart`
   - `randomForest`
   - `pptree`
   - `PPforest`
   - `PPtreeViz`
   
   This is the key boundary in the system: the rest of the package works against a unified model contract rather than handling each learner separately.

3. **Fit pipeline**
   `fit_model()` is the entry point for model training. It likely delegates to the appropriate adapter based on the `method` argument, creating a fitted model object in a common wrapper format. That wrapper is what later functions consume, which keeps model-specific details isolated inside adapter files.

4. **Prediction pipeline**
   `predict_model()` is the second half of the abstraction. It provides a method-agnostic way to generate class predictions from fitted model objects. This is important because boundary computation depends on prediction being consistent across all supported learners.

5. **Decision-boundary computation**
   `boundary_compute()` is the transformation from a fitted classifier to a visualizable surface. It takes a 2D feature range and a resolution, constructs a grid of points over that space, and runs predictions across the grid. The output is a table-like boundary dataset suitable for plotting, rather than a model object or a plot object.

6. **Visualization layer**
   `plot_boundary()` is responsible for rendering the computed boundary together with the original observations. The architecture here separates computation from presentation: boundary generation is done first, then a dedicated visualization function converts it into a figure. The README indicates the plot includes both the predicted surface and the true labels from the observed data.

7. **Data preprocessing and compatibility**
   `preprocessing.R` suggests a normalization/validation step that adapts user data into the form required by the model and boundary pipeline. This is where the package likely handles class labels, feature selection, and consistent input formatting so that different backends can be used interchangeably.

8. **Interactive exploration subsystem**
   `app.R` and the exported `explorapp()` documentation indicate a Shiny-based interactive app. This app sits on top of the same core pipeline, likely letting users change model type, ranges, or preprocessing settings and immediately see how the boundary changes. It is an interface layer, not a separate computational engine.

9. **Synthetic and example data**
   `simulation.R` and `data69_1.R`/`data/data69_1.rda` provide built-in data and generated examples. These support reproducible demos, tests, and documentation. They are not part of the runtime pipeline, but they matter because they exercise the visualization and model adapters across known scenarios.

10. **Package testing and compatibility focus**
    The test suite is broad and explicitly names each backend (`test-rpart`, `test-randomForest`, `test-pptree`, `test-PPforest`, `test-PPtreeViz`), plus pipeline, boundary, preprocessing, and visualization tests. That indicates the main architectural risk the package manages is cross-model consistency: the same public API must behave correctly for every adapter.

11. **Documentation and developer tooling**
    The repository is a standard R package with `DESCRIPTION`, `NAMESPACE`, `man/`, `vignettes/`, and GitHub Actions for `R-CMD-check` and `pkgdown`. These are supporting layers around the core architecture: they ensure the package API is documented, the examples are reproducible, and the adapter/pipeline contract stays stable.

12. **Overall data flow**
    The end-to-end flow is: user data → preprocessing → adapter-based model fitting → adapter-based prediction on a grid → boundary dataset → boundary visualization or Shiny exploration. The strongest architectural boundary is between the model-specific adapters and the generic boundary/plotting pipeline.

Main entry points: [`R/adapter_interface.R`](https://github.com/natydasilva/classbound/blob/main/R/adapter_interface.R) (Adapter API), [`tests/testthat`](https://github.com/natydasilva/classbound/tree/main/tests/testthat) (Tests), [`R/fit_model.R`](https://github.com/natydasilva/classbound/blob/main/R/fit_model.R) (Fit model), [`R/app.R`](https://github.com/natydasilva/classbound/blob/main/R/app.R) (Exploration app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core pipeline"]
  node_preprocess_data["Preprocess<br/>API<br/>[preprocessing.R]"]
  node_fit_model["Fit model<br/>API<br/>[fit_model.R]"]
  node_predict_model["Predict model<br/>API<br/>[predict_model.R]"]
  node_boundary_compute["Boundary grid<br/>compute<br/>[boundary_compute.R]"]
  node_plot_boundary["Plot boundary<br/>visualization<br/>[visualization.R]"]
end

subgraph group_adapters["Model adapters"]
  node_adapter_interface["Adapter API<br/>contract"]
  node_rpart_adapter["rpart<br/>adapter<br/>[rpart_adapter.R]"]
  node_randomforest_adapter["randomForest<br/>adapter"]
  node_pptree_adapter["pptree<br/>adapter<br/>[pptree_adapter.R]"]
  node_ppforest_adapter["PPforest<br/>adapter<br/>[PPforest_adapter.R]"]
  node_pptreeviz_adapter["PPtreeViz<br/>adapter"]
end

subgraph group_support["Support"]
  node_app["Exploration app<br/>shiny app<br/>[app.R]"]
  node_simulation["Simulation<br/>examples<br/>[simulation.R]"]
  node_data69_1[("Example data<br/>dataset<br/>[data69_1.rda]")]
  node_tests["Tests<br/>test suite"]
  node_docs_pkg["Package docs"]
  node_pkgdown["Site config<br/>tooling<br/>[_pkgdown.yml]"]
  node_github_actions["CI workflows<br/>tooling<br/>[R-CMD-check.yaml]"]
end

node_preprocess_data -->|"prepared data"| node_fit_model
node_fit_model -->|"uses"| node_adapter_interface
node_adapter_interface -->|"implements"| node_rpart_adapter
node_adapter_interface -->|"implements"| node_randomforest_adapter
node_adapter_interface -->|"implements"| node_pptree_adapter
node_adapter_interface -->|"implements"| node_ppforest_adapter
node_adapter_interface -->|"implements"| node_pptreeviz_adapter
node_fit_model -->|"fitted model"| node_predict_model
node_predict_model -->|"grid predictions"| node_boundary_compute
node_boundary_compute -->|"boundary data"| node_plot_boundary
node_app -->|"uses"| node_preprocess_data
node_app -->|"uses"| node_fit_model
node_app -->|"uses"| node_boundary_compute
node_app -->|"uses"| node_plot_boundary
node_simulation -->|"example inputs"| node_data69_1
node_tests -.->|"covers"| node_preprocess_data
node_tests -.->|"covers"| node_boundary_compute
node_tests -.->|"covers"| node_plot_boundary
node_tests -.->|"covers"| node_adapter_interface
node_docs_pkg -.->|"documents"| node_fit_model
node_docs_pkg -.->|"documents"| node_plot_boundary
node_pkgdown -.->|"publishes"| node_docs_pkg
node_github_actions -.->|"runs"| node_tests

click node_preprocess_data "https://github.com/natydasilva/classbound/blob/main/R/preprocessing.R"
click node_fit_model "https://github.com/natydasilva/classbound/blob/main/R/fit_model.R"
click node_predict_model "https://github.com/natydasilva/classbound/blob/main/R/predict_model.R"
click node_boundary_compute "https://github.com/natydasilva/classbound/blob/main/R/boundary_compute.R"
click node_plot_boundary "https://github.com/natydasilva/classbound/blob/main/R/visualization.R"
click node_adapter_interface "https://github.com/natydasilva/classbound/blob/main/R/adapter_interface.R"
click node_rpart_adapter "https://github.com/natydasilva/classbound/blob/main/R/rpart_adapter.R"
click node_randomforest_adapter "https://github.com/natydasilva/classbound/blob/main/R/randomForest_adapter.R"
click node_pptree_adapter "https://github.com/natydasilva/classbound/blob/main/R/pptree_adapter.R"
click node_ppforest_adapter "https://github.com/natydasilva/classbound/blob/main/R/PPforest_adapter.R"
click node_pptreeviz_adapter "https://github.com/natydasilva/classbound/blob/main/R/PPtreeViz_adapter.R"
click node_app "https://github.com/natydasilva/classbound/blob/main/R/app.R"
click node_simulation "https://github.com/natydasilva/classbound/blob/main/R/simulation.R"
click node_data69_1 "https://github.com/natydasilva/classbound/blob/main/data/data69_1.rda"
click node_tests "https://github.com/natydasilva/classbound/tree/main/tests/testthat"
click node_docs_pkg "https://github.com/natydasilva/classbound/tree/main/DESCRIPTION"
click node_pkgdown "https://github.com/natydasilva/classbound/blob/main/_pkgdown.yml"
click node_github_actions "https://github.com/natydasilva/classbound/blob/main/.github/workflows/R-CMD-check.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_preprocess_data,node_fit_model,node_predict_model,node_boundary_compute,node_plot_boundary toneBlue
class node_adapter_interface,node_rpart_adapter,node_randomforest_adapter,node_pptree_adapter,node_ppforest_adapter,node_pptreeviz_adapter toneAmber
class node_app,node_simulation,node_data69_1,node_tests,node_docs_pkg,node_pkgdown,node_github_actions toneMint
```

## Components

### Core pipeline

User-facing data-to-boundary flow

- [Preprocess](https://github.com/natydasilva/classbound/blob/main/R/preprocessing.R): API · Validates and reshapes input data for the boundary pipeline · `R/preprocessing.R`
- [Fit model](https://github.com/natydasilva/classbound/blob/main/R/fit_model.R): API · Trains a classifier through the adapter layer · `R/fit_model.R`
- [Predict model](https://github.com/natydasilva/classbound/blob/main/R/predict_model.R): API · Generates method-agnostic class predictions from fitted models · `R/predict_model.R`
- [Boundary grid](https://github.com/natydasilva/classbound/blob/main/R/boundary_compute.R): compute · Builds a 2D prediction grid and computes decision surface values · `R/boundary_compute.R`
- [Plot boundary](https://github.com/natydasilva/classbound/blob/main/R/visualization.R): visualization · Renders the decision surface with the observed data · `R/visualization.R`

### Model adapters

Common classifier contract and backend implementations

- [Adapter API](https://github.com/natydasilva/classbound/blob/main/R/adapter_interface.R): contract · Shared interface used by all supported classifier backends · `R/adapter_interface.R`
- [rpart](https://github.com/natydasilva/classbound/blob/main/R/rpart_adapter.R): adapter · Backend adapter for rpart classification trees · `R/rpart_adapter.R`
- [randomForest](https://github.com/natydasilva/classbound/blob/main/R/randomForest_adapter.R): adapter · Backend adapter for randomForest classification models · `R/randomForest_adapter.R`
- [pptree](https://github.com/natydasilva/classbound/blob/main/R/pptree_adapter.R): adapter · Backend adapter for pptree models · `R/pptree_adapter.R`
- [PPforest](https://github.com/natydasilva/classbound/blob/main/R/PPforest_adapter.R): adapter · Backend adapter for PPforest models · `R/PPforest_adapter.R`
- [PPtreeViz](https://github.com/natydasilva/classbound/blob/main/R/PPtreeViz_adapter.R): adapter · Backend adapter for PPtreeViz models · `R/PPtreeViz_adapter.R`

### Support

Interactive app, examples, docs, and tests

- [Exploration app](https://github.com/natydasilva/classbound/blob/main/R/app.R): shiny app · Interactive front end for exploring boundaries and model settings · `R/app.R`
- [Simulation](https://github.com/natydasilva/classbound/blob/main/R/simulation.R): examples · Generates synthetic data used for demos and exploration · `R/simulation.R`
- [Example data](https://github.com/natydasilva/classbound/blob/main/data/data69_1.rda): dataset · Packaged example dataset for documentation and testing · `data/data69_1.rda`
- [Tests](https://github.com/natydasilva/classbound/tree/main/tests/testthat): test suite · Verifies pipeline behavior, preprocessing, boundary logic, and backend compatibility · `tests/testthat`
- [Package docs](https://github.com/natydasilva/classbound/tree/main/DESCRIPTION): docs · Package metadata, manual pages, README, and vignettes · `DESCRIPTION`
- [Site config](https://github.com/natydasilva/classbound/blob/main/_pkgdown.yml): tooling · Documentation site and package publishing configuration · `_pkgdown.yml`
- [CI workflows](https://github.com/natydasilva/classbound/blob/main/.github/workflows/R-CMD-check.yaml): tooling · Automated checks and site build workflows · `.github/workflows/R-CMD-check.yaml`

## Connections

- Preprocess → Fit model: prepared data · Cleaned data is passed into training
- Fit model → Adapter API: uses · Training goes through the common adapter contract
- Adapter API → rpart: implements · Concrete backend implementation
- Adapter API → randomForest: implements · Concrete backend implementation
- Adapter API → pptree: implements · Concrete backend implementation
- Adapter API → PPforest: implements · Concrete backend implementation
- Adapter API → PPtreeViz: implements · Concrete backend implementation
- Fit model → Predict model: fitted model · Trained models are consumed by prediction
- Predict model → Boundary grid: grid predictions · Boundary computation depends on consistent prediction across backends
- Boundary grid → Plot boundary: boundary data · Computed surface is rendered by the plotting layer
- Exploration app → Preprocess: uses · Interactive exploration starts from the same preprocessing step
- Exploration app → Fit model: uses · The app can train supported models on demand
- Exploration app → Boundary grid: uses · The app updates boundary surfaces interactively
- Exploration app → Plot boundary: uses · The app displays the resulting plot
- Simulation → Example data: example inputs · Synthetic and packaged data support reproducible examples
- Tests → Preprocess: covers · Validates preprocessing behavior
- Tests → Boundary grid: covers · Validates boundary generation
- Tests → Plot boundary: covers · Validates visualization output
- Tests → Adapter API: covers · Checks cross-backend consistency
- Package docs → Fit model: documents · Manual pages and README describe the main API
- Package docs → Plot boundary: documents · Documentation includes the plotting workflow
- Site config → Package docs: publishes · Site configuration supports package documentation publishing
- CI workflows → Tests: runs · CI executes the test suite and package checks
