# ahdinosaur/push-stream architecture

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

- Interactive diagram: https://gitdiagram.com/ahdinosaur/push-stream
- Repository: https://github.com/ahdinosaur/push-stream

## Overview

##### Main Components

a) Core Stream Component:
- Stream Constructor (from stream.js)
- Push Mechanism
- Observer Registry
- Unsubscribe Mechanism

b) Stream Operators:
- Transform
- Filter Transform
- Unique Value Filter
- Async Map Transform
- State Management
- Spy/Debug Pipeline

c) Stream Sources:
- Values Stream (Array Source)
- State Stream (Stateful Source)

**TOP LAYER: Stream Sources**
- [Values] [State] [Custom Sources]

- ▼        ▼         ▼
**MIDDLE LAYER: Stream Operators**
- [Map] [Filter] [Uniq] [MapAsync]

- ▼        ▼         ▼
**BOTTOM LAYER: Observers/Subscribers**
- [Observer 1] [Observer 2] [Observer N]

##### Flow Representation

Use the following elements:
- Blue rectangles for stream sources
- Green rectangles for stream operators
- Yellow rectangles for observers
- Red diamonds for stream termination points

##### Important Details

a) Core Mechanics:
- Push() method flow
- Observer subscription/unsubscription
- Demonstrate pipeline composition

b) State Management:
- State storage
- Immediate value emission
- State updates

c) Error Handling:
- Error propagation paths
- Error boundaries

##### Implementation Details

- The minimal nature of the implementation
- The composability of stream operators
- The push-based nature of data flow
- The observer pattern implementation

##### Additional Elements

- How the pipeline is constructed
- How values flow through multiple operators
- How the unsubscribe chain works

Remember to:
- Keep the main flow clear and centered
- Use consistent sizing for similar components
- Code examples for key operations
- Both simple and complex pipeline examples

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef source fill:#b3d9ff,stroke:#333
    classDef operator fill:#90EE90,stroke:#333
    classDef observer fill:#FFE5B4,stroke:#333
    classDef core fill:#FFB6C1,stroke:#333
    classDef test fill:#E6E6FA,stroke:#333

    %% Core Components
    subgraph CoreComponents
        Stream["Stream Constructor"]:::core
        Push["Push Mechanism"]:::core
        Observable["Observable Interface"]:::core
    end

    %% Stream Sources
    subgraph Sources
        Values["Values Stream"]:::source
        State["State Stream"]:::source
        Custom["Custom Sources"]:::source
    end

    %% Stream Operators
    subgraph Operators
        Map["Map Transform"]:::operator
        Filter["Filter Transform"]:::operator
        Uniq["Unique Filter"]:::operator
        MapAsync["Async Map"]:::operator
        Spy["Spy/Debug"]:::operator
    end

    %% Observers
    subgraph Observers
        Obs1["Observer 1"]:::observer
        Obs2["Observer 2"]:::observer
        ObsN["Observer N"]:::observer
    end

    %% Test Components
    subgraph Tests
        FilterTest["Filter Tests"]:::test
        MapTest["Map Tests"]:::test
        AsyncTest["Async Map Tests"]:::test
        PushTest["Push Tests"]:::test
        StateTest["State Tests"]:::test
        StreamTest["Stream Tests"]:::test
        UniqTest["Unique Tests"]:::test
    end

    %% Connections
    Values --> Stream
    State --> Stream
    Custom --> Stream

    Stream --> Map
    Stream --> Filter
    Stream --> Uniq
    Stream --> MapAsync
    Stream --> Spy

    Map --> Obs1
    Filter --> Obs2
    Uniq --> ObsN
    MapAsync -.-> Obs1
    Spy --> Obs2

    Push --> Stream
    Observable --> Stream

    %% Click Events
    click Stream "https://github.com/ahdinosaur/push-stream/blob/master/stream.js"
    click Push "https://github.com/ahdinosaur/push-stream/blob/master/push.js"
    click Observable "https://github.com/ahdinosaur/push-stream/blob/master/readable.js"
    click Values "https://github.com/ahdinosaur/push-stream/blob/master/values.js"
    click State "https://github.com/ahdinosaur/push-stream/blob/master/state.js"
    click Map "https://github.com/ahdinosaur/push-stream/blob/master/map.js"
    click Filter "https://github.com/ahdinosaur/push-stream/blob/master/filter.js"
    click Uniq "https://github.com/ahdinosaur/push-stream/blob/master/uniq.js"
    click MapAsync "https://github.com/ahdinosaur/push-stream/blob/master/mapAsync.js"
    click Spy "https://github.com/ahdinosaur/push-stream/blob/master/spy.js"
    click FilterTest "https://github.com/ahdinosaur/push-stream/blob/master/test/filter.js"
    click MapTest "https://github.com/ahdinosaur/push-stream/blob/master/test/map.js"
    click AsyncTest "https://github.com/ahdinosaur/push-stream/blob/master/test/mapAsync.js"
    click PushTest "https://github.com/ahdinosaur/push-stream/blob/master/test/push.js"
    click StateTest "https://github.com/ahdinosaur/push-stream/blob/master/test/state.js"
    click StreamTest "https://github.com/ahdinosaur/push-stream/blob/master/test/stream.js"
    click UniqTest "https://github.com/ahdinosaur/push-stream/blob/master/test/uniq.js"

    %% Legend
    subgraph Legend
        L1["Source"]:::source
        L2["Operator"]:::operator
        L3["Observer"]:::observer
        L4["Core Component"]:::core
        L5["Test"]:::test
    end
```
