# fenndd/bachelorsproject architecture

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

- Interactive diagram: https://gitdiagram.com/fenndd/bachelorsproject
- Repository: https://github.com/fenndd/bachelorsproject

## Overview

1. **Project purpose and scope**  
   This repository is a scaffold for automating optimization of C++ 3D vision algorithms with LLM assistance. The first concrete use case is a P3P solver, so the architecture is centered on running, comparing, and eventually modifying C++ solver variants.

2. **Two main runtime domains**  
   The system is split into a **C++ algorithm layer** and a **Python orchestration layer**. C++ contains the actual solver code and buildable baseline executable; Python coordinates build/run/analysis workflows around that executable.

3. **C++ core and baseline boundary**  
   `cpp/src/baseline_runner.cpp` is the project-owned baseline entry point. It is linked against the imported third-party Lambda Twist P3P implementation under `cpp/external/lambdatwist/`, which acts as the clean external baseline and should remain unchanged in the current baseline state.

4. **Build and native tooling**  
   `cpp/CMakeLists.txt` defines the native build boundary. The C++ tree also includes placeholders for `tests/` and `bench/`, indicating that validation and benchmarking are intended to be native concerns, even though the README says those stages are not yet fully implemented.

5. **Orchestration layer as control plane**  
   The Python package under `orchestrator/` is the control plane for experiments. The current entry point is `orchestrator/cli/main.py`, which the README describes as the minimal CLI for baseline configure/build/run automation.

6. **Execution subsystem**  
   `orchestrator/execution/` separates the external process steps into distinct runners: `build_runner.py`, `test_runner.py`, and `benchmark_runner.py`. This is the boundary where the Python side invokes native tooling and captures outcomes from CMake/build/test/benchmark operations.

7. **Optimization workflow scaffolding**  
   `orchestrator/llm/`, `orchestrator/patching/`, and `orchestrator/pipeline/` define the future optimization loop. `prompt_builder.py` and `base_adapter.py` suggest a provider-agnostic LLM interface, while `apply_patch.py` is the mechanism for turning generated edits into modified source trees inside the workspace.

8. **Experiment state, persistence, and selection**  
   `orchestrator/storage/` holds run metadata and result bookkeeping (`result_store.py`, `run_index.py`), while `orchestrator/analysis/select_best.py` indicates post-run ranking or winner selection. This creates a separation between transient execution data and persistent experiment history.

9. **Workspace and results as environment boundaries**  
   The repository uses `workspace/` for ephemeral run-specific files and `results/` for durable outputs. That separation is important architecturally: source-controlled code remains clean, while generated patches, build artifacts, and experiment outputs are isolated from the repo state.

10. **Configuration-driven experiments**  
   `configs/defaults/`, `configs/models/`, and `configs/experiments/` provide a config hierarchy for defaults, model settings, and experiment definitions. This implies runs are intended to be parameterized rather than hardcoded, with configuration files driving orchestration behavior.

11. **Documentation and roadmap as architectural contract**  
   `docs/architecture.md`, `docs/baseline.md`, `docs/setup.md`, and `docs/roadmap.md` document the intended system boundaries and current implementation status. The README makes clear that baseline integration exists, while validation, benchmarking, and the optimization loop are scaffolded but not yet complete.

12. **Overall data flow**  
   The practical flow is: configuration in `configs/` → Python CLI in `orchestrator/cli/` → build/run via `orchestrator/execution/` against the C++ baseline in `cpp/` → outputs written to `workspace/` and persisted in `results/` → analysis/reporting via `orchestrator/analysis/` and `orchestrator/reporting/`. The future LLM-assisted loop will insert patch generation and code modification between analysis and execution.

Main entry points: [`orchestrator/pipeline/run_pipeline.py`](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/pipeline/run_pipeline.py) (Pipeline), [`cpp/src/baseline_runner.cpp`](https://github.com/fenndd/bachelorsproject/blob/main/cpp/src/baseline_runner.cpp) (Baseline runner), [`orchestrator/cli/main.py`](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/cli/main.py) (CLI), [`orchestrator/execution/build_runner.py`](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/build_runner.py) (Build runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_cpp["C++ core"]
  node_cpp_cmake["CMake<br/>native build<br/>[CMakeLists.txt]"]
  node_cpp_baseline_runner["Baseline runner<br/>C++ entrypoint"]
  node_cpp_lambdatwist["LambdaTwist<br/>third-party P3P<br/>[p3p.cc]"]
  node_cpp_p3p_header["P3P API<br/>solver interface<br/>[p3p.h]"]
  node_cpp_p3p_test["Upstream test<br/>external test<br/>[p3p_test.cc]"]
end

subgraph group_group_orchestrator["Python orchestration"]
  node_orch_cli["CLI<br/>Python entrypoint<br/>[main.py]"]
  node_orch_pipeline["Pipeline<br/>workflow coordinator<br/>[run_pipeline.py]"]
  node_orch_build["Build runner<br/>native runner<br/>[build_runner.py]"]
  node_orch_test["Test runner<br/>native runner<br/>[test_runner.py]"]
  node_orch_bench["Benchmark runner<br/>native runner"]
  node_orch_llm_adapter["LLM adapter<br/>provider interface<br/>[base_adapter.py]"]
  node_orch_prompt["Prompt builder<br/>prompting<br/>[prompt_builder.py]"]
  node_orch_patch["Patch applier<br/>source patching<br/>[apply_patch.py]"]
  node_orch_store[("Result store<br/>experiment storage<br/>[result_store.py]")]
  node_orch_index["Run index<br/>run registry<br/>[run_index.py]"]
  node_orch_select["Best select<br/>analysis<br/>[select_best.py]"]
  node_orch_report["Report gen<br/>reporting<br/>[generate_report.py]"]
end

subgraph group_group_config["Config and state"]
  node_config_defaults["Defaults<br/>project config"]
  node_config_model["Model config<br/>llm config<br/>[example_model.yaml]"]
  node_config_experiment["Experiment config<br/>run config"]
  node_workspace[("Workspace<br/>ephemeral area<br/>[.gitkeep]")]
  node_results[("Results<br/>output area<br/>[.gitkeep]")]
end

subgraph group_group_docs["Docs"]
  node_docs_arch["Architecture doc<br/>documentation<br/>[architecture.md]"]
  node_docs_baseline["Baseline doc<br/>documentation<br/>[baseline.md]"]
  node_docs_setup["Setup doc<br/>documentation<br/>[setup.md]"]
  node_docs_roadmap["Roadmap<br/>planning doc<br/>[roadmap.md]"]
end

node_cpp_cmake -->|"builds"| node_cpp_baseline_runner
node_cpp_baseline_runner -->|"links to"| node_cpp_lambdatwist
node_cpp_baseline_runner -->|"uses API"| node_cpp_p3p_header
node_cpp_lambdatwist -->|"validated by"| node_cpp_p3p_test
node_config_experiment -->|"drives"| node_orch_cli
node_config_defaults -->|"sets defaults"| node_orch_cli
node_config_model -->|"configures"| node_orch_llm_adapter
node_orch_cli -->|"invokes"| node_orch_pipeline
node_orch_pipeline -->|"runs"| node_orch_build
node_orch_pipeline -->|"runs"| node_orch_test
node_orch_pipeline -->|"runs"| node_orch_bench
node_orch_build -->|"calls"| node_cpp_cmake
node_orch_test -->|"executes"| node_cpp_baseline_runner
node_orch_bench -->|"measures"| node_cpp_baseline_runner
node_orch_pipeline -->|"queries"| node_orch_llm_adapter
node_orch_llm_adapter -->|"uses"| node_orch_prompt
node_orch_pipeline -->|"applies edits"| node_orch_patch
node_orch_patch -->|"writes"| node_workspace
node_orch_build -->|"builds in"| node_workspace
node_orch_test -->|"records"| node_results
node_orch_bench -->|"records"| node_results
node_orch_pipeline -->|"persists"| node_orch_store
node_orch_store -->|"indexes"| node_orch_index
node_orch_store -->|"feeds"| node_orch_select
node_orch_select -->|"summarizes"| node_orch_report
node_orch_report -->|"publishes"| node_results
node_docs_arch -->|"describes"| node_orch_pipeline
node_docs_baseline -->|"describes"| node_cpp_baseline_runner
node_docs_setup -->|"guides"| node_orch_cli
node_docs_roadmap -->|"projects"| node_orch_patch

click node_cpp_cmake "https://github.com/fenndd/bachelorsproject/blob/main/cpp/CMakeLists.txt"
click node_cpp_baseline_runner "https://github.com/fenndd/bachelorsproject/blob/main/cpp/src/baseline_runner.cpp"
click node_cpp_lambdatwist "https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p.cc"
click node_cpp_p3p_header "https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p.h"
click node_cpp_p3p_test "https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p_test.cc"
click node_orch_cli "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/cli/main.py"
click node_orch_pipeline "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/pipeline/run_pipeline.py"
click node_orch_build "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/build_runner.py"
click node_orch_test "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/test_runner.py"
click node_orch_bench "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/benchmark_runner.py"
click node_orch_llm_adapter "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/llm/base_adapter.py"
click node_orch_prompt "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/llm/prompt_builder.py"
click node_orch_patch "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/patching/apply_patch.py"
click node_orch_store "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/storage/result_store.py"
click node_orch_index "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/storage/run_index.py"
click node_orch_select "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/analysis/select_best.py"
click node_orch_report "https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/reporting/generate_report.py"
click node_config_defaults "https://github.com/fenndd/bachelorsproject/blob/main/configs/defaults/project_defaults.yaml"
click node_config_model "https://github.com/fenndd/bachelorsproject/blob/main/configs/models/example_model.yaml"
click node_config_experiment "https://github.com/fenndd/bachelorsproject/blob/main/configs/experiments/example_experiment.yaml"
click node_workspace "https://github.com/fenndd/bachelorsproject/blob/main/workspace/.gitkeep"
click node_results "https://github.com/fenndd/bachelorsproject/blob/main/results/.gitkeep"
click node_docs_arch "https://github.com/fenndd/bachelorsproject/blob/main/docs/architecture.md"
click node_docs_baseline "https://github.com/fenndd/bachelorsproject/blob/main/docs/baseline.md"
click node_docs_setup "https://github.com/fenndd/bachelorsproject/blob/main/docs/setup.md"
click node_docs_roadmap "https://github.com/fenndd/bachelorsproject/blob/main/docs/roadmap.md"

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_cpp_cmake,node_cpp_baseline_runner,node_cpp_lambdatwist,node_cpp_p3p_header,node_cpp_p3p_test toneBlue
class node_orch_cli,node_orch_pipeline,node_orch_build,node_orch_test,node_orch_bench,node_orch_llm_adapter,node_orch_prompt,node_orch_patch,node_orch_store,node_orch_index,node_orch_select,node_orch_report toneAmber
class node_config_defaults,node_config_model,node_config_experiment,node_workspace,node_results toneMint
class node_docs_arch,node_docs_baseline,node_docs_setup,node_docs_roadmap toneRose
```

## Components

### C++ core

Native solver and build boundary

- [CMake](https://github.com/fenndd/bachelorsproject/blob/main/cpp/CMakeLists.txt): native build · Defines the native build boundary for the C++ solver · `cpp/CMakeLists.txt`
- [Baseline runner](https://github.com/fenndd/bachelorsproject/blob/main/cpp/src/baseline_runner.cpp): C++ entrypoint · Project-owned executable entry point for the baseline solver · `cpp/src/baseline_runner.cpp`
- [LambdaTwist](https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p.cc): third-party P3P · Imported external P3P implementation used as the clean baseline · `cpp/external/lambdatwist/p3p.cc`
- [P3P API](https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p.h): solver interface · Header boundary for the external P3P implementation · `cpp/external/lambdatwist/p3p.h`
- [Upstream test](https://github.com/fenndd/bachelorsproject/blob/main/cpp/external/lambdatwist/p3p_test.cc): external test · Reference test for the imported LambdaTwist implementation · `cpp/external/lambdatwist/p3p_test.cc`

### Python orchestration

Experiment control plane and workflow stages

- [CLI](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/cli/main.py): Python entrypoint · Minimal command-line entry for baseline and experiment automation · `orchestrator/cli/main.py`
- [Pipeline](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/pipeline/run_pipeline.py): workflow coordinator · Coordinates end-to-end experiment runs · `orchestrator/pipeline/run_pipeline.py`
- [Build runner](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/build_runner.py): native runner · Invokes native build steps through the Python control plane · `orchestrator/execution/build_runner.py`
- [Test runner](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/test_runner.py): native runner · Runs validation steps against built solver artifacts · `orchestrator/execution/test_runner.py`
- [Benchmark runner](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/execution/benchmark_runner.py): native runner · Runs performance measurements for solver variants · `orchestrator/execution/benchmark_runner.py`
- [LLM adapter](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/llm/base_adapter.py): provider interface · Provider-agnostic abstraction for model calls · `orchestrator/llm/base_adapter.py`
- [Prompt builder](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/llm/prompt_builder.py): prompting · Builds prompts for optimization and patch generation · `orchestrator/llm/prompt_builder.py`
- [Patch applier](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/patching/apply_patch.py): source patching · Applies generated edits into the workspace · `orchestrator/patching/apply_patch.py`
- [Result store](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/storage/result_store.py): experiment storage · Persists run metadata and outcomes · `orchestrator/storage/result_store.py`
- [Run index](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/storage/run_index.py): run registry · Tracks experiment runs and their identifiers · `orchestrator/storage/run_index.py`
- [Best select](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/analysis/select_best.py): analysis · Ranks results and selects the best candidate · `orchestrator/analysis/select_best.py`
- [Report gen](https://github.com/fenndd/bachelorsproject/blob/main/orchestrator/reporting/generate_report.py): reporting · Generates human-readable experiment reports · `orchestrator/reporting/generate_report.py`

### Config and state

Parameterization, workspace, and results

- [Defaults](https://github.com/fenndd/bachelorsproject/blob/main/configs/defaults/project_defaults.yaml): project config · Baseline project defaults for experiments and runs · `configs/defaults/project_defaults.yaml`
- [Model config](https://github.com/fenndd/bachelorsproject/blob/main/configs/models/example_model.yaml): llm config · Model-specific settings for LLM-assisted workflows · `configs/models/example_model.yaml`
- [Experiment config](https://github.com/fenndd/bachelorsproject/blob/main/configs/experiments/example_experiment.yaml): run config · Concrete experiment definition driving orchestration · `configs/experiments/example_experiment.yaml`
- [Workspace](https://github.com/fenndd/bachelorsproject/blob/main/workspace/.gitkeep): ephemeral area · Scratch space for run-specific files and modified trees · `workspace/.gitkeep`
- [Results](https://github.com/fenndd/bachelorsproject/blob/main/results/.gitkeep): output area · Durable outputs and experiment artifacts · `results/.gitkeep`

### Docs

Architecture and project guidance

- [Architecture doc](https://github.com/fenndd/bachelorsproject/blob/main/docs/architecture.md): documentation · Explains repository boundaries and design intent · `docs/architecture.md`
- [Baseline doc](https://github.com/fenndd/bachelorsproject/blob/main/docs/baseline.md): documentation · Documents the current baseline state and solver boundary · `docs/baseline.md`
- [Setup doc](https://github.com/fenndd/bachelorsproject/blob/main/docs/setup.md): documentation · Describes environment setup and local usage · `docs/setup.md`
- [Roadmap](https://github.com/fenndd/bachelorsproject/blob/main/docs/roadmap.md): planning doc · Tracks intended future capabilities and incomplete stages · `docs/roadmap.md`

## Connections

- CMake → Baseline runner: builds · Native build produces the baseline executable
- Baseline runner → LambdaTwist: links to · Project-owned entry point wraps the imported solver
- Baseline runner → P3P API: uses API · Baseline runner depends on the external solver interface
- LambdaTwist → Upstream test: validated by · Imported implementation includes its own reference test
- Experiment config → CLI: drives · Experiment definitions are consumed by the CLI and pipeline
- Defaults → CLI: sets defaults · Project defaults parameterize orchestration behavior
- Model config → LLM adapter: configures · Model settings feed the provider-agnostic adapter
- CLI → Pipeline: invokes · CLI hands control to the experiment pipeline
- Pipeline → Build runner: runs · Pipeline stages invoke the native build runner
- Pipeline → Test runner: runs · Pipeline stages invoke validation after build
- Pipeline → Benchmark runner: runs · Pipeline stages can benchmark solver variants
- Build runner → CMake: calls · Build runner executes the CMake-defined native build
- Test runner → Baseline runner: executes · Test runner runs the built baseline or variants
- Benchmark runner → Baseline runner: measures · Benchmarking targets the solver executable
- Pipeline → LLM adapter: queries · Optimization loop requests model assistance
- LLM adapter → Prompt builder: uses · Adapter relies on prompt construction for requests
- Pipeline → Patch applier: applies edits · Generated changes are materialized into the workspace
- Patch applier → Workspace: writes · Patch application updates ephemeral run files
- Build runner → Workspace: builds in · Native builds are staged inside the workspace boundary
- Test runner → Results: records · Validation outcomes are persisted as experiment outputs
- Benchmark runner → Results: records · Benchmark outputs are stored for later comparison
- Pipeline → Result store: persists · Pipeline stores run metadata and outcomes
- Result store → Run index: indexes · Persistent storage is organized by run identifiers
- Result store → Best select: feeds · Stored results are used for winner selection
- Best select → Report gen: summarizes · Selected results are turned into reports
- Report gen → Results: publishes · Reports are emitted into the durable results area
- Architecture doc → Pipeline: describes · Documentation captures the orchestration architecture
- Baseline doc → Baseline runner: describes · Baseline documentation explains the solver boundary
- Setup doc → CLI: guides · Setup instructions support local orchestration usage
- Roadmap → Patch applier: projects · Roadmap calls out future optimization and patching work
