# impredicative/podgenai architecture

> Architecture diagram of the GitHub repository impredicative/podgenai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/impredicative/podgenai
- Repository: https://github.com/impredicative/podgenai

## Overview

##### Main Components Overview

a) Input Layer
- Topic Input Handler
- Configuration Manager (environment variables, OpenAI API keys)

b) Core Processing Layer
- Content Generation Engine
- Audio Processing Pipeline

c) Storage Layer
- Cache Management System
- Output File Handler

##### Detailed Component Breakdown

Create sub-sections showing:

a) Content Generation Pipeline:
- Topic Analyzer
- Subtopic Generator (using GPT-4)
- Voice Selector
- Text Content Generator
- Text-to-Speech Converter (using OpenAI TTS-1)

b) Audio Processing:
- Audio Segment Generator
- Audio Concatenation Service (using ffmpeg)
- Marker Integration System

##### Data Flow Representation

Following flows:

a) Primary Flow:
Topic Input → Subtopic Generation → Content Generation → Audio Generation → Final Output

b) Secondary Flows:
- Cache Check/Storage Flow
- Error Handling Paths
- Confirmation Workflow (when enabled)

##### Technical Implementation Details

Specific components based on the codebase:

a) Core Modules (from src/podgenai):
- Config Handler (config.py)
- Content Management (content/ directory)
- Prompt Management (prompts/ directory)
- Utility Services (util/ directory)

##### Integration Points

External service integrations:
- OpenAI API Integration
- FFmpeg Integration
- File System Integration

##### Component Relationships

Key relationships:
- Topic → Subtopics generation
- Content generation → TTS conversion
- Audio segment → Final concatenation
- Cache interaction points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph ExternalServices
        OpenAI[OpenAI GPT-4 API]:::external
        TTS[OpenAI TTS API]:::external
        FFmpeg[FFmpeg]:::external
    end

    subgraph CoreApplication
        Main["Main Application"]:::core
        click Main "https://github.com/impredicative/podgenai/blob/master/src/podgenai/podgenai.py"
        
        subgraph InputProcessing
            TopicHandler["Topic Handler"]:::input
            click TopicHandler "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/topic.py"
            ConfigMgr["Configuration Manager"]:::config
            click ConfigMgr "https://github.com/impredicative/podgenai/blob/master/src/podgenai/config.py"
            EnvHandler["Environment Variables"]:::config
            click EnvHandler "https://github.com/impredicative/podgenai/blob/master/src/podgenai/util/dotenv_.py"
            InputProc["Input Processor"]:::input
            click InputProc "https://github.com/impredicative/podgenai/blob/master/src/podgenai/util/input.py"
        end

        subgraph ContentGeneration
            SubtopicGen["Subtopic Generator"]:::content
            click SubtopicGen "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/subtopics.py"
            ContentGen["Content Generator"]:::content
            click ContentGen "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/topic.py"
            VoiceSelect["Voice Selector"]:::content
            click VoiceSelect "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/voice.py"
            TTSConvert["TTS Converter"]:::content
            click TTSConvert "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/tts.py"
        end

        subgraph AudioProcessing
            AudioMgr["Audio File Manager"]:::audio
            click AudioMgr "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/audio.py"
            AudioConcat["Audio Concatenation"]:::audio
            click AudioConcat "https://github.com/impredicative/podgenai/blob/master/src/podgenai/content/audio.py"
        end

        subgraph Storage
            Cache["Local Cache System"]:::storage
            click Cache "https://github.com/impredicative/podgenai/blob/master/src/podgenai/work.py"
            Prompts["Prompt Templates"]:::storage
            click Prompts "https://github.com/impredicative/podgenai/tree/master/src/podgenai/prompts/"
            TextProc["Text Processor"]:::util
            click TextProc "https://github.com/impredicative/podgenai/blob/master/src/podgenai/util/semantic_text_splitter.py"
        end

        OpenAIUtil["OpenAI Integration"]:::util
        click OpenAIUtil "https://github.com/impredicative/podgenai/blob/master/src/podgenai/util/openai.py"
    end

    %% Main Flow
    Main --> TopicHandler
    TopicHandler --> SubtopicGen
    SubtopicGen --> ContentGen
    ContentGen --> VoiceSelect
    VoiceSelect --> TTSConvert
    TTSConvert --> AudioMgr
    AudioMgr --> AudioConcat

    %% External Service Integration
    SubtopicGen -.-> OpenAIUtil
    ContentGen -.-> OpenAIUtil
    OpenAIUtil -.-> OpenAI
    TTSConvert -.-> TTS
    AudioConcat -.-> FFmpeg

    %% Support Flows
    ConfigMgr --> Main
    EnvHandler --> ConfigMgr
    InputProc --> TopicHandler
    Prompts -.-> ContentGen
    Prompts -.-> SubtopicGen
    Prompts -.-> VoiceSelect
    Cache -.-> ContentGen
    Cache -.-> TTSConvert
    TextProc -.-> ContentGen

    %% Styling
    classDef core fill:#2b5797,color:#fff
    classDef input fill:#00a300,color:#fff
    classDef content fill:#2d89ef,color:#fff
    classDef audio fill:#9f00a7,color:#fff
    classDef storage fill:#ffc40d,color:#000
    classDef config fill:#808080,color:#fff
    classDef external fill:#00aba9,color:#fff
    classDef util fill:#da532c,color:#fff

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Input Processing"]:::input
        L3["Content Generation"]:::content
        L4["Audio Processing"]:::audio
        L5["Storage"]:::storage
        L6["Configuration"]:::config
        L7["External Service"]:::external
        L8["Utility"]:::util
    end
```
