# morhadotsan/py2cpp-thesis architecture

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

- Interactive diagram: https://gitdiagram.com/morhadotsan/py2cpp-thesis
- Repository: https://github.com/morhadotsan/py2cpp-thesis

## Overview

py2cpp converts a project’s Python numerical computation and the library code it exercises into a standalone C++ program. The main workflow is discover executed code, prune it, record test inputs and outputs, translate, verify against Python, then hold out unseen inputs and save an accepted result. The UI and CLI expose this workflow; preparation can create a project target, and experiment and speed tools support thesis runs. Edges follow the README and source-index references; unsampled implementation details are not inferred.

Main entry points: [`py2cpp/app.py`](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/app.py) (Web UI), [`py2cpp/verify.py`](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/verify.py) (Compile and verify), [`py2cpp/prepare.py`](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prepare.py) (Target preparation), [`py2cpp/prune.py`](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prune.py) (AST pruning)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Conversion workflow"]
  node_ui["Web UI<br/>[app.py]"]
  node_config["Settings and paths<br/>[config.py]"]
  node_discover["Coverage discovery<br/>[discover.py]"]
  node_prune["AST pruning<br/>[prune.py]"]
  node_record["Case recording<br/>[record.py]"]
  node_prepare["Target preparation<br/>[prepare.py]"]
  node_verify["Compile and verify<br/>[verify.py]"]
  node_runs[("Run data")]
  node_results[("Accepted and fast outputs")]
end

subgraph group_translation["Code translation"]
  node_translate["C++ translation<br/>[translate.py]"]
  node_sources["Library source cache<br/>[sources.py]"]
end

subgraph group_runtime["Generated runtime"]
  node_cpp["Generated C++ program<br/>[prog.cpp]"]
  node_npy["NPY array I/O<br/>[npy.hpp]"]
end

subgraph group_research["Experiments"]
  node_experiment["Experiment runner<br/>[experiment.py]"]
  node_speed["Speed comparison<br/>[speed.py]"]
end

node_user(("Engineer"))
node_claude{{"Claude API"}}

node_user -->|"starts conversion"| node_ui
node_ui -->|"analyse"| node_discover
node_ui -->|"prune code"| node_prune
node_ui -->|"record cases"| node_record
node_ui -->|"convert and verify"| node_verify
node_ui -->|"prepare target"| node_prepare
node_ui -->|"show experiments"| node_experiment
node_discover -->|"measured code"| node_prune
node_prune -->|"pruned inputs"| node_record
node_record -->|"test cases"| node_verify
node_prune -->|"resolves library source"| node_sources
node_verify -->|"requests translation"| node_translate
node_prepare -->|"checks draft"| node_discover
node_prepare -->|"records draft cases"| node_record
node_prepare -->|"drafts target"| node_translate
node_translate -->|"sends code prompt"| node_claude
node_verify -->|"requests repairs"| node_claude
node_verify -->|"logs attempts"| node_runs
node_verify -->|"saves accepted program"| node_results
node_cpp -->|"loads and saves arrays"| node_npy
node_experiment -->|"reads recorded runs"| node_runs
node_speed -->|"writes speed report"| node_results

click node_ui "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/app.py"
click node_config "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/config.py"
click node_discover "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/discover.py"
click node_prune "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prune.py"
click node_record "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/record.py"
click node_prepare "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prepare.py"
click node_translate "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/translate.py"
click node_sources "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/sources.py"
click node_verify "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/verify.py"
click node_runs "https://github.com/morhadotsan/py2cpp-thesis/tree/main/runs"
click node_results "https://github.com/morhadotsan/py2cpp-thesis/tree/main/results"
click node_cpp "https://github.com/morhadotsan/py2cpp-thesis/blob/main/results/kmeans_fit/accepted/prog.cpp"
click node_npy "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/npy.hpp"
click node_experiment "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/experiment.py"
click node_speed "https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/speed.py"

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_ui,node_config,node_discover,node_prune,node_record,node_prepare,node_verify,node_runs,node_results toneBlue
class node_translate,node_sources toneAmber
class node_cpp,node_npy,node_claude toneMint
class node_experiment,node_speed toneRose
class node_user toneIndigo
```

## Components

### Conversion workflow

- [Web UI](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/app.py): `py2cpp/app.py`
- [Settings and paths](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/config.py): `py2cpp/config.py`
- [Coverage discovery](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/discover.py): `py2cpp/discover.py`
- [AST pruning](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prune.py): `py2cpp/prune.py`
- [Case recording](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/record.py): `py2cpp/record.py`
- [Target preparation](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/prepare.py): `py2cpp/prepare.py`
- [Compile and verify](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/verify.py): `py2cpp/verify.py`
- [Run data](https://github.com/morhadotsan/py2cpp-thesis/tree/main/runs): `runs`
- [Accepted and fast outputs](https://github.com/morhadotsan/py2cpp-thesis/tree/main/results): `results`

### Code translation

- [C++ translation](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/translate.py): `py2cpp/translate.py`
- [Library source cache](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/sources.py): `py2cpp/sources.py`

### Generated runtime

- [Generated C++ program](https://github.com/morhadotsan/py2cpp-thesis/blob/main/results/kmeans_fit/accepted/prog.cpp): `results/kmeans_fit/accepted/prog.cpp`
- [NPY array I/O](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/npy.hpp): `py2cpp/npy.hpp`

### Experiments

- [Experiment runner](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/experiment.py): `py2cpp/experiment.py`
- [Speed comparison](https://github.com/morhadotsan/py2cpp-thesis/blob/main/py2cpp/speed.py): `py2cpp/speed.py`

### Other components

- **Engineer**
- **Claude API**

## Connections

- Engineer → Web UI: starts conversion
- Web UI → Coverage discovery: analyse (evidence: `py2cpp/app.py`)
- Web UI → AST pruning: prune code (evidence: `py2cpp/app.py`)
- Web UI → Case recording: record cases (evidence: `py2cpp/app.py`)
- Web UI → Compile and verify: convert and verify (evidence: `py2cpp/app.py`)
- Web UI → Target preparation: prepare target (evidence: `py2cpp/app.py`)
- Web UI → Experiment runner: show experiments (evidence: `py2cpp/app.py`)
- Coverage discovery → AST pruning: measured code (evidence: `py2cpp/prune.py`)
- AST pruning → Case recording: pruned inputs
- Case recording → Compile and verify: test cases
- AST pruning → Library source cache: resolves library source (evidence: `py2cpp/prune.py`)
- Compile and verify → C++ translation: requests translation (evidence: `py2cpp/verify.py`)
- Target preparation → Coverage discovery: checks draft (evidence: `py2cpp/prepare.py`)
- Target preparation → Case recording: records draft cases (evidence: `py2cpp/prepare.py`)
- Target preparation → C++ translation: drafts target (evidence: `py2cpp/prepare.py`)
- C++ translation → Claude API: sends code prompt
- Compile and verify → Claude API: requests repairs
- Compile and verify → Run data: logs attempts
- Compile and verify → Accepted and fast outputs: saves accepted program
- Generated C++ program → NPY array I/O: loads and saves arrays (evidence: `results/kmeans_fit/accepted/prog.cpp`)
- Experiment runner → Run data: reads recorded runs
- Speed comparison → Accepted and fast outputs: writes speed report
