# surasithaof/eventbus architecture

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

- Interactive diagram: https://gitdiagram.com/surasithaof/eventbus
- Repository: https://github.com/surasithaof/eventbus

## Overview

##### Project type and purpose
- This is an open-source Go library (“EventBus”) that implements an in-process asynchronous publish/subscribe event bus.
- Purpose: allow Go applications to publish events and have subscribers asynchronously receive them via Goroutines.

##### File structure
- Top-level files:
- eventbus.go – the core implementation of the EventBus
- eventbus_test.go, benchmark_test.go – unit tests and benchmarks
- go.mod, go.sum – module dependencies
- README.md, LICENSE.md – documentation and licensing
- No frontend/backend separation; this is a single-library codebase.

##### README
- Confirms it’s a minimal async event-bus for learning Goroutine patterns.
- Shows benchmarks for Subscribe and Publish performance.

##### Detail
- Call out thread‐safety: annotate where mutex locks are held in the core.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main flow
    Client["Client (Publisher/Subscriber)"]:::user
    EventBusCore["EventBus Core\n(subscription registry, mutex-lock, Publish/Subscribe APIs)"]:::internal
    InternalQueue["Internal Event Queue (channel)"]:::internal
    Broker["Broker Goroutine(s)\n(dequeue & lookup handlers)"]:::internal
    Subscriber["Subscriber Handlers\n(user callbacks)"]:::user

    Client -->|"Subscribe(eventType, handler)"| EventBusCore
    Client -->|"Publish(eventType, eventData)"| EventBusCore
    EventBusCore -->|"Enqueue(event)"| InternalQueue
    InternalQueue -->|"Dequeue(nextEvent)"| Broker
    Broker -->|"Dispatch(eventType)"| Subscriber

    %% Supporting files and docs
    subgraph "Library Files & Documentation"
        direction TB
        CoreFile["eventbus.go"]:::file
        UnitTests["eventbus_test.go"]:::file
        BenchTests["benchmark_test.go"]:::file
        ModuleFile1["go.mod"]:::file
        ModuleFile2["go.sum"]:::file
        Readme["README.md"]:::file
        License["LICENSE.md"]:::file
        GitIgnore[".gitignore"]:::file
    end

    %% Click events
    click CoreFile "https://github.com/surasithaof/eventbus/blob/master/eventbus.go"
    click UnitTests "https://github.com/surasithaof/eventbus/blob/master/eventbus_test.go"
    click BenchTests "https://github.com/surasithaof/eventbus/blob/master/benchmark_test.go"
    click ModuleFile1 "https://github.com/surasithaof/eventbus/blob/master/go.mod"
    click ModuleFile2 "https://github.com/surasithaof/eventbus/blob/master/go.sum"
    click Readme "https://github.com/surasithaof/eventbus/blob/master/README.md"
    click License "https://github.com/surasithaof/eventbus/blob/master/LICENSE.md"
    click GitIgnore "https://github.com/surasithaof/eventbus/blob/master/.gitignore"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef user fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef file fill:#f2f2f2,stroke:#666,stroke-dasharray: 2 2
```
