# bonsai-rx/bonsai architecture

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

- Interactive diagram: https://gitdiagram.com/bonsai-rx/bonsai
- Repository: https://github.com/bonsai-rx/bonsai

## Overview

##### Main Components
The system architecture should be organized into the following major components:

a. Core Framework
- Bonsai.Core: The reactive programming engine and workflow compiler
- Bonsai.Design: UI components and design-time infrastructure
- Bonsai.Editor: The IDE and workflow editor implementation
- Bonsai.Configuration: System configuration and bootstrapping

b. Standard Library
- Bonsai.System: System I/O and resource management
- Bonsai.Vision: Computer vision processing
- Bonsai.Shaders: Graphics and GPU computation
- Bonsai.Audio: Audio processing
- Bonsai.Osc: Network communication

c. Package Management
- Bonsai.NuGet: Package management infrastructure
- Bonsai.Templates: Project templates

##### Architectural Patterns

a. Reactive Architecture
- Observable data streams between components
- Transformation and combination operators
- Async processing pipelines

b. Plugin Architecture
- Extension points for custom modules
- Package management system
- Type visualization framework

##### Component Relationships

a. Core Dependencies
**Editor -> Design -> Core**
**Configuration -> Core**
**Standard Library -> Core**

b. Runtime Flow
**Editor -> Configuration -> Package Management**
**Workflow Execution -> Standard Library**
**Visualizers -> Design System**

##### Implementation Details

Technical elements:

a. Framework Components
- Expression builders and combinators
- Workflow compiler
- Type system and reflection
- Resource management

b. Runtime Services
- Package management
- Configuration
- Visualization
- I/O handling

**[Editor/IDE Layer]**
- ↓
**[Design/Configuration Layer]**
- ↓
**[Core Framework Layer]**
- ↓
**[Standard Library Layer]**

##### Additional Elements

Include:
- Version information
- External dependencies (Rx.NET)
- Extension points
- Package management flow

This architecture emphasizes Bonsai's nature as a visual reactive programming environment while capturing its modular, extensible design and rich standard library components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph IDE
        Editor["Editor/IDE"]
        GraphView["Graph View"]
        TypeVis["Type Visualizers"]
        PackageUI["Package Manager UI"]
    end

    subgraph Design
        DesignInfra["Design Infrastructure"]
        UIComponents["UI Components"]
    end

    subgraph Core
        ReactiveEngine["Reactive Engine"]
        WorkflowCompiler["Workflow Compiler"]
        ExprBuilder["Expression Builder"]
        ReactiveOps["Reactive Operators"]
    end

    subgraph Config
        SysConfig["System Configuration"]
        PackageConfig["Package Configuration"]
        AssemblyMgmt["Assembly Management"]
        ExtensionMgmt["Extension Management"]
    end

    subgraph "Standard Library"
        SystemIO["System I/O"]
        Vision["Computer Vision"]
        Shaders["Graphics & GPU"]
        Audio["Audio Processing"]
        Network["Network (OSC)"]
    end

    subgraph "Package Management"
        NuGetInfra["NuGet Infrastructure"]
        Templates["Project Templates"]
    end

    %% Relationships
    Editor --> DesignInfra
    Editor --> SysConfig
    GraphView --> WorkflowCompiler
    TypeVis --> UIComponents
    PackageUI --> NuGetInfra
    
    DesignInfra --> ReactiveEngine
    UIComponents --> WorkflowCompiler
    
    ReactiveEngine --> ExprBuilder
    WorkflowCompiler --> ReactiveOps
    
    SysConfig --> PackageConfig
    PackageConfig --> AssemblyMgmt
    AssemblyMgmt --> ExtensionMgmt
    
    ReactiveEngine --> SystemIO
    ReactiveEngine --> Vision
    ReactiveEngine --> Shaders
    ReactiveEngine --> Audio
    ReactiveEngine --> Network
    
    NuGetInfra --> Templates
    NuGetInfra --> PackageConfig

    %% Styling
    classDef ide fill:#f9f,stroke:#333
    classDef design fill:#fcf,stroke:#333
    classDef core fill:#9cf,stroke:#333
    classDef config fill:#ff9,stroke:#333
    classDef stdlib fill:#9f9,stroke:#333
    classDef package fill:#f90,stroke:#333

    class Editor,GraphView,TypeVis,PackageUI ide
    class DesignInfra,UIComponents design
    class ReactiveEngine,WorkflowCompiler,ExprBuilder,ReactiveOps core
    class SysConfig,PackageConfig,AssemblyMgmt,ExtensionMgmt config
    class SystemIO,Vision,Shaders,Audio,Network stdlib
    class NuGetInfra,Templates package

    %% Click events
    click Editor "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Editor/"
    click GraphView "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Editor/GraphView/"
    click TypeVis "https://github.com/bonsai-rx/bonsai/blob/main/Bonsai.Design/TypeVisualizerDialog.cs"
    click PackageUI "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.NuGet.Design/"
    click DesignInfra "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Design/"
    click ReactiveEngine "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Core/"
    click ExprBuilder "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Core/Expressions/"
    click ReactiveOps "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Core/Reactive/"
    click SysConfig "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Configuration/"
    click PackageConfig "https://github.com/bonsai-rx/bonsai/blob/main/Bonsai.Configuration/PackageConfiguration.cs"
    click AssemblyMgmt "https://github.com/bonsai-rx/bonsai/blob/main/Bonsai.Configuration/AssemblyReference.cs"
    click ExtensionMgmt "https://github.com/bonsai-rx/bonsai/blob/main/Bonsai.Configuration/ExtensionFolderCollection.cs"
    click SystemIO "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.System/"
    click Vision "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Vision/"
    click Shaders "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Shaders/"
    click Audio "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Audio/"
    click Network "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Osc/"
    click NuGetInfra "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.NuGet/"
    click Templates "https://github.com/bonsai-rx/bonsai/tree/main/Bonsai.Templates/"
```
