# kjdragan/pf1 architecture

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

- Interactive diagram: https://gitdiagram.com/kjdragan/pf1
- Repository: https://github.com/kjdragan/pf1

## Overview

##### Main Components
- Core Application: Highlight the primary entry points like main.py and flow.py which likely drive the orchestration of the LLM pipeline.
- Nodes Architecture: Emphasize the “nodes” folder (both at the project root and under src/nodes). These include:
- Base Node (common functionality)
- Specialized nodes such as content extraction, ELI5 transformation, HTML generation, input processing, question answering, topic extraction, topic orchestration, and topic processing.
- Utility Functions: Include the utilities from both src/utils and utils folders that handle tasks like calling the LLM, extracting YouTube metadata and transcripts, generating HTML, logging, and URL validations.
- Documentation: Reference the “docs” folder (e.g., design.md, requirements.md) which provides further insights into design choices and requirements.
- Configurations and Metadata: Mark configuration files like pyproject.toml, requirements.txt, and version/configuration files like .python-version.
- Supporting Elements: Include the “Kevin” folder that appears to have experimental or future implementation notes and details.
- External Services: Represent external interactions with LLM endpoints as indicated by the call_llm utilities and other extraction functionalities (e.g., YouTube metadata).
- Agentic Coding Integration: Note the inclusion of specific rule sets (cursorrules, clinerules, windsurfrules) that integrate with coding assistants.

##### Relationships and Interactions
- Data Flow: Illustrate how input data is processed starting with input_processing_node, then routed to content extraction or topic extraction nodes, then to further transformation (ELI5, QA generation) and HTML generation nodes.
- Control Flow: Show that a central orchestration (possibly handled by flow.py and/or topic_orchestrator_node) directs how the individual nodes interconnect.

##### Architectural Patterns and Design Principles
- Modular Pipeline: The “nodes” directory indicates that the project leverages a modular design where each node encapsulates a distinct piece of functionality.
- Separation of Concerns: Frontline processing in main.py and flow.py orchestrates the various nodes, while utility functions handle low-level service integration.
- Extensibility: The inclusion of extra future implementation notes (found in the “Kevin” folder) suggests that the design supports adding new nodes or updating the LLM workflow without major refactoring.
- Clear Layering: Mark the division of responsibilities between orchestration, node-specific processing, and utility/auxiliary functions.

##### Relevant Technologies and Frameworks
- LLM Integration: Emphasize the use of the Pocket Flow framework for interacting with large language models.
- Python Ecosystem: Since Python is heavily used (main script files, pyproject.toml, requirements.txt), note the reliance on Python libraries and dependencies.
- Documentation and Configuration: The existence of detailed design and requirement documents suggests adherence to design standards and potential use of continuous integration and deployment practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Inputs
    U("User Input"):::external

    %% Core Application Subgraph
    subgraph "Core Application"
        CORE_MAIN("main.py"):::core
        CORE_FLOW("flow.py"):::core
        CORE_NODES("nodes.py"):::core
    end

    %% Nodes Pipeline Subgraph
    subgraph "Nodes Pipeline"
        BASE_NODE("Base Node"):::node
        IPN("Input Processing Node"):::node
        CEN("Content Extraction Node"):::node
        ELI5("ELI5 Transformation Node"):::node
        QAN("QA Generation Node"):::node
        HTMLN("HTML Generation Node"):::node
        TEN("Topic Extraction Node"):::node
        TORCH("Topic Orchestrator Node"):::node
        TPN("Topic Processor Node"):::node
    end

    %% Utility Functions Subgraph
    subgraph "Utility Functions"
        LLM1("Call LLM Utility (src)"):::utility
        LLM2("Call LLM Utility (utils)"):::utility
        YT_META("YouTube Metadata Extraction"):::utility
        YT_TRANS("YouTube Transcript Extraction"):::utility
        HTML_UTIL("HTML Generation Utility"):::utility
        LOGGER("Logger Utility"):::utility
        URL_VALID("URL Validation Utility"):::utility
    end

    %% External Services
    EXT("LLM API"):::external

    %% Ancillary Components (Documentation, Config, Support, Agentic)
    DOC("Documentation"):::doc
    CONFIG("Configurations & Metadata"):::config
    SUPPORT("Kevin (Experimental)"):::support
    AGENTIC("Agentic Coding Rules"):::agentic

    %% Data Flow Connections
    U -->|"enters"| CORE_MAIN
    CORE_NODES -->|"triggers"| IPN

    %% Process Pipeline Branches
    IPN -->|"branch"| CEN
    CEN -->|"transform"| ELI5
    ELI5 -->|"generate"| QAN
    QAN -->|"output"| HTMLN

    IPN -->|"branch"| TEN
    TEN -->|"orchestrate"| TORCH
    TORCH -->|"process"| TPN
    TPN -->|"merge"| HTMLN

    %% Inheritance / Shared Base Node (dotted connections)
    CEN ---|"inherits"| BASE_NODE
    ELI5 ---|"inherits"| BASE_NODE
    QAN ---|"inherits"| BASE_NODE
    HTMLN ---|"inherits"| BASE_NODE
    TEN ---|"inherits"| BASE_NODE
    TORCH ---|"inherits"| BASE_NODE
    TPN ---|"inherits"| BASE_NODE

    %% Utility Interactions
    CEN -->|"calls"| LLM1
    CEN -->|"calls"| LLM2
    ELI5 -->|"calls"| LLM1
    ELI5 -->|"calls"| LLM2
    QAN -->|"calls"| LLM1
    QAN -->|"calls"| LLM2
    IPN -->|"processes"| YT_META
    IPN -->|"processes"| YT_TRANS
    IPN -->|"validates"| URL_VALID
    HTMLN -->|"builds"| HTML_UTIL

    %% Utilities to External LLM API
    LLM1 -->|"requests"| EXT
    LLM2 -->|"requests"| EXT

    %% Logger shared connection (dotted for cross-cutting concerns)
    BASE_NODE --- LOGGER

    %% Ancillary Components Connections
    CORE_MAIN -.-> DOC
    CORE_FLOW -.-> CONFIG
    CORE_NODES -.-> CONFIG
    CORE_MAIN -.-> SUPPORT
    CORE_FLOW -.-> AGENTIC

    %% Styles and Legend
    classDef core fill:#f9d6b3,stroke:#333,stroke-width:2px;
    classDef node fill:#ccf2ff,stroke:#333,stroke-width:2px;
    classDef utility fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef doc fill:#fef9c3,stroke:#333,stroke-width:2px;
    classDef config fill:#f6ddcc,stroke:#333,stroke-width:2px;
    classDef support fill:#f4cccc,stroke:#333,stroke-width:2px;
    classDef agentic fill:#ead1dc,stroke:#333,stroke-width:2px;
    classDef external fill:#d9ead3,stroke:#333,stroke-width:2px;

    %% Click Events for Core Application
    click CORE_MAIN "https://github.com/kjdragan/pf1/blob/main/main.py"
    click CORE_FLOW "https://github.com/kjdragan/pf1/blob/main/flow.py"
    click CORE_NODES "https://github.com/kjdragan/pf1/blob/main/nodes.py"

    %% Click Events for Nodes Architecture
    click BASE_NODE "https://github.com/kjdragan/pf1/blob/main/src/nodes/base_node.py"
    click CEN "https://github.com/kjdragan/pf1/blob/main/src/nodes/content_extraction_node.py"
    click ELI5 "https://github.com/kjdragan/pf1/blob/main/src/nodes/eli5_transformation_node.py"
    click HTMLN "https://github.com/kjdragan/pf1/blob/main/src/nodes/html_generation_node.py"
    click IPN "https://github.com/kjdragan/pf1/blob/main/src/nodes/input_processing_node.py"
    click QAN "https://github.com/kjdragan/pf1/blob/main/src/nodes/qa_generation_node.py"
    click TEN "https://github.com/kjdragan/pf1/blob/main/src/nodes/topic_extraction_node.py"
    click TORCH "https://github.com/kjdragan/pf1/blob/main/src/nodes/topic_orchestrator_node.py"
    click TPN "https://github.com/kjdragan/pf1/blob/main/src/nodes/topic_processor_node.py"

    %% Click Events for Utility Functions
    click LLM1 "https://github.com/kjdragan/pf1/blob/main/src/utils/call_llm.py"
    click LLM2 "https://github.com/kjdragan/pf1/blob/main/utils/call_llm.py"
    click YT_META "https://github.com/kjdragan/pf1/blob/main/src/utils/extract_youtube_metadata.py"
    click YT_TRANS "https://github.com/kjdragan/pf1/blob/main/src/utils/extract_youtube_transcript.py"
    click HTML_UTIL "https://github.com/kjdragan/pf1/blob/main/src/utils/generate_html.py"
    click LOGGER "https://github.com/kjdragan/pf1/blob/main/src/utils/logger.py"
    click URL_VALID "https://github.com/kjdragan/pf1/blob/main/src/utils/validate_youtube_url.py"

    %% Click Events for Documentation
    click DOC "https://github.com/kjdragan/pf1/tree/main/docs"

    %% Click Events for Configurations and Metadata
    click CONFIG "https://github.com/kjdragan/pf1/blob/main/.python-version"
    click CONFIG "https://github.com/kjdragan/pf1/blob/main/pyproject.toml"
    click CONFIG "https://github.com/kjdragan/pf1/blob/main/requirements.txt"

    %% Click Events for Supporting Elements
    click SUPPORT "https://github.com/kjdragan/pf1/tree/main/Kevin"

    %% Click Events for Agentic Coding Integration
    click AGENTIC "https://github.com/kjdragan/pf1/blob/main/.cursorrules"
    click AGENTIC "https://github.com/kjdragan/pf1/blob/main/.clinerules"
    click AGENTIC "https://github.com/kjdragan/pf1/blob/main/.windsurfrules"
```
