# jeanjerome/echoinstone architecture

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

- Interactive diagram: https://gitdiagram.com/jeanjerome/echoinstone
- Repository: https://github.com/jeanjerome/echoinstone

## Overview

##### Project Type and Purpose
- **Type**: An open-source, CLI-driven audio processing pipeline.
- **Purpose**: Download audio from various sources, transcribe it with Whisper, diarize speakers with Pyannote, align text to audio, and persist the results.

##### File Structure
- **Top-level Modules**:
- `EchoInStone/capture/` – downloader implementations (YouTube, podcast, generic audio).
- `EchoInStone/processing/` – orchestrator and processing interfaces (transcriber, diarizer, aligner).
- `EchoInStone/utils/` – logging, timing, and data persistence.
- `main.py` – CLI entry point.
- `config.py` – holds Hugging Face token, model names, and global settings.
- **Testing**:
- `tests/` (unit tests) and `features/` (BDD scenarios) ensure downloader logic, orchestrator flows, and edge-case handling.
- **Build & Config**:
- `pyproject.toml`, `requirements.txt`, `pytest.ini`.

##### Extract Key Architecture Insights from the README
- **Pipeline**: A flexible, orchestrated sequence—download → transcribe → diarize → align → save.
- **Interfaces**: Abstract base classes allow swapping or extending downloaders and processors.
- **External Dependencies**:
- ffmpeg (audio handling)
- Hugging Face APIs (`openai/whisper-large-v3-turbo`, `pyannote/speaker-diarization-3.1`)

##### Main Components & Their Interactions
a. **Downloader Layer** (`capture/`):
- **DownloaderFactory** selects between `YouTubeDownloader`, `PodcastDownloader`, or `AudioDownloader`.
- Each downloader fetches raw audio, writes to local storage.
b. **Processing Layer** (`processing/`):
- **AudioProcessingOrchestrator**:
- Invokes `WhisperAudioTranscriber` → produces timestamped transcript.
- Invokes `PyannoteDiarizer` → produces speaker turn segments.
- Invokes `SpeakerAligner` → merges transcript and segments into a unified output.
c. **Persistence & Utilities** (`utils/`):
- **DataSaver** writes JSON outputs.
- **LoggingConfig** sets up console/file logging.
- **Timer** measures processing durations.
d. **CLI / Entry Point**:
- `main.py` parses arguments (URL, output directory, file names), loads `config.py`, and kicks off the orchestrator.

##### Architectural Patterns & Design Principles
- **Modular Pipeline**: each step (download, transcribe, diarize, align, save) is decoupled via interfaces.
- **Factory Pattern**: `DownloaderFactory` selects the correct downloader at runtime.
- **Dependency Injection**: components rely on interfaces (`downloader_interface`, `aligner_interface`, etc.), easing testability and extensibility.
- **Separation of Concerns**: download logic, processing logic, and utility logic reside in distinct modules.

##### Putting It All Together – High-Level View
[ Input URL ]
↓
[ DownloaderFactory ] → selects → [ YouTubeDownloader / PodcastDownloader / AudioDownloader ]
↓  (raw .wav)
[ AudioProcessingOrchestrator ]
├─> [ WhisperAudioTranscriber ] → (text + timestamps)
├─> [ PyannoteDiarizer ] → (speaker time segments)
└─> [ SpeakerAligner ] → (merged speaker-aligned transcript)
↓
[ DataSaver ] → writes JSON to results directory
↓
Logs & Metrics (via LoggingConfig & Timer)

##### Detail, Not Complexity
- Every interface and factory choice.
- External dependencies and where they’re invoked.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Inputs
    URL["Input URL"]:::external
    CLI["CLI Entry Point\n(main.py)"]:::external
    CFG["Configuration\n(config.py)"]:::config

    %% Capture Layer
    subgraph "Capture Layer"
        DI["DownloaderInterface"]:::capture
        DF["DownloaderFactory"]:::capture
        YTD["YouTubeDownloader"]:::capture
        PDL["PodcastDownloader"]:::capture
        AD["AudioDownloader"]:::capture
    end

    %% Processing Layer
    subgraph "Processing Layer"
        ATI["AudioTranscriberInterface"]:::processing
        DI2["DiarizerInterface"]:::processing
        AI["AlignerInterface"]:::processing
        APO["AudioProcessingOrchestrator"]:::processing
        WAT["WhisperAudioTranscriber"]:::processing
        PDZ["PyannoteDiarizer"]:::processing
        SAL["SpeakerAligner"]:::processing
    end

    %% Utilities
    subgraph "Utilities"
        DS["DataSaver"]:::utils
        LC["LoggingConfig"]:::utils
        TM["Timer"]:::utils
    end

    %% External Dependencies
    subgraph "External Dependencies"
        YTAPI["YouTube API"]:::external
        RSS["RSS Feed"]:::external
        FF["ffmpeg"]:::external
        HF["Hugging Face API"]:::external
    end

    %% Results
    RES["Results JSON\n(Results Directory)"]:::external

    %% Flow
    CLI -->|parses args| URL
    CLI -->|loads config| CFG
    URL --> DF
    CFG --> WAT
    CFG --> PDZ
    CFG --> SAL

    DF --> DI
    YTD --> DI
    PDL --> DI
    AD --> DI

    DF --> YTD
    DF --> PDL
    DF --> AD

    YTD -->|raw .wav| APO
    PDL -->|raw .wav| APO
    AD -->|raw .wav| APO

    APO --> ATI
    APO --> DI2
    APO --> AI

    ATI --> WAT
    DI2 --> PDZ
    AI --> SAL

    WAT -->|audio + text| HF
    WAT -->|audio processing| FF
    PDZ -->|speaker segments| HF
    SAL -->|aligned transcript| DS

    SAL --> DS
    DS --> RES

    APO --> LC
    APO --> TM

    %% Click Events
    click DF "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/capture/downloader_factory.py"
    click YTD "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/capture/youtube_downloader.py"
    click PDL "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/capture/podcast_downloader.py"
    click AD "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/capture/audio_downloader.py"
    click DI "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/capture/downloader_interface.py"
    click APO "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/audio_processing_orchestrator.py"
    click WAT "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/whisper_audio_transcriber.py"
    click PDZ "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/pyannote_diarizer.py"
    click SAL "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/speaker_aligner.py"
    click ATI "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/audio_transcriber_interface.py"
    click DI2 "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/diarizer_interface.py"
    click AI "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/processing/aligner_interface.py"
    click DS "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/utils/data_saver.py"
    click LC "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/utils/logging_config.py"
    click TM "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/utils/timer.py"
    click CLI "https://github.com/jeanjerome/echoinstone/blob/main/main.py"
    click CFG "https://github.com/jeanjerome/echoinstone/blob/main/EchoInStone/config.py"

    %% Styles
    classDef capture fill:#CCE5FF,stroke:#1E90FF,color:#000;
    classDef processing fill:#CCFFCC,stroke:#28A745,color:#000;
    classDef utils fill:#FFE5CC,stroke:#FF8C00,color:#000;
    classDef external fill:#EEEEEE,stroke:#666,color:#000,stroke-dasharray: 5 5;
    classDef config fill:#F0F0F0,stroke:#999,color:#000;
```
