# texorn/gitsnip architecture

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

- Interactive diagram: https://gitdiagram.com/texorn/gitsnip
- Repository: https://github.com/texorn/gitsnip

## Overview

##### Project Type and Purpose
- Key indicators:
- main.py: CLI entry point
- flow.py & nodes.py: define the PocketFlow pipeline and individual processing steps

##### Top-Level Components
- **CLI Layer**
- main.py: Parses arguments (`--dir` / `--repo`, include/exclude patterns, output path) and kicks off the flow.
- **Orchestration Layer**
- flow.py: Defines the overall workflow (PocketFlow “flow”). Coordinates node execution in sequence.
- nodes.py: Contains discrete “nodes” (pipeline stages) such as fetch, identify_abstractions, analyze_relationships, order_chapters, write_chapters, combine_tutorial, validate_diagrams.
- **Utility Layer** (utils package)
- crawl_local_files.py / crawl_github_files.py: Fetch source files.
- get_embedding.py: Calls embedding service to vectorize code chunks.
- call_llm.py: Wraps Google Gemini API calls for analysis and content generation.
- prepare_for_llm.py: Prepares prompts and chunks for LLM consumption.
- **External Services**
- Google Gemini (via google-genai)
- GitHub API (via PyGithub)
- **Output**

##### Relationships and Data Flows
- **main.py → flow.py**
The CLI passes configuration into the PocketFlow orchestrator.
- **flow.py → nodes.py**
The flow triggers each node in turn.
- **Fetch Node**
- Uses crawl_local or crawl_github → returns raw file contents.
- **Embedding & Clustering Node**
- get_embedding → clusters large codebases into manageable chunks.
- **LLM Analysis Nodes**
- call_llm (via identify_abstractions & analyze_relationships) → extracts key concepts and relationships.
- **Chapter Generation Nodes**
- prepare_for_llm → formats prompts
- write_chapters → writes individual files
- **Combine & Validate Node**
- **Output Directory**
- All generated files stored under `./output-directory/Project_Name`.

##### Highlighted Architectural Patterns
- **Pipeline / Workflow Pattern** (PocketFlow)
- Each node is a single responsibility, with inputs & outputs passed along.
- **Modular Utility Functions**
- The utils package encapsulates all I/O, API calls, and data processing.
- **External-Service Integration**

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        CLI["main.py"]:::cli
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        Flow["flow.py"]:::orchestrator
        Nodes["nodes.py"]:::orchestrator
    end

    %% Processing Nodes
    subgraph "PocketFlow Pipeline" 
        direction TB
        Fetch["Fetch Node"]:::node
        Identify["Identify Abstractions"]:::node
        Analyze["Analyze Relationships"]:::node
        Order["Order Chapters"]:::node
        Write["Write Chapters"]:::node
        Combine["Combine Tutorial"]:::node
        Validate["Validate Diagrams"]:::node
    end

    %% Utility Layer
    subgraph "Utils Package"
        direction TB
        CrawlLocal["crawl_local_files.py"]:::util
        CrawlGithub["crawl_github_files.py"]:::util
        Embedding["get_embedding.py"]:::util
        CallLLM["call_llm.py"]:::util
        Prepare["prepare_for_llm.py"]:::util
        ValidateUtil["validate_mermaid.py"]:::util
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Gemini["Google Gemini"]:::external
        GitHubAPI["GitHub API"]:::external
        MermaidCLI["Mermaid CLI"]:::external
    end

    %% Output
    subgraph "Output Directory" 
        direction TB
        OutDir["./output-directory/Project_Name"]:::output
        OutREADME["README.md"]:::output
        Chapters["Chapter Files"]:::output
    end

    %% Metadata
    subgraph "Project Metadata & Dependencies"
        direction TB
        MetaReadme["README.md"]:::metadata
        Requirements["requirements.txt"]:::metadata
        Gitignore[".gitignore"]:::metadata
    end

    %% Connections
    CLI -->|"config args"| Flow
    Flow -->|"defines workflow"| Nodes

    Nodes --> Fetch
    Nodes --> Identify
    Nodes --> Analyze
    Nodes --> Order
    Nodes --> Write
    Nodes --> Combine
    Nodes --> Validate

    Fetch -->|"file list"| Prepare
    Prepare -->|"chunks"| Embedding
    Embedding -->|"embeddings"| Identify
    Identify -->|"abstractions"| Analyze
    Analyze -->|"relationships"| Order
    Order -->|"chapter order"| Write
    Write -->|"Markdown content"| Combine
    Combine -->|"combined tutorial"| Validate
    Validate -->|"validated diagrams"| OutDir

    %% Utils connections
    Fetch --> CrawlLocal
    Fetch --> CrawlGithub
    Identify --> CallLLM
    Analyze --> CallLLM
    Write --> CallLLM
    Prepare --> Prepare
    Embedding --> Embedding
    Validate --> ValidateUtil

    %% External integrations
    CrawlGithub -->|"API calls"| GitHubAPI
    CallLLM -->|"LLM requests"| Gemini
    Embedding -->|"embedding API"| Gemini
    ValidateUtil -->|"Mermaid lint"| MermaidCLI

    %% Output files
    OutDir --> OutREADME
    OutDir --> Chapters

    %% Click Events
    click CLI "https://github.com/texorn/gitsnip/blob/main/main.py"
    click Flow "https://github.com/texorn/gitsnip/blob/main/flow.py"
    click Nodes "https://github.com/texorn/gitsnip/blob/main/nodes.py"
    click CrawlLocal "https://github.com/texorn/gitsnip/blob/main/utils/crawl_local_files.py"
    click CrawlGithub "https://github.com/texorn/gitsnip/blob/main/utils/crawl_github_files.py"
    click Embedding "https://github.com/texorn/gitsnip/blob/main/utils/get_embedding.py"
    click CallLLM "https://github.com/texorn/gitsnip/blob/main/utils/call_llm.py"
    click Prepare "https://github.com/texorn/gitsnip/blob/main/utils/prepare_for_llm.py"
    click ValidateUtil "https://github.com/texorn/gitsnip/blob/main/validate_mermaid.py"
    click MetaReadme "https://github.com/texorn/gitsnip/blob/main/README.md"
    click Requirements "https://github.com/texorn/gitsnip/blob/main/requirements.txt"
    click Gitignore "https://github.com/texorn/gitsnip/blob/main/.gitignore"

    %% Styles
    classDef cli fill:#D0E6FF,stroke:#0366d6
    classDef orchestrator fill:#D0E6FF,stroke:#0366d6
    classDef node fill:#E6FFE6,stroke:#34a853
    classDef util fill:#F0F0F0,stroke:#999999
    classDef external fill:#FFE6CC,stroke:#FB8C00
    classDef output fill:#FFF4CC,stroke:#FFEB3B
    classDef metadata fill:#FCE4EC,stroke:#E91E63
```
