# emre-emiroglu/signalbus architecture

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

- Interactive diagram: https://gitdiagram.com/emre-emiroglu/signalbus
- Repository: https://github.com/emre-emiroglu/signalbus

## Overview

1. **Project type and scope**
   - This is a **Unity UPM package** named **SignalBus**.
   - It provides a lightweight **publish/subscribe event bus** for decoupled communication between Unity components and plain C# classes.
   - The repository is small and focused: runtime source, tests, and package metadata.

2. **Top-level architecture**
   - The code is split into three main parts:
     - **Runtime/**: the actual package implementation
     - **Tests/EditMode/**: editor-side unit tests
     - **Tests/PlayMode/**: runtime behavior tests in Unity play mode
   - `package.json` and the `.asmdef` files define Unity package and assembly boundaries.

3. **Public API layer**
   - The main entry point for consumers is **`SignalBusUtilities`**.
   - It acts as a **static façade**, so client code can call `Declare`, `Subscribe`, `Unsubscribe`, and `Fire` without manually managing a bus instance.
   - This is the boundary most users interact with; it hides the underlying construction/lifecycle concerns.

4. **Core bus implementation**
   - **`SignalBus`** is the central runtime object that owns signal declarations and dispatch behavior.
   - It is responsible for:
     - tracking whether a signal type has been declared
     - registering subscribers
     - removing subscribers
     - firing signals to listeners
   - The README indicates it enforces declaration-before-use and throws on duplicate declarations.

5. **Subscription and dispatch mechanics**
   - **`SignalBinding`** is the internal delivery mechanism used by `SignalBus`.
   - It holds the receiver list for a given signal and manages:
     - adding/removing handlers
     - invoking handlers
     - checking whether any subscribers exist
   - The important architectural detail is that signal dispatch is not just a raw list of callbacks; it is a managed binding layer.

6. **Priority-based ordering**
   - Subscriptions support a **priority value**.
   - That priority affects the order in which callbacks are invoked when a signal is fired.
   - The README also notes that unsubscribe must use the same priority value used at subscribe time, which means priority is part of the identity of the subscription.

7. **Signal lifecycle and data flow**
   - The normal flow is:
     - client declares a signal type
     - client subscribes one or more callbacks
     - client fires a signal instance
     - `SignalBus` finds the corresponding binding
     - `SignalBinding` invokes subscribers in priority order
   - If a signal is fired with no subscribers, the package logs a warning rather than failing silently.

8. **Error and guard behavior**
   - The package appears to enforce a few important rules:
     - **multiple declarations** are rejected with an exception
     - **use before declaration** is rejected with an exception
     - **no subscribers on fire** generates a warning
   - These checks make the bus deterministic and help catch configuration mistakes early.

9. **Unity-specific packaging**
   - `Runtime/SignalBus.Runtime.asmdef` isolates the runtime code into its own assembly.
   - Separate test assemblies exist for edit mode and play mode.
   - This structure matters for architecture diagrams because it shows the package is designed to be imported into Unity projects as a reusable module, not as an application.

10. **Test coverage boundary**
   - The presence of both **EditMode** and **PlayMode** tests suggests the package validates both pure logic and Unity-runtime integration behavior.
   - This usually means:
     - EditMode tests cover core bus logic deterministically
     - PlayMode tests validate behavior in an actual Unity runtime context
   - The tests sit outside the runtime assembly, reinforcing a clean separation between implementation and verification.

11. **External integration surface**
   - The only meaningful external dependency implied by the repo structure is **Unity itself**.
   - The package is meant to be consumed by Unity projects via **Git URL / UPM**.
   - There are no signs of network services, databases, or backend infrastructure; the architecture is self-contained and in-process.

12. **What to show in an architecture diagram**
   - A useful diagram would have:
     - **Game / component code** calling into **SignalBusUtilities**
     - **SignalBusUtilities** delegating to a **SignalBus instance**
     - **SignalBus** managing a map of signal types to **SignalBinding**
     - **SignalBinding** holding ordered subscriber callbacks and invoking them on fire
     - **Tests** verifying both the core logic and Unity execution behavior
   - The key boundary is between the **consumer-facing static API** and the **internal subscription/dispatch machinery**.

Main entry points: [`Runtime/SignalBus.cs`](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.cs) (Signal bus), [`Runtime/SignalBusUtilities.cs`](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBusUtilities.cs) (Bus utils), [`Runtime/SignalBus.Runtime.asmdef`](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.Runtime.asmdef) (Runtime asmdef), [`Tests/PlayMode/SignalBusPlayModeTests.cs`](https://github.com/emre-emiroglu/signalbus/blob/main/Tests/PlayMode/SignalBusPlayModeTests.cs) (PlayMode tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_package["Package"]
  node_package_json["Package file<br/>upm manifest<br/>[package.json]"]
  node_runtime_asmdef["Runtime asmdef<br/>assembly"]
end

subgraph group_runtime["Runtime"]
  node_signalbus_utilities["Bus utils<br/>public facade"]
  node_signalbus["Signal bus<br/>core bus<br/>[SignalBus.cs]"]
  node_signalbinding["Bindings<br/>delivery layer<br/>[SignalBinding.cs]"]
end

subgraph group_tests["Tests"]
  node_editmode_asmdef["EditMode asmdef<br/>test assembly"]
  node_editmode_tests["EditMode tests<br/>unit tests"]
  node_playmode_asmdef["PlayMode asmdef<br/>test assembly"]
  node_playmode_tests["PlayMode tests<br/>runtime tests"]
end

node_game_code(("Game code<br/>consumer"))

node_game_code -->|"uses"| node_signalbus_utilities
node_signalbus_utilities -->|"delegates to"| node_signalbus
node_signalbus -->|"manages"| node_signalbinding
node_signalbus -.->|"exposes"| node_signalbus_utilities
node_signalbinding -.->|"reports to"| node_signalbus
node_signalbus -->|"fires to"| node_game_code
node_package_json -.->|"packages"| node_runtime_asmdef
node_runtime_asmdef -->|"includes"| node_signalbus_utilities
node_runtime_asmdef -->|"includes"| node_signalbus
node_runtime_asmdef -->|"includes"| node_signalbinding
node_editmode_asmdef -->|"includes"| node_editmode_tests
node_playmode_asmdef -->|"includes"| node_playmode_tests
node_editmode_tests -.->|"verifies"| node_signalbus
node_playmode_tests -.->|"verifies"| node_signalbus_utilities
node_playmode_tests -.->|"verifies"| node_signalbus

click node_package_json "https://github.com/emre-emiroglu/signalbus/blob/main/package.json"
click node_runtime_asmdef "https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.Runtime.asmdef"
click node_signalbus_utilities "https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBusUtilities.cs"
click node_signalbus "https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.cs"
click node_signalbinding "https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBinding.cs"
click node_editmode_asmdef "https://github.com/emre-emiroglu/signalbus/blob/main/Tests/EditMode/SignalBus.Tests.EditMode.asmdef"
click node_editmode_tests "https://github.com/emre-emiroglu/signalbus/blob/main/Tests/EditMode/SignalBusEditModeTests.cs"
click node_playmode_asmdef "https://github.com/emre-emiroglu/signalbus/blob/main/Tests/PlayMode/SignalBus.Tests.PlayMode.asmdef"
click node_playmode_tests "https://github.com/emre-emiroglu/signalbus/blob/main/Tests/PlayMode/SignalBusPlayModeTests.cs"

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_package_json,node_runtime_asmdef toneBlue
class node_signalbus_utilities,node_signalbus,node_signalbinding toneAmber
class node_editmode_asmdef,node_editmode_tests,node_playmode_asmdef,node_playmode_tests toneMint
class node_game_code toneNeutral
```

## Components

### Package

Unity package metadata and assembly boundaries

- [Package file](https://github.com/emre-emiroglu/signalbus/blob/main/package.json): upm manifest · Unity package metadata and dependency boundary · `package.json`
- [Runtime asmdef](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.Runtime.asmdef): assembly · Runtime assembly boundary for the package · `Runtime/SignalBus.Runtime.asmdef`

### Runtime

Public API and core bus implementation

- [Bus utils](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBusUtilities.cs): public facade · Static entry point for declaring, subscribing, unsubscribing, and firing signals · `Runtime/SignalBusUtilities.cs`
- [Signal bus](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBus.cs): core bus · Owns signal declarations and routes signal delivery · `Runtime/SignalBus.cs`
- [Bindings](https://github.com/emre-emiroglu/signalbus/blob/main/Runtime/SignalBinding.cs): delivery layer · Per-signal subscriber collection and ordered invocation · `Runtime/SignalBinding.cs`

### Tests

Edit mode and play mode verification

- [EditMode asmdef](https://github.com/emre-emiroglu/signalbus/blob/main/Tests/EditMode/SignalBus.Tests.EditMode.asmdef): test assembly · Assembly boundary for edit mode tests · `Tests/EditMode/SignalBus.Tests.EditMode.asmdef`
- [EditMode tests](https://github.com/emre-emiroglu/signalbus/blob/main/Tests/EditMode/SignalBusEditModeTests.cs): unit tests · Deterministic tests for core bus behavior · `Tests/EditMode/SignalBusEditModeTests.cs`
- [PlayMode asmdef](https://github.com/emre-emiroglu/signalbus/blob/main/Tests/PlayMode/SignalBus.Tests.PlayMode.asmdef): test assembly · Assembly boundary for play mode tests · `Tests/PlayMode/SignalBus.Tests.PlayMode.asmdef`
- [PlayMode tests](https://github.com/emre-emiroglu/signalbus/blob/main/Tests/PlayMode/SignalBusPlayModeTests.cs): runtime tests · Unity runtime behavior tests for the bus · `Tests/PlayMode/SignalBusPlayModeTests.cs`

### Other components

- **Game code**: consumer · Unity components and plain C# callers using the package

## Connections

- Game code → Bus utils: uses · Consumer code calls the static façade
- Bus utils → Signal bus: delegates to · Facade routes API calls to the bus instance
- Signal bus → Bindings: manages · Bus creates and looks up per-signal bindings
- Signal bus → Bus utils: exposes · Public API is the primary consumer-facing boundary
- Bindings → Signal bus: reports to · Binding is the internal dispatch mechanism used by the bus
- Signal bus → Game code: fires to · Signals are delivered back to subscribed callers
- Package file → Runtime asmdef: packages · Package metadata defines the runtime assembly module
- Runtime asmdef → Bus utils: includes · Runtime assembly contains the public façade
- Runtime asmdef → Signal bus: includes · Runtime assembly contains the core bus
- Runtime asmdef → Bindings: includes · Runtime assembly contains the binding layer
- EditMode asmdef → EditMode tests: includes · Edit mode assembly contains its tests
- PlayMode asmdef → PlayMode tests: includes · Play mode assembly contains its tests
- EditMode tests → Signal bus: verifies · Edit mode tests cover core bus logic
- PlayMode tests → Bus utils: verifies · Play mode tests validate runtime-facing behavior
- PlayMode tests → Signal bus: verifies · Play mode tests validate dispatch in Unity runtime
