# bruskatech/psyforge architecture

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

- Interactive diagram: https://gitdiagram.com/bruskatech/psyforge
- Repository: https://github.com/bruskatech/psyforge

## Overview

##### Main Components

a. Core Framework Layer:
- MainManager (central orchestrator)
- InputManager (input handling)
- ErrorNotifier (error management)
- Configuration System (Config, FileManager)
- Threading System (EventLoop, SingleThreadTaskScheduler)

b. Experiment Layer:
- ExperimentBase (base experiment functionality)
- ExperimentSession (session management)
- Trial Management
- Data Collection/Logging

c. External Interfaces:
- NetworkInterface
- ElememInterface (for closed-loop systems)
- SyncBox/PhotoDiodeSyncBox (timing synchronization)
- HostPC Communication

d. UI/Presentation Components:
- TextDisplayer
- VideoPlayer
- SoundRecorder
- GUI Management System

##### Relationship Flow

**[External Hardware] <---> [Network/Device Interfaces] <---> [Core Framework Layer]**

- v
**[UI Components] <---> [Experiment Layer] <---> [Data Management]**
- ^

**[Configuration] ----------->|**

##### Important Details

- Thread boundaries and communication channels
- Real-time processing paths (marked with different line styles)
- Configuration flow
- Data collection points
- Error handling paths
- Platform-specific variations

##### Specific Implementation Notes

- How the EventLoop handles high-frequency inputs (30-60Hz+)
- Where Unity's main thread integrates with the system
- Cross-platform compatibility points
- Integration points with Unity's rendering pipeline

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Hardware Layer"]
        HW[Hardware Devices]
    end

    subgraph Interfaces["Interface Layer"]
        NI["Network Interface"]:::interface
        EI["Elemem Interface"]:::interface
        SB["SyncBox"]:::interface
        PD["PhotoDiode SyncBox"]:::interface
        HC["HostPC Communication"]:::interface
    end

    subgraph Core["Core Framework Layer"]
        MM["Main Manager"]:::core
        IM["Input Manager"]:::core
        EN["Error Notifier"]:::core
        CS["Configuration System"]:::core
        TS["Threading System"]:::core
    end

    subgraph Experiment["Experiment Layer"]
        EB["Experiment Base"]:::experiment
        ES["Experiment Session"]:::experiment
        TM["Trial Management"]:::experiment
    end

    subgraph UI["UI/Presentation Layer"]
        TD["Text Displayer"]:::ui
        VP["Video Player"]:::ui
        SR["Sound Recorder"]:::ui
        GM["GUI Management"]:::ui
    end

    subgraph Data["Data Management Layer"]
        DC["Data Collection"]:::data
        ER["Event Reporter"]:::data
        IR["Input Reporter"]:::data
    end

    %% Connections
    HW <--> NI & EI & SB & PD & HC
    NI & EI & SB & PD & HC --> MM
    MM --> IM & EN & CS & TS
    IM & CS --> EB
    EB --> ES
    ES --> TM
    EB --> TD & VP & SR & GM
    EB --> DC
    DC --> ER & IR

    %% Click Events
    click MM "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Core/MainManager.cs"
    click IM "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Core/InputManager.cs"
    click EN "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Core/ErrorNotifier.cs"
    click CS "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Configuration/Config.cs"
    click TS "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Threading/EventLoop.cs"
    click EB "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Experiment/ExperimentBase.cs"
    click ES "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Experiment/ExperimentSession.cs"
    click TM "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/Experiment/ExpHelpers.cs"
    click NI "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/ExternalDevices/NetworkInterface.cs"
    click EI "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/ExternalDevices/ElememInterface.cs"
    click SB "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/ExternalDevices/SyncBox.cs"
    click PD "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/ExternalDevices/PhotoDiodeSyncBox.cs"
    click HC "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/ExternalDevices/HostPC.cs"
    click TD "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Prefabs/TextDisplayer/TextDisplayer.cs"
    click VP "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Prefabs/VideoPlayer/VideoControl.cs"
    click SR "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Prefabs/SoundRecorder/SoundRecorder.cs"
    click GM "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/GUI/TextOverlay.cs"
    click DC "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/DataManagement/DataPoint.cs"
    click ER "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/DataManagement/EventReporter.cs"
    click IR "https://github.com/BruskaTech/PsyForge/blob/main/Runtime/Scripts/DataManagement/InputReporter.cs"

    %% Styling
    classDef core fill:#3498db
    classDef interface fill:#2ecc71
    classDef experiment fill:#f1c40f
    classDef ui fill:#e74c3c
    classDef data fill:#9b59b6

    %% Legend
    subgraph Legend
        L1[Core Framework]:::core
        L2[Interfaces]:::interface
        L3[Experiment]:::experiment
        L4[UI/Presentation]:::ui
        L5[Data Management]:::data
    end
```
