# rafael1mc/epub-tts architecture

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

- Interactive diagram: https://gitdiagram.com/rafael1mc/epub-tts
- Repository: https://github.com/rafael1mc/epub-tts

## Overview

##### Main Components

a. Input Layer:
- Input ePub file in the volume/input.epub directory

b. Core Processing Components (arrange these in a pipeline flow):
1. ePub Parser Component (from internal/book)
- Epub.go and epub-parser.go as the main processing units
- Represents the initial file processing and content extraction

2. Text Processing Component (from internal/book)
- Text-book.go as the intermediate processing unit
- Handles the conversion of ePub content into processable text sections

3. TTS Engine Interface (from internal/tts)
- Tts.go connecting to external MacOS 'say' command
- Represents the text-to-speech conversion process

c. Support Components (show these as utility modules):
- File Handler (internal/file)
- String Utilities (internal/str)
- Debug Tools (internal/debug)
- Constants (internal/consts)

##### Flow and Relationships

**[Input ePub] → [ePub Parser] → [Text Processor] → [TTS Engine] → [Audio Output Files]**
- ↑             ↑               ↑                   ↑
- [Utility Modules]──────────┘

##### Important Elements to Highlight

a. Worker Pool System:
- Parallel processing capabilities
- Batch conversion flow

b. External Dependencies:
- FFmpeg integration
- MacOS 'say' command
- As external service dependencies

##### Technical Details

- Input Format: ePub files
- Output Format: Audio files (with numerical prefixes)
- System Requirements: MacOS, FFmpeg, Go runtime
- File Organization: Show how output files are created and organized

##### Specific Implementation Notes

- Worker pool architecture for parallel processing
- Where file size optimization occurs
- Chapter extraction process
- Where language processing happens

Remember to:
- System boundaries
- External system dependencies
- Where future expansions (like Web UI) would fit
- Points where performance optimizations occur

This design should emphasize the pipeline nature of the processing while showing how the various internal packages work together to achieve the conversion from ePub to audio files.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        input[("Input ePub")]
    end
    
    subgraph "Core Processing"
        direction TB
        parser["ePub Parser"]:::core
        textproc["Text Processor"]:::core
        tts["TTS Engine"]:::core
        
        parser --> textproc
        textproc --> tts
    end
    
    subgraph "External Dependencies"
        ffmpeg["FFmpeg"]:::external
        say["MacOS 'say'"]:::external
    end
    
    subgraph "Utility Modules"
        direction TB
        file["File Handler"]:::utility
        str["String Utilities"]:::utility
        debug["Debug Tools"]:::utility
        consts["Constants"]:::utility
    end
    
    subgraph Output
        audio[("Audio Files")]:::output
    end
    
    input --> parser
    tts --> audio
    tts --> ffmpeg
    tts --> say
    
    file --> parser
    file --> textproc
    file --> tts
    str --> parser
    str --> textproc
    debug --> parser
    debug --> textproc
    debug --> tts
    consts --> parser
    consts --> textproc
    consts --> tts
    
    classDef core fill:#2374ab
    classDef external fill:#ffd700
    classDef utility fill:#808080
    classDef output fill:#2ecc71
    
    %% Click events for component mapping
    click input "https://github.com/rafael1mc/epub-tts/blob/main/volume/input.epub"
    click parser "https://github.com/rafael1mc/epub-tts/blob/main/internal/book/epub-parser.go"
    click textproc "https://github.com/rafael1mc/epub-tts/blob/main/internal/book/text-book.go"
    click tts "https://github.com/rafael1mc/epub-tts/blob/main/internal/tts/tts.go"
    click file "https://github.com/rafael1mc/epub-tts/blob/main/internal/file/file.go"
    click str "https://github.com/rafael1mc/epub-tts/blob/main/internal/str/str.go"
    click debug "https://github.com/rafael1mc/epub-tts/blob/main/internal/debug/debug.go"
    click consts "https://github.com/rafael1mc/epub-tts/blob/main/internal/consts/consts.go"
    
    %% Legend
    subgraph Legend
        direction TB
        l1["Core Components"]:::core
        l2["External Dependencies"]:::external
        l3["Utility Modules"]:::utility
        l4["Input/Output"]:::output
    end
```
