# maxjeblick/llm-docstring-generator architecture

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

- Interactive diagram: https://gitdiagram.com/maxjeblick/llm-docstring-generator
- Repository: https://github.com/maxjeblick/llm-docstring-generator

## Overview

##### Component Details and Relationships

a) Parser Components (llm_docstring_generator/parser/):
- AST Parser
- Import Parser
- Python File Parser
- Load Python Files

b) Dependency Resolution System (llm_docstring_generator/sorters/):
- Function Import Graph
- Python File Sorter
- Code2Flow Integration
This as a crucial middleware layer that processes parser output.

c) LLM Integration (llm_docstring_generator/llm/):
- LLM Interface
- Cache Database
- Configuration
- Prompts Manager
This as a separate service with clear API boundaries.

d) Pipeline Orchestration (llm_docstring_generator/pipelines/):
- Code Annotation Pipeline
- Code Graph
- Default Pipelines
This as the central coordinator connecting all components.

##### Data Flow Representation

**Repository Input → Parser Layer**
**↓**
**Parser Output → Dependency Resolver**
**↓**
**Sorted Code Structure → Annotation Pipeline**
**↓**
**Code Chunks → LLM Service**
**↓**
**Generated Docstrings → File Writer**

##### Additional Elements

- Configuration points where customization is possible
- Error handling/retry mechanisms
- Caching points

##### Technical Details

- File formats (.py files)
- Database type (SQLite)
- Supported LLM providers (OpenAI, TGI)
- Key dependencies (graphviz, code2flow)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        RepoInput["Repository Input"]
        Config["Configuration"]:::config
    end

    subgraph "Parser Layer"
        ASTParser["AST Parser"]:::parser
        ImportParser["Import Parser"]:::parser
        PyFileParser["Python File Parser"]:::parser
        FileLoader["File Loader"]:::parser
        DepResolver["Dependency Resolver"]:::parser
    end

    subgraph "Dependency Resolution"
        FuncGraph["Function Import Graph"]:::resolver
        FileSorter["Python File Sorter"]:::resolver
        Code2Flow["Code2Flow Integration"]:::resolver
        ImportDeps["Import Dependencies"]:::resolver
    end

    subgraph "LLM Integration"
        LLMInterface["LLM Interface"]:::llm
        CacheDB[(Cache Database)]:::db
        LLMConfig["LLM Configuration"]:::llm
        Prompts["Prompts Manager"]:::llm
    end

    subgraph "Pipeline Orchestration"
        CodePipeline["Code Annotation Pipeline"]:::pipeline
        CodeGraph["Code Graph"]:::pipeline
        DefaultPipes["Default Pipelines"]:::pipeline
        PipeRunner["Pipeline Runner"]:::pipeline
    end

    subgraph "Code Annotation"
        CodeAnnotator["Code Annotator"]:::annotator
        MetaProvider["Metadata Provider"]:::annotator
    end

    subgraph "Models"
        FuncClasses["Functions and Classes"]:::model
        Imports["Imports"]:::model
        PyFile["Python File"]:::model
    end

    %% Relationships
    RepoInput --> FileLoader
    Config --> LLMConfig
    
    FileLoader --> PyFileParser
    PyFileParser --> ASTParser
    PyFileParser --> ImportParser
    ImportParser --> DepResolver
    
    DepResolver --> FuncGraph
    FuncGraph --> FileSorter
    FileSorter --> Code2Flow
    Code2Flow --> ImportDeps
    
    ImportDeps --> CodePipeline
    CodePipeline --> CodeGraph
    CodeGraph --> DefaultPipes
    DefaultPipes --> PipeRunner
    
    PipeRunner --> LLMInterface
    LLMInterface --> CacheDB
    LLMInterface --> Prompts
    LLMConfig --> LLMInterface
    
    PipeRunner --> CodeAnnotator
    CodeAnnotator --> MetaProvider
    
    PyFileParser --> FuncClasses
    ImportParser --> Imports
    FileLoader --> PyFile

    %% Styles
    classDef parser fill:#2374ab
    classDef resolver fill:#ff8c42
    classDef llm fill:#ffcd3c
    classDef pipeline fill:#2c5530
    classDef annotator fill:#8cb369
    classDef model fill:#bad1cd
    classDef config fill:#d4afb9
    classDef db fill:#95a5a6

    %% Click Events
    click ASTParser "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/parser/ast_parser.py"
    click ImportParser "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/parser/import_parser.py"
    click PyFileParser "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/parser/python_file_parser.py"
    click FileLoader "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/parser/load_python_files.py"
    click DepResolver "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/parser/dependency_resolver.py"
    click FuncGraph "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/sorters/function_import_graph.py"
    click FileSorter "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/sorters/sort_python_files.py"
    click Code2Flow "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/sorters/code2flow_patched.py"
    click ImportDeps "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/sorters/get_import_dependencies.py"
    click LLMInterface "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/llm/llm.py"
    click CacheDB "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/llm/cache_database.py"
    click LLMConfig "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/llm/llm_config.py"
    click Prompts "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/llm/prompts.py"
    click CodePipeline "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/pipelines/code_annotation_pipeline.py"
    click CodeGraph "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/pipelines/code_graph.py"
    click DefaultPipes "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/pipelines/default_pipelines.py"
    click PipeRunner "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/pipelines/run_code_annotation_pipeline.py"
    click CodeAnnotator "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/annotator/code_annotator.py"
    click MetaProvider "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/annotator/metadata_provider.py"
    click Config "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/utils/base_config.py"
    click FuncClasses "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/python_files/function_and_classes.py"
    click Imports "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/python_files/imports.py"
    click PyFile "https://github.com/maxjeblick/llm-docstring-generator/blob/main/llm_docstring_generator/python_files/python_file.py"
```
