# neuecc/unirx architecture

> Architecture diagram of the GitHub repository neuecc/unirx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neuecc/unirx
- Repository: https://github.com/neuecc/unirx

## Overview

##### Main components
- Core Reactive Library: This includes the base abstractions of reactive programming (IObservable, IObserver, Disposable types, various LINQ-style operators, Subjects, and ReactiveProperties). This is found under Assets/Plugins/UniRx/Scripts and also in the Dlls/UniRx projects.
- Unity Adaptor Layer: Contains platform-specific adaptations (e.g., MonoBehaviour triggers within Assets/Plugins/UniRx/Scripts/UnityEngineBridge and related trigger classes under Assets/Plugins/UniRx/Examples that show the bridge between Unity events and observables).
- Scheduling and Threading: It implements specialized schedulers like Scheduler.MainThread, ThreadPoolScheduler, and MicroCoroutine mechanisms for efficient frame-based asynchronous execution. These components (located within the Schedulers subdirectories and as parts of the UnityEngineBridge) are critical in mapping Unity’s game loop characteristics.
- Testing and Analysis: The project has a robust test suite (see Tests/UniRx.Console, Tests/UniRx.Tests) and a Visual Studio Analyzer under the Analyzer directory. This part of the system verifies correct reactive behavior and helps identify common mistakes (e.g., forgotten subscriptions).
- Build and Distribution Infrastructure: NuGet packaging files (inside the .nuget directory), continuous integration configuration (in the .circleci folder), and Visual Studio solution/project files (such as UniRx.sln, Assembly-CSharp, and .csproj files) represent the build and deployment pipeline.
- Example and Documentation: There are extensive examples (Assets/Plugins/UniRx/Examples) and sample scenes that illustrate “how to use” the library in practical Unity projects, along with the README documentation that guides usage.

##### Relationships and interactions
- The Core Library provides the fundamental reactive types and operators. These are consumed by both Unity Adaptor components and the high-level Reactive UI components.
- The Unity Adapters/Triggers layer converts Unity events (Update, OnCollision, UI interactions, etc.) into observable streams. For example, ObservableTrigger classes (and the extension methods on GameObject/Component) tap directly into Unity’s event lifecycle and forward these events as Rx notifications.
- The Testing/Analyzer components are decoupled from the main library but are integrated during CI build (.circleci config) and help enforce correct reactive patterns.
- Tools like MessageBroker and ReactiveCommand provide glue between the UI and the domain logic, emphasizing a Model-View-(Reactive)Presenter pattern (illustrated in the README) where view events are funneled as observables to update models and trigger UI changes.

##### Architectural Patterns and Design Principles
- Modular Architecture: The separation of core functionality (reactive extensions and operators) from Unity-specific adapters fosters reuse and substitution.
- Reactive Programming Fundamentals: All aspects of the library, from asynchronous operations to UI events, follow a reactive paradigm—using streams, subscriptions, and disposables to manage communication.
- Asynchronous and Multithreaded Handling: The use of schedulers, micro-coroutines, and main thread dispatchers underscores how asynchronous work is coordinated with Unity’s single-threaded nature.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Distribution
    subgraph "Build & Distribution"
        NU_GET[".nuget"]:::build
        CIRCLECI[".circleci"]:::build
        SOLUTION["UniRx.sln"]:::build
    end

    %% Core Reactive Library
    subgraph "Core Reactive Library"
        CORE["Core Reactive Library\n(Assets/Plugins/UniRx/Scripts)"]:::core
    end

    %% Unity Adapter Layer
    subgraph "Unity Adapter Layer"
        ADAPTER["Unity Adapter Layer\n(Assets/Plugins/UniRx/Scripts/UnityEngineBridge)"]:::adapter
    end

    %% Scheduling & Threading
    subgraph "Scheduling & Threading"
        SCHED["Schedulers\n(Assets/Plugins/UniRx/Scripts/Schedulers)"]:::scheduler
        MAIN_TS["MainThreadScheduler\n(Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs)"]:::scheduler
    end

    %% Testing & Analysis
    subgraph "Testing & Analysis"
        TESTS1["UniRx.Tests"]:::testing
        TESTS2["UniRx.Console"]:::testing
        ANALYZER["UniRxAnalyzer"]:::testing
    end

    %% Examples & Documentation
    subgraph "Examples & Documentation"
        EXAMPLES_DOC["Examples\n(Assets/Plugins/UniRx/Examples)"]:::example
        READ_ME["ReadMe.txt\n(Assets/Plugins/UniRx/ReadMe.txt)"]:::example
    end

    %% Build Dependencies
    SOLUTION -->|"builds"| CORE
    SOLUTION -->|"builds"| ADAPTER
    SOLUTION -->|"builds"| SCHED

    CIRCLECI -->|"CI_runs"| TESTS1
    CIRCLECI -->|"CI_runs"| TESTS2
    CIRCLECI -->|"CI_runs"| ANALYZER

    %% Core and Adapter Interactions
    ADAPTER -->|"uses"| CORE
    CORE -->|"operates-with"| SCHED
    ADAPTER -->|"schedules"| SCHED
    SCHED -->|"includes"| MAIN_TS

    %% Testing Relationships
    CORE -->|"verified_by"| TESTS1
    CORE -->|"verified_by"| TESTS2
    CORE -->|"analyzed_by"| ANALYZER
    ADAPTER -->|"verified_by"| TESTS1
    ADAPTER -->|"verified_by"| TESTS2
    ADAPTER -->|"analyzed_by"| ANALYZER
    SCHED -->|"verified_by"| TESTS1
    SCHED -->|"verified_by"| TESTS2
    SCHED -->|"analyzed_by"| ANALYZER

    %% Examples Demonstrations
    EXAMPLES_DOC -->|"demonstrates"| CORE
    EXAMPLES_DOC -->|"demonstrates"| ADAPTER
    EXAMPLES_DOC -->|"demonstrates"| SCHED

    %% Click Events
    click CORE "https://github.com/neuecc/unirx/tree/master/Assets/Plugins/UniRx/Scripts"
    click ADAPTER "https://github.com/neuecc/unirx/tree/master/Assets/Plugins/UniRx/Scripts/UnityEngineBridge"
    click SCHED "https://github.com/neuecc/unirx/tree/master/Assets/Plugins/UniRx/Scripts/Schedulers"
    click MAIN_TS "https://github.com/neuecc/unirx/blob/master/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs"
    click TESTS1 "https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Tests"
    click TESTS2 "https://github.com/neuecc/unirx/blob/master/Tests/UniRx.Console"
    click ANALYZER "https://github.com/neuecc/unirx/tree/master/Analyzer/UniRxAnalyzer"
    click NU_GET "https://github.com/neuecc/unirx/blob/master/.nuget"
    click CIRCLECI "https://github.com/neuecc/unirx/blob/master/.circleci"
    click SOLUTION "https://github.com/neuecc/unirx/blob/master/UniRx.sln"
    click EXAMPLES_DOC "https://github.com/neuecc/unirx/tree/master/Assets/Plugins/UniRx/Examples"
    click READ_ME "https://github.com/neuecc/unirx/blob/master/Assets/Plugins/UniRx/ReadMe.txt"

    %% Styles
    classDef core fill:#ffeead,stroke:#333,stroke-width:2px;
    classDef adapter fill:#ccebc5,stroke:#333,stroke-width:2px;
    classDef scheduler fill:#decbe4,stroke:#333,stroke-width:2px;
    classDef testing fill:#fddaec,stroke:#333,stroke-width:2px;
    classDef build fill:#b3cde3,stroke:#333,stroke-width:2px;
    classDef example fill:#fed9a6,stroke:#333,stroke-width:2px;
```
