# phunkie/streams architecture

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

- Interactive diagram: https://gitdiagram.com/phunkie/streams
- Repository: https://github.com/phunkie/streams

## Overview

Phunkie Streams is a PHP library for lazily processing finite, infinite, and effectful data sources. The main user workflow is to create a Stream, compose transformations and stream operations, then compile the result to a collection or run effects. The graph also preserves the documented file, database, network, resource-management, and parallel-processing capabilities. Some subsystem links use README descriptions because their implementation files were not sampled; unsampled details and call paths are not inferred.

Main entry points: [`src/Type/Stream.php`](https://github.com/phunkie/streams/blob/main/src/Type/Stream.php) (Stream API), [`src/Ops/Pull/CompileOps.php`](https://github.com/phunkie/streams/blob/main/src/Ops/Pull/CompileOps.php) (Pull compiler), [`src/Pull/InfinitePull.php`](https://github.com/phunkie/streams/blob/main/src/Pull/InfinitePull.php) (Infinite pull), [`src/Type/Pull.php`](https://github.com/phunkie/streams/blob/main/src/Type/Pull.php) (Pull contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_stream["Stream API"]
  node_stream_api["Stream API<br/>[Stream.php]"]
  node_stream_ops["Stream operations"]
  node_parallel_ops["Parallel operations<br/>[ParallelOps.php]"]
end

subgraph group_engine["Pull Engine"]
  node_pull_contract["Pull contract<br/>[Pull.php]"]
  node_value_pull["Values pull<br/>[ValuesPull.php]"]
  node_resource_pull["Resource pulls<br/>[ResourcePull.php]"]
  node_infinite_pull["Infinite pull<br/>[InfinitePull.php]"]
  node_scope["Pipeline scope<br/>[Scope.php]"]
  node_transformation["Transformation<br/>[Transformation.php]"]
  node_pull_compile["Pull compiler<br/>[CompileOps.php]"]
  node_stream_compiler["Stream compiler<br/>[Compiler.php]"]
end

subgraph group_sources["Data Sources"]
  node_infinite_sources["Infinite sources"]
  node_file_source["File source<br/>[Read.php]"]
  node_pdo_source["PDO rows<br/>[PDOPull.php]"]
end

subgraph group_io["I/O and Concurrency"]
  node_file_functions["File functions<br/>[file.php]"]
  node_network_api["Network API<br/>[Network.php]"]
  node_network_functions["Network functions<br/>[network.php]"]
  node_network_resources["Network resources"]
  node_closeable["Resource cleanup<br/>[Closeable.php]"]
end

node_user(("Library user"))

node_user -->|"creates and composes"| node_stream_api
node_stream_api -->|"creates values pull"| node_value_pull
node_stream_api -->|"wraps resource"| node_resource_pull
node_stream_api -->|"wraps infinite source"| node_infinite_pull
node_stream_api -->|"exposes operations"| node_stream_ops
node_stream_api -->|"exposes parallel ops"| node_parallel_ops
node_stream_api -->|"compiles through"| node_stream_compiler
node_value_pull -->|"implements"| node_pull_contract
node_resource_pull -->|"implements"| node_pull_contract
node_infinite_pull -->|"implements"| node_pull_contract
node_infinite_sources -->|"feeds infinite pull"| node_infinite_pull
node_pull_compile -->|"emits through"| node_scope
node_scope -->|"runs pipeline"| node_transformation
node_stream_compiler -->|"compiles pull"| node_pull_compile
node_file_functions -->|"reads file source"| node_file_source
node_stream_api -->|"constructs from path"| node_file_source
node_user -->|"reads and writes files"| node_file_functions
node_user -->|"streams database rows"| node_pdo_source
node_user -->|"requests network streams"| node_network_api
node_network_api -->|"delegates operations"| node_network_functions
node_network_functions -->|"uses resources"| node_network_resources
node_pull_compile -->|"closes completed pull"| node_closeable
node_user -->|"uses managed resources"| node_stream_api
node_user -->|"runs concurrent processing"| node_parallel_ops

click node_stream_api "https://github.com/phunkie/streams/blob/main/src/Type/Stream.php"
click node_stream_ops "https://github.com/phunkie/streams/tree/main/src/Ops/Stream"
click node_parallel_ops "https://github.com/phunkie/streams/blob/main/src/Ops/Stream/ParallelOps.php"
click node_pull_contract "https://github.com/phunkie/streams/blob/main/src/Type/Pull.php"
click node_value_pull "https://github.com/phunkie/streams/blob/main/src/Pull/ValuesPull.php"
click node_resource_pull "https://github.com/phunkie/streams/blob/main/src/Pull/ResourcePull.php"
click node_infinite_pull "https://github.com/phunkie/streams/blob/main/src/Pull/InfinitePull.php"
click node_scope "https://github.com/phunkie/streams/blob/main/src/Type/Scope.php"
click node_transformation "https://github.com/phunkie/streams/blob/main/src/Type/Transformation.php"
click node_pull_compile "https://github.com/phunkie/streams/blob/main/src/Ops/Pull/CompileOps.php"
click node_stream_compiler "https://github.com/phunkie/streams/blob/main/src/Stream/Compiler.php"
click node_infinite_sources "https://github.com/phunkie/streams/tree/main/src/Infinite"
click node_file_source "https://github.com/phunkie/streams/blob/main/src/IO/Read.php"
click node_pdo_source "https://github.com/phunkie/streams/blob/main/src/Pull/PDOPull.php"
click node_file_functions "https://github.com/phunkie/streams/blob/main/src/Functions/file.php"
click node_network_api "https://github.com/phunkie/streams/blob/main/src/Network.php"
click node_network_functions "https://github.com/phunkie/streams/blob/main/src/Functions/network.php"
click node_network_resources "https://github.com/phunkie/streams/tree/main/src/IO/Network"
click node_closeable "https://github.com/phunkie/streams/blob/main/src/Closeable.php"

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_stream_api,node_stream_ops,node_parallel_ops,node_user toneBlue
class node_pull_contract,node_value_pull,node_resource_pull,node_infinite_pull,node_scope,node_transformation,node_pull_compile,node_stream_compiler toneAmber
class node_infinite_sources,node_file_source,node_pdo_source toneMint
class node_file_functions,node_network_api,node_network_functions,node_network_resources,node_closeable toneRose
```

## Components

### Stream API

- [Stream API](https://github.com/phunkie/streams/blob/main/src/Type/Stream.php): `src/Type/Stream.php`
- [Stream operations](https://github.com/phunkie/streams/tree/main/src/Ops/Stream): `src/Ops/Stream`
- [Parallel operations](https://github.com/phunkie/streams/blob/main/src/Ops/Stream/ParallelOps.php): `src/Ops/Stream/ParallelOps.php`

### Pull Engine

- [Pull contract](https://github.com/phunkie/streams/blob/main/src/Type/Pull.php): `src/Type/Pull.php`
- [Values pull](https://github.com/phunkie/streams/blob/main/src/Pull/ValuesPull.php): `src/Pull/ValuesPull.php`
- [Resource pulls](https://github.com/phunkie/streams/blob/main/src/Pull/ResourcePull.php): `src/Pull/ResourcePull.php`
- [Infinite pull](https://github.com/phunkie/streams/blob/main/src/Pull/InfinitePull.php): `src/Pull/InfinitePull.php`
- [Pipeline scope](https://github.com/phunkie/streams/blob/main/src/Type/Scope.php): `src/Type/Scope.php`
- [Transformation](https://github.com/phunkie/streams/blob/main/src/Type/Transformation.php): `src/Type/Transformation.php`
- [Pull compiler](https://github.com/phunkie/streams/blob/main/src/Ops/Pull/CompileOps.php): `src/Ops/Pull/CompileOps.php`
- [Stream compiler](https://github.com/phunkie/streams/blob/main/src/Stream/Compiler.php): `src/Stream/Compiler.php`

### Data Sources

- [Infinite sources](https://github.com/phunkie/streams/tree/main/src/Infinite): `src/Infinite`
- [File source](https://github.com/phunkie/streams/blob/main/src/IO/Read.php): `src/IO/Read.php`
- [PDO rows](https://github.com/phunkie/streams/blob/main/src/Pull/PDOPull.php): `src/Pull/PDOPull.php`

### I/O and Concurrency

- [File functions](https://github.com/phunkie/streams/blob/main/src/Functions/file.php): `src/Functions/file.php`
- [Network API](https://github.com/phunkie/streams/blob/main/src/Network.php): `src/Network.php`
- [Network functions](https://github.com/phunkie/streams/blob/main/src/Functions/network.php): `src/Functions/network.php`
- [Network resources](https://github.com/phunkie/streams/tree/main/src/IO/Network): `src/IO/Network`
- [Resource cleanup](https://github.com/phunkie/streams/blob/main/src/Closeable.php): `src/Closeable.php`

### Other components

- **Library user**

## Connections

- Library user → Stream API: creates and composes (evidence: `README.md`)
- Stream API → Values pull: creates values pull (evidence: `src/Type/Stream.php`)
- Stream API → Resource pulls: wraps resource (evidence: `src/Type/Stream.php`)
- Stream API → Infinite pull: wraps infinite source (evidence: `src/Type/Stream.php`)
- Stream API → Stream operations: exposes operations (evidence: `README.md`)
- Stream API → Parallel operations: exposes parallel ops (evidence: `README.md`)
- Stream API → Stream compiler: compiles through (evidence: `src/Type/Stream.php`)
- Values pull → Pull contract: implements (evidence: `src/Pull/ValuesPull.php`)
- Resource pulls → Pull contract: implements (evidence: `src/Pull/ResourcePull.php`)
- Infinite pull → Pull contract: implements (evidence: `src/Pull/InfinitePull.php`)
- Infinite sources → Infinite pull: feeds infinite pull (evidence: `src/Pull/InfinitePull.php`)
- Pull compiler → Pipeline scope: emits through (evidence: `src/Ops/Pull/CompileOps.php`)
- Pipeline scope → Transformation: runs pipeline (evidence: `src/Type/Scope.php`)
- Stream compiler → Pull compiler: compiles pull (evidence: `src/Stream/Compiler.php`)
- File functions → File source: reads file source (evidence: `src/Functions/file.php`)
- Stream API → File source: constructs from path (evidence: `src/Type/Stream.php`)
- Library user → File functions: reads and writes files (evidence: `README.md`)
- Library user → PDO rows: streams database rows (evidence: `README.md`)
- Library user → Network API: requests network streams (evidence: `README.md`)
- Network API → Network functions: delegates operations (evidence: `src/Network.php`)
- Network functions → Network resources: uses resources (evidence: `src/Functions/network.php`)
- Pull compiler → Resource cleanup: closes completed pull (evidence: `src/Ops/Pull/CompileOps.php`)
- Library user → Stream API: uses managed resources (evidence: `README.md`)
- Library user → Parallel operations: runs concurrent processing (evidence: `README.md`)
