# pyper-dev/pyper architecture

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

- Interactive diagram: https://gitdiagram.com/pyper-dev/pyper
- Repository: https://github.com/pyper-dev/pyper

## Overview

##### Main Components

a) Core Framework Components:
- Task Decorator System
- Pipeline Execution Engine
- Worker Management System
- Queue-based Communication Layer

b) Execution Models:
- Thread Pool
- Process Pool
- Async Task Pool

##### Key Relationships to Highlight

a) Data Flow:
- Worker pool distribution

b) Control Flow:
- Error propagation paths
- Resource lifecycle management

##### Implementation Details

- Worker Pool Configuration
- Queue Implementation (sync_helper and async_helper)
- Task Group Management
- Pipeline Composition Logic

##### Specific Components from File Structure

Core Components:
**src/pyper/_core/**
- async_helper/
- sync_helper/
- pipeline.py
- task.py
- util/

How these components interact:
- task.py defines the decorator interface
- pipeline.py handles execution flow
- async_helper and sync_helper manage different execution models
- util/ provides supporting functionality

##### Additional Notes

- Zero-dependency nature of the project
- Integration points with Python standard library components
- Error handling and resource management paths
- Examples of different worker configurations

- Intuitive API design
- Functional programming paradigm
- Safety in concurrent execution
- Efficient resource utilization
- Pure Python implementation

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef queue fill:#4CAF50,stroke:#2E7D32,color:white
    classDef worker fill:#FF9800,stroke:#EF6C00,color:white
    classDef engine fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef util fill:#9E9E9E,stroke:#616161,color:white

    %% Public API Layer
    subgraph API
        TaskDecorator["@task Decorator"]:::api
        PipelineInterface["Pipeline Interface"]:::api
    end
    click TaskDecorator "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/task.py"
    click PipelineInterface "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/pipeline.py"

    %% Execution Engine Layer
    subgraph ExecutionEngine
        AsyncPipeline["Async Pipeline"]:::engine
        SyncPipeline["Sync Pipeline"]:::engine
        WorkerPool["Worker Pool Manager"]:::worker
    end
    click AsyncPipeline "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/pipeline.py"
    click SyncPipeline "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/pipeline.py"
    click WorkerPool "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/util/worker_pool.py"

    %% Communication Layer
    subgraph Communication
        SyncQueue["Sync Queue IO"]:::queue
        AsyncQueue["Async Queue IO"]:::queue
    end
    click SyncQueue "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/sync_helper/queue_io.py"
    click AsyncQueue "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/async_helper/queue_io.py"

    %% Runtime Layer
    subgraph Runtime
        ThreadPool["Thread Pool"]:::worker
        ProcessPool["Process Pool"]:::worker
        AsyncPool["Async Pool"]:::worker
    end

    %% Utility Components
    subgraph Utilities
        TaskGroup["Task Group"]:::util
        Sentinel["Sentinel"]:::util
        Asynchronize["Asynchronize"]:::util
    end
    click TaskGroup "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/util/task_group.py"
    click Sentinel "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/util/sentinel.py"
    click Asynchronize "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/util/asynchronize.py"

    %% Execution Models
    subgraph SyncModel
        SyncStage["Sync Stage"]:::engine
        SyncOutput["Sync Output"]:::engine
    end
    click SyncStage "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/sync_helper/stage.py"
    click SyncOutput "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/sync_helper/output.py"

    subgraph AsyncModel
        AsyncStage["Async Stage"]:::engine
        AsyncOutput["Async Output"]:::engine
    end
    click AsyncStage "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/async_helper/stage.py"
    click AsyncOutput "https://github.com/pyper-dev/pyper/blob/main/src/pyper/_core/async_helper/output.py"

    %% Relationships
    TaskDecorator --> PipelineInterface
    PipelineInterface --> AsyncPipeline & SyncPipeline
    AsyncPipeline --> WorkerPool
    SyncPipeline --> WorkerPool
    WorkerPool --> ThreadPool & ProcessPool & AsyncPool
    ThreadPool & ProcessPool & AsyncPool --> SyncQueue & AsyncQueue
    AsyncPipeline --> AsyncModel
    SyncPipeline --> SyncModel
    WorkerPool --> TaskGroup
    TaskGroup --> Sentinel
    AsyncModel & SyncModel --> Asynchronize

    %% Legend
    subgraph Legend
        API_L["API Components"]:::api
        Queue_L["Queue Components"]:::queue
        Worker_L["Worker Components"]:::worker
        Engine_L["Engine Components"]:::engine
        Util_L["Utility Components"]:::util
    end
```
