# uwrealitylabs/universal-text-unity architecture

> Architecture diagram of the GitHub repository uwrealitylabs/universal-text-unity, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uwrealitylabs/universal-text-unity
- Repository: https://github.com/uwrealitylabs/universal-text-unity

## Overview

##### Primary Components
- Unity Engine Core – This is the runtime platform where the application executes using Unity 2022.3.24f1.
- XR Integration Layer – Components include Oculus configuration (OculusLoader, OculusProjectConfig.asset) and the XR Interaction Toolkit (samples, XR origin prefabs and interactors). This layer handles VR/AR input, controller events, simulation settings, and overall XR runtime support.
- Universal Text Functionality – The “Universal Text” modules (e.g., UniversalTextScanner in Scripts/Core/UniversalTextScanner and UniversalTextTag) represent the core functional aspects of the package. They handle text capture, tagging, scanning, and maybe semantic interpretation.
- LLM/Conversation Module – Found in the Scripts/LLM directory (e.g., ChatGPTHandler.cs). This module likely interacts with an external language model or provides demo interactions based on text input.
- UI and Scene Management – Several prefabs (e.g., Sent/Received Message prefabs, UI Sample prefabs in Assets/Samples), Scenes, and TextMesh Pro assets, collectively manage visual feedback and interactions in the UI, both in 3D and in overlays.
- External Assets/Packages – Third-party dependencies like TextMesh Pro, NuGet packages (for dependency management), and additional sample scene assets that support XR interaction and improve demonstration quality.

##### Relationships and Interactions
- The Unity Engine acts as the foundation that interconnects all components.
- The XR Integration layer provides the input events and hardware device abstraction. These input events feed directly into the interactive prefabs and controllers, which then pass events to the Universal Text components.
- The Universal Text Scanner and Tag modules interact with the LLM modules to provide additional functionality (such as natural language processing and dynamic text interpretation). Visual cues and messages are rendered via Unity Scenes and UI components.
- The UI and Scene Management components use assets (like TextMesh Pro and prefabs) to render textual output and interactive elements. They both subscribe to events from the underlying text scanning and XR input systems.
- External libraries (NuGet packages, XR-specific packages, etc.) support these interactions by providing underlying frameworks (such as XR device simulation or text formatting).

##### Architectural Patterns & Design Principles
- Separation of Concerns – Input handling, text scanning/tagging, language model processing, and visual presentation are handled by separate modules, promoting a clean architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% XR Integration Layer Subgraph
    subgraph "XR Integration Layer"
        XR1["Oculus Config"]:::xr
        XR2["XR Loaders & Settings"]:::xr
        XR3["XR Interaction Toolkit Samples"]:::xr
    end

    %% Universal Text Functionality Subgraph
    subgraph "Universal Text Functionality"
        UT1["UniversalTextScanner"]:::ut
        UT2["UniversalTextTag"]:::ut
    end

    %% UI and Scene Management Subgraph
    subgraph "UI and Scene Management"
        UI1["UI Prefabs"]:::ui
        UI2["Scenes"]:::ui
        UI3["UI Sample"]:::ui
    end

    %% External Dependencies Subgraph
    subgraph "External Dependencies"
        EX1["NuGet Package Resources"]:::external
        EX2["TextMesh Pro Assets"]:::external
        EX3["Package Definitions"]:::external
    end

    %% LLM Module Node
    LLM1["LLM Module (ChatGPTHandler)"]:::llm

    %% Unity Engine Core Node
    engineCore["Unity Engine Core (2022.3.24f1)"]:::engine

    %% Interactions between components
    %% XR Integration Layer sending input events to Universal Text and UI
    XR1 -->|"input"| UT1
    XR1 -->|"input"| UI1

    %% Universal Text modules interacting with LLM module
    UT1 -->|"text"| LLM1
    UT2 -->|"text"| LLM1

    %% LLM module sending responses to UI
    LLM1 -->|"response"| UI1

    %% All modules feeding into the Unity Engine Core
    XR1 -->|"feeds"| engineCore
    XR2 -->|"feeds"| engineCore
    XR3 -->|"feeds"| engineCore
    UT1 -->|"feeds"| engineCore
    UT2 -->|"feeds"| engineCore
    LLM1 -->|"feeds"| engineCore
    UI1 -->|"feeds"| engineCore
    UI2 -->|"feeds"| engineCore
    UI3 -->|"feeds"| engineCore
    EX1 -->|"supports"| engineCore
    EX2 -->|"supports"| engineCore
    EX3 -->|"supports"| engineCore

    %% Click Events for XR Integration Layer
    click XR1 "https://github.com/uwrealitylabs/universal-text-unity/blob/main/Assets/Oculus/OculusProjectConfig.asset"
    click XR2 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/XR"
    click XR3 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/Samples/XR Interaction Toolkit"

    %% Click Events for Universal Text Functionality
    click UT1 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/Scripts/Core/UniversalTextScanner"
    click UT2 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/Scripts/Core/UniversalTextTag"

    %% Click Event for LLM Module
    click LLM1 "https://github.com/uwrealitylabs/universal-text-unity/blob/main/Assets/Scripts/LLM/ChatGPTHandler.cs"

    %% Click Events for UI and Scene Management
    click UI1 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/Prefabs"
    click UI2 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/Scenes"
    click UI3 "https://github.com/uwrealitylabs/universal-text-unity/blob/main/Assets/Samples/XR Interaction Toolkit/2.5.4/Starter Assets/DemoSceneAssets/Prefabs/UI Sample.prefab"

    %% Click Events for External Dependencies
    click EX1 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/NuGet"
    click EX2 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Assets/TextMesh Pro"
    click EX3 "https://github.com/uwrealitylabs/universal-text-unity/tree/main/Packages"

    %% Styles
    classDef engine fill:#dcedc8,stroke:#558b2f,stroke-width:2px;
    classDef xr fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef ut fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef llm fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef ui fill:#f8bbd0,stroke:#ad1457,stroke-width:2px;
    classDef external fill:#d1c4e9,stroke:#673ab7,stroke-width:2px;
```
