# bnnr-team/bnnr architecture

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

- Interactive diagram: https://gitdiagram.com/bnnr-team/bnnr
- Repository: https://github.com/bnnr-team/bnnr

## Overview

1. **Repository shape**
   - This is a Python package centered on `src/bnnr`, with a separate React/Vite dashboard in `dashboard_web`.
   - The package ships a built dashboard bundle under `src/bnnr/dashboard/frontend/dist`, so the Python runtime can serve the UI without rebuilding it.

2. **Primary product boundary**
   - BNNR is a closed-loop vision workflow: train a model, analyze failures with XAI, generate improved augmentations, then validate and report the result.
   - The core architectural boundary is between the **training/analysis engine** in Python and the **interactive dashboard/reporting layer**.

3. **Entry points and orchestration**
   - `python -m bnnr` is the main CLI surface (`src/bnnr/cli.py`, `__main__.py`).
   - Key CLI flows are training, reporting, dataset/augmentation/preset listing, and dashboard serving/export.
   - `quick_run`, `pipelines`, and `core`/`craft` appear to be the main orchestration modules that stitch together configuration, training, evaluation, and artifact generation.

4. **Configuration and runtime control**
   - `BNNRConfig` in `config.py` is the central contract for experiment settings.
   - The README and tests suggest it drives dataset selection, task type, metrics, pruning, checkpoint/report paths, device choice, seeds, XAI toggles, and iteration limits.
   - This config layer is the main boundary between user intent and the rest of the system.

5. **Task adapters and model integration**
   - `adapter.py`, `detection_adapter.py`, and `lightning_adapter.py` in examples indicate an adapter-based design for plugging in custom models and dataloaders.
   - The repo supports multiple task families with different data/metric paths: single-label classification, multilabel classification, and object detection.
   - Detection has its own specialized modules for collation, metrics, augmentations, and XAI, which implies a separate sub-pipeline rather than a thin wrapper over classification.

6. **Augmentation subsystem**
   - Augmentation logic is a major subsystem: `augmentations.py`, `albumentations_aug.py`, `kornia_aug.py`, `detection_augmentations.py`, and `augmentation_runner.py`.
   - The architecture supports both CPU-style augmentation integration and GPU-accelerated augmentation via Kornia, with Albumentations as an optional integration.
   - This subsystem is part of the feedback loop: selected augmentations are applied, measured, and then fed back into improved training runs.

7. **XAI, analysis, and candidate selection**
   - `xai.py`, `xai_analysis.py`, `xai_cache.py`, `detection_xai.py`, and `data_quality.py` indicate a pipeline for explanation generation and reuse.
   - XAI outputs are not just visual artifacts; they appear to influence augmentation choice, candidate pruning, and reporting.
   - The cache layer suggests explanations can be expensive and are reused across iterations or dashboard views.

8. **Metrics, eventing, and reporting**
   - `metrics` are collected per task and per class, with dedicated modules like `detection_metrics.py`, `taskMetrics.py`, and several dashboard components for confusion, deltas, accuracy gain, and training-time breakdown.
   - `events.py` likely provides the structured event stream used to track pipeline progress and feed UI/report generation.
   - `reporting.py` plus the README’s `report.json` flow indicate a structured artifact model: the training run emits machine-readable results that are later summarized or visualized.

9. **Dashboard backend and static delivery**
   - `src/bnnr/dashboard/backend.py`, `exporter.py`, and `serve.py` implement the Python-side dashboard service.
   - The dashboard backend serves run artifacts and exposes them to the frontend; the exporter can package a run into a standalone dashboard directory.
   - The UI is not a generic monitoring tool; it is a read-only visualization layer over run artifacts, explanations, and metrics.

10. **Dashboard frontend architecture**
   - `dashboard_web` is a TypeScript/React app built with Vite.
   - Components are purpose-built around model-analysis views: branch graphs, candidate radar, confusion matrix/chord, per-class metrics, loss landscape, augmentation preview/impact/stack, XAI trend/quality, and node detail panels.
   - The frontend consumes a run state model (`useRunState`, `types.ts`) and task-specific metric helpers, so it is tightly coupled to the report/run schema produced by Python.

11. **Packaging and deployment path**
   - The default install path is pure Python; the dashboard is optional via extra dependencies.
   - For development, the dashboard must be built before editable install, which shows that the Python package embeds the web build artifact rather than compiling it at runtime.
   - The bundled frontend plus FastAPI/Uvicorn backend means the dashboard can run locally from a single Python process.

12. **Examples and supported workflows**
   - `examples/` provides runnable demos and notebooks for classification, detection, and multilabel tasks, plus YAML configs for reproducible scenarios.
   - These examples are part of the architecture because they encode the supported integration pattern: config-driven runs with task-specific adapters and pipelines.

13. **Testing and quality boundaries**
   - The test suite covers contracts, config, core pipeline behavior, dashboard backend/export/serve, detection, XAI, pause/resume, metrics, and regression scenarios.
   - This breadth suggests the project treats the pipeline, artifacts, and dashboard schema as stable interfaces that need end-to-end validation.

14. **Overall data flow**
   - User config and CLI input start a training run.
   - The pipeline builds adapters, datasets, augmentations, and metrics for the selected task.
   - Training emits structured events, checkpoints, XAI results, and report artifacts.
   - Those artifacts power both static reports and the live dashboard, which visualizes run state and supports export/serve modes.

Main entry points: [`src/bnnr/core.py`](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/core.py) (Core), [`src/bnnr/cli.py`](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/cli.py) (CLI), [`src/bnnr/pipelines.py`](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/pipelines.py) (Pipelines), [`src/bnnr/dashboard/backend.py`](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/backend.py) (Dashboard backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_python["Python runtime"]
  node_n_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_n_main["Module entry<br/>bootstrap<br/>[__main__.py]"]
  node_n_config["Config<br/>contract<br/>[config.py]"]
  node_n_quickrun["Quick run<br/>orchestration<br/>[quick_run.py]"]
  node_n_pipelines["Pipelines<br/>orchestration<br/>[pipelines.py]"]
  node_n_core["Core<br/>engine<br/>[core.py]"]
  node_n_craft["Craft<br/>artifact builder<br/>[craft.py]"]
  node_n_adapter["Adapters<br/>integration layer<br/>[adapter.py]"]
  node_n_det_adapter["Detection adapter<br/>task adapter"]
  node_n_aug["Augmentations<br/>subsystem<br/>[augmentations.py]"]
  node_n_aug_impl["Augment backends<br/>backend adapters"]
  node_n_xai["XAI<br/>analysis subsystem<br/>[xai.py]"]
  node_n_events["Events<br/>telemetry<br/>[events.py]"]
  node_n_reporting["Reporting<br/>artifact schema<br/>[reporting.py]"]
  node_n_dashboard_backend["Dashboard backend<br/>service backend<br/>[backend.py]"]
  node_n_dashboard_export["Dashboard export<br/>packaging<br/>[exporter.py]"]
  node_n_dashboard_serve["Dashboard serve<br/>[serve.py]"]
  node_n_bundle["Bundled UI<br/>static asset bundle<br/>[index.html]"]
end

subgraph group_grp_web["Dashboard web"]
  node_n_web_app["Web app<br/>react app<br/>[App.tsx]"]
  node_n_web_state["Run state<br/>ui state<br/>[types.ts]"]
  node_n_web_components["UI views<br/>components<br/>[BranchGraph.tsx]"]
end

subgraph group_grp_examples["Examples"]
  node_n_examples["Examples<br/>usage patterns<br/>[README.md]"]
end

node_n_main -->|"boots"| node_n_cli
node_n_cli -->|"loads"| node_n_config
node_n_cli -->|"dispatches"| node_n_quickrun
node_n_cli -->|"starts"| node_n_pipelines
node_n_pipelines -->|"executes"| node_n_core
node_n_pipelines -->|"builds"| node_n_craft
node_n_core -->|"uses"| node_n_adapter
node_n_core -->|"specializes"| node_n_det_adapter
node_n_core -->|"applies"| node_n_aug
node_n_aug -->|"backs"| node_n_aug_impl
node_n_core -->|"analyzes"| node_n_xai
node_n_xai -->|"feeds"| node_n_aug
node_n_core -->|"emits"| node_n_events
node_n_core -->|"writes"| node_n_reporting
node_n_reporting -->|"powers"| node_n_dashboard_backend
node_n_dashboard_backend -->|"packages"| node_n_dashboard_export
node_n_dashboard_backend -->|"serves"| node_n_dashboard_serve
node_n_dashboard_serve -->|"loads"| node_n_bundle
node_n_web_app -->|"reads"| node_n_web_state
node_n_web_app -->|"composes"| node_n_web_components
node_n_bundle -.->|"built from"| node_n_web_app
node_n_examples -->|"demonstrates"| node_n_config
node_n_examples -->|"shows"| node_n_adapter

click node_n_cli "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/cli.py"
click node_n_main "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/__main__.py"
click node_n_config "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/config.py"
click node_n_quickrun "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/quick_run.py"
click node_n_pipelines "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/pipelines.py"
click node_n_core "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/core.py"
click node_n_craft "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/craft.py"
click node_n_adapter "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/adapter.py"
click node_n_det_adapter "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/detection_adapter.py"
click node_n_aug "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/augmentations.py"
click node_n_aug_impl "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/albumentations_aug.py"
click node_n_xai "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/xai.py"
click node_n_events "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/events.py"
click node_n_reporting "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/reporting.py"
click node_n_dashboard_backend "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/backend.py"
click node_n_dashboard_export "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/exporter.py"
click node_n_dashboard_serve "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/serve.py"
click node_n_web_app "https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/App.tsx"
click node_n_web_state "https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/types.ts"
click node_n_web_components "https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/components/BranchGraph.tsx"
click node_n_bundle "https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/frontend/dist/index.html"
click node_n_examples "https://github.com/bnnr-team/bnnr/blob/main/examples/README.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_n_cli,node_n_main,node_n_config,node_n_quickrun,node_n_pipelines,node_n_core,node_n_craft,node_n_adapter,node_n_det_adapter,node_n_aug,node_n_aug_impl,node_n_xai,node_n_events,node_n_reporting,node_n_dashboard_backend,node_n_dashboard_export,node_n_dashboard_serve,node_n_bundle toneBlue
class node_n_web_app,node_n_web_state,node_n_web_components toneAmber
class node_n_examples toneMint
```

## Components

### Python runtime

Core package, orchestration, analysis, and packaged dashboard backend

- [CLI](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/cli.py): entrypoint · Main command surface for training, reporting, listing, and dashboard commands · `src/bnnr/cli.py`
- [Module entry](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/__main__.py): bootstrap · python -m bnnr entry hook · `src/bnnr/__main__.py`
- [Config](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/config.py): contract · Central experiment and runtime settings contract · `src/bnnr/config.py`
- [Quick run](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/quick_run.py): orchestration · High-level shortcut for launching standard workflows · `src/bnnr/quick_run.py`
- [Pipelines](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/pipelines.py): orchestration · Task and iteration flow coordination across training and analysis · `src/bnnr/pipelines.py`
- [Core](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/core.py): engine · Primary training and evaluation execution logic · `src/bnnr/core.py`
- [Craft](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/craft.py): artifact builder · Artifact generation and experiment assembly utilities · `src/bnnr/craft.py`
- [Adapters](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/adapter.py): integration layer · Base adapter boundary for custom models and dataloaders · `src/bnnr/adapter.py`
- [Detection adapter](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/detection_adapter.py): task adapter · Detection-specific model and data integration · `src/bnnr/detection_adapter.py`
- [Augmentations](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/augmentations.py): subsystem · Augmentation selection and application for feedback loops · `src/bnnr/augmentations.py`
- [Augment backends](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/albumentations_aug.py): backend adapters · Albumentations, Kornia, and detection augmentation implementations · `src/bnnr/albumentations_aug.py`
- [XAI](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/xai.py): analysis subsystem · Explanation generation, analysis, caching, and quality scoring · `src/bnnr/xai.py`
- [Events](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/events.py): telemetry · Structured run events used for progress and artifact tracking · `src/bnnr/events.py`
- [Reporting](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/reporting.py): artifact schema · Run summaries and machine-readable report output · `src/bnnr/reporting.py`
- [Dashboard backend](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/backend.py): service backend · Python-side API for serving run artifacts to the UI · `src/bnnr/dashboard/backend.py`
- [Dashboard export](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/exporter.py): packaging · Packages a run into a standalone dashboard directory · `src/bnnr/dashboard/exporter.py`
- [Dashboard serve](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/serve.py): service · Local dashboard serving process · `src/bnnr/dashboard/serve.py`
- [Bundled UI](https://github.com/bnnr-team/bnnr/blob/main/src/bnnr/dashboard/frontend/dist/index.html): static asset bundle · Built frontend shipped inside the Python package · `src/bnnr/dashboard/frontend/dist/index.html`

### Dashboard web

Source React app and bundled static frontend

- [Web app](https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/App.tsx): react app · Vite/React dashboard source application · `dashboard_web/src/App.tsx`
- [Run state](https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/types.ts): ui state · Frontend run-state model and task metric helpers · `dashboard_web/src/types.ts`
- [UI views](https://github.com/bnnr-team/bnnr/blob/main/dashboard_web/src/components/BranchGraph.tsx): components · Analysis and reporting views for metrics, XAI, augmentation, and decision flow · `dashboard_web/src/components/BranchGraph.tsx`

### Examples

Runnable task demos and config-driven usage patterns

- [Examples](https://github.com/bnnr-team/bnnr/blob/main/examples/README.md): usage patterns · Task demos and reproducible configuration examples · `examples/README.md`

## Connections

- Module entry → CLI: boots · Module entry hands control to the CLI
- CLI → Config: loads · CLI resolves experiment settings from the central config
- CLI → Quick run: dispatches · Common one-shot workflows are routed through quick run helpers
- CLI → Pipelines: starts · CLI invokes pipeline orchestration for full runs
- Pipelines → Core: executes · Pipelines coordinate training and evaluation in the core engine
- Pipelines → Craft: builds · Pipelines assemble artifacts and run outputs
- Core → Adapters: uses · Core execution depends on the adapter boundary for model and data integration
- Core → Detection adapter: specializes · Detection tasks use a specialized adapter path
- Core → Augmentations: applies · Training uses augmentation strategy selection and execution
- Augmentations → Augment backends: backs · Augmentation logic delegates to concrete backends
- Core → XAI: analyzes · Core run produces explanations and analysis inputs
- XAI → Augmentations: feeds · XAI and quality analysis influence augmentation choice in the feedback loop
- Core → Events: emits · Training and evaluation emit structured lifecycle events
- Core → Reporting: writes · Core run outputs report artifacts and summaries
- Reporting → Dashboard backend: powers · Reports and artifacts are consumed by the dashboard backend
- Dashboard backend → Dashboard export: packages · Backend data can be exported as a standalone dashboard
- Dashboard backend → Dashboard serve: serves · Backend supports live local serving
- Dashboard serve → Bundled UI: loads · Serving uses the bundled static frontend shipped in the package
- Web app → Run state: reads · UI renders from the run-state and metric model
- Web app → UI views: composes · App is assembled from analysis and reporting views
- Bundled UI → Web app: built from · Packaged assets are built from the dashboard source application
- Examples → Config: demonstrates · Examples encode reproducible config-driven usage
- Examples → Adapters: shows · Examples illustrate custom adapter integration
