# bud-ro/zig-pub-sub architecture

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

- Interactive diagram: https://gitdiagram.com/bud-ro/zig-pub-sub
- Repository: https://github.com/bud-ro/zig-pub-sub

## Overview

##### Project Type Analysis
This is a specialized embedded systems library implementing a publish-subscribe pattern with data storage abstraction. The project is written in Zig and emphasizes compile-time optimizations and memory efficiency.

##### Main Components

A. Core Components:
- SystemData (Central Manager)
- Data Components
- RAMDataComponent
- IndirectDataComponent
- ERD (Event Resource Data) Definitions
- Subscription Management
- Timer System

B. Key Interactions:
- Data Flow
- Subscription Management
- Event Publishing
- Component Communication

**Top Level (Application Interface):**
**┌─────────────────────────────────────────┐**
- SystemData Manager           │
- ┘

**Middle Level (Data Components):**
**┌─────────────┐    ┌─────────────┐**
- RAM     │    │  Indirect   │
- Component   │    │  Component  │
- ┘    └─────────────┘

**Bottom Level (Core Mechanisms):**
**┌─────────────┐    ┌─────────────┐**
- Subscription │    │    Timer    │
- System     │    │   System    │
- ┘    └─────────────┘

##### Key Relationships

a) Data Flow:
- SystemData → Data Components (fetch_component)
- Data Components → Storage Medium
- Subscription System → Components (notifications)

b) Control Flow:
- Subscribe/Unsubscribe operations
- Publish operations
- Component initialization chain

##### Interface Layer
- ┌─────────────────────────────────────┐
- Public Interface          │
- init()                           │
- fetch_component()                │
- subscribe()/unsubscribe()        │
- publish()                        │
- ┘

##### Component Layer
- ┌─────────────────┐    ┌─────────────────┐
- RAM Component  │    │Indirect Component│
- read()        │    │ - read()        │
- write()       │    │ - write()       │
- ┘    └─────────────────┘

##### Event Management Layer
- ┌─────────────────┐    ┌─────────────────┐
- Subscription  │    │      Timer      │
- Management   │    │     System      │
- ┘    └─────────────────┘

##### Additional Notes

- A note about the compile-time optimization strategy
- ERD ownership boundaries
- Subscription array size limitations
- Critical paths for real-time operations

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef data fill:#90EE90,stroke:#333
    classDef utility fill:#FFE5B4,stroke:#333
    classDef subscription fill:#DDA0DD,stroke:#333
    classDef test fill:#F0F0F0,stroke:#333
    classDef erd fill:#FFB6C1,stroke:#333

    %% Main System Components
    SystemData["SystemData Manager"]:::core
    RAMComp["RAM Data Component"]:::data
    IndirectComp["Indirect Data Component"]:::data
    Timer["Timer System"]:::utility
    SubSystem["Subscription System"]:::subscription
    ERD["ERD Definitions"]:::erd

    %% Test Components
    Tests["Unit Tests"]:::test
    SysTest["System Data Tests"]:::test
    RAMTest["RAM Component Tests"]:::test
    IndirectTest["Indirect Component Tests"]:::test
    TimerTest["Timer Tests"]:::test

    %% Relationships
    SystemData --> RAMComp
    SystemData --> IndirectComp
    SystemData --> SubSystem
    SystemData --> Timer
    SystemData --> ERD

    RAMComp --> SubSystem
    IndirectComp --> SubSystem

    %% Test Relationships
    Tests --> SysTest
    Tests --> RAMTest
    Tests --> IndirectTest
    Tests --> TimerTest

    %% Notes
    subgraph Notes
        CompileTime["Compile-time Optimizations"]
        MemoryConstraints["Memory Constraints"]
        SubLimits["Subscription Array Limits"]
    end

    %% Click Events
    click SystemData "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/system_data.zig"
    click RAMComp "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/ram_data_component.zig"
    click IndirectComp "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/indirect_data_component.zig"
    click ERD "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/erd.zig"
    click SubSystem "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/subscription.zig"
    click Timer "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/timer.zig"
    click Tests "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/unit_tests.zig"
    click SysTest "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/tests/system_data_test.zig"
    click RAMTest "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/tests/ram_data_component_test.zig"
    click IndirectTest "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/tests/indirect_data_component_test.zig"
    click TimerTest "https://github.com/Bud-ro/zig-pub-sub/blob/master/src/tests/timer_test.zig"
```
