# minillmflow/pocketflow architecture

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

- Interactive diagram: https://gitdiagram.com/minillmflow/pocketflow
- Repository: https://github.com/minillmflow/pocketflow

## Overview

##### Main Components

a) Core Framework Layer:
- Core 100-line implementation (/pocketflow/__init__.py)
- Nested Directed Graph abstraction as the central architectural concept

b) Programming Paradigms Layer:
- Multi-Agent Systems
- Task Decomposition
- RAG (Retrieval Augmented Generation)
- Async/Parallel Processing (evident from test files)
- Batch Processing

c) Integration Layer:
- LLM Provider Connections
- Tool Integration
- Memory Management System

##### Specific Elements

- Flow Nodes (representing atomic operations)
- Batch Nodes (for batch processing)
- Async Nodes (for asynchronous operations)
- Memory Management System
- Tool Integration Points
- LLM Provider Integration Points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#2374ab
    classDef app fill:#7a28cb
    classDef infra fill:#ff8c42
    classDef docs fill:#grey
    classDef test fill:#green

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Applications]:::app
        L3[Infrastructure]:::infra
    end

    %% Application Layer
    subgraph ApplicationLayer
        Apps["Example Applications"]
        CustomApps["Custom Applications"]
    end
    click Apps "https://github.com/miniLLMFlow/PocketFlow/blob/main/cookbook/demo.ipynb"

    %% Core Framework Layer
    subgraph CoreFramework
        CoreImpl["Core Implementation"]
        FlowMgmt["Flow Management System"]
        NodeSys["Node System"]
        MemoryMgmt["Memory Management"]
        
        subgraph ProcessingPatterns
            AsyncProc["Async Processing"]
            BatchProc["Batch Processing"]
            ParallelProc["Parallel Processing"]
        end
        
        subgraph ProgrammingParadigms
            MultiAgent["Multi-Agent Systems"]
            TaskDecomp["Task Decomposition"]
            RAG["RAG System"]
        end
    end

    click CoreImpl "https://github.com/miniLLMFlow/PocketFlow/blob/main/pocketflow/__init__.py"
    click FlowMgmt "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/flow.md"
    click NodeSys "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/node.md"
    click MemoryMgmt "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/memory.md"
    click AsyncProc "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/async.md"
    click BatchProc "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/batch.md"
    click ParallelProc "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/parallel.md"
    click MultiAgent "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/multi_agent.md"
    click TaskDecomp "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/decomp.md"
    click RAG "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/rag.md"

    %% Infrastructure Layer
    subgraph InfrastructureLayer
        LLMIntegration["LLM Provider Integration"]
        ToolIntegration["Tool Integration"]
        Storage["Storage Systems"]
    end

    click LLMIntegration "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/llm.md"
    click ToolIntegration "https://github.com/miniLLMFlow/PocketFlow/blob/main/docs/tool.md"

    %% Test Components
    subgraph TestSuite
        AsyncTests["Async Tests"]
        BatchTests["Batch Tests"]
        BasicTests["Basic Flow Tests"]
        CompTests["Composition Tests"]
    end

    click AsyncTests "https://github.com/miniLLMFlow/PocketFlow/blob/main/tests/test_async_flow.py"
    click BatchTests "https://github.com/miniLLMFlow/PocketFlow/blob/main/tests/test_batch_flow.py"
    click BasicTests "https://github.com/miniLLMFlow/PocketFlow/blob/main/tests/test_flow_basic.py"
    click CompTests "https://github.com/miniLLMFlow/PocketFlow/blob/main/tests/test_flow_composition.py"

    %% Relationships
    Apps --> CoreImpl
    CustomApps --> CoreImpl
    CoreImpl --> FlowMgmt
    CoreImpl --> NodeSys
    CoreImpl --> MemoryMgmt
    
    FlowMgmt --> ProcessingPatterns
    FlowMgmt --> ProgrammingParadigms
    
    ProcessingPatterns --> LLMIntegration
    ProgrammingParadigms --> LLMIntegration
    
    NodeSys --> ToolIntegration
    MemoryMgmt --> Storage
    
    TestSuite -.-> CoreImpl

    %% Apply Classes
    class CoreImpl,FlowMgmt,NodeSys,MemoryMgmt,ProcessingPatterns,ProgrammingParadigms core
    class Apps,CustomApps app
    class LLMIntegration,ToolIntegration,Storage infra
    class AsyncTests,BatchTests,BasicTests,CompTests test
```
