# jpistone/notwhatisaid architecture

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

- Interactive diagram: https://gitdiagram.com/jpistone/notwhatisaid
- Repository: https://github.com/jpistone/notwhatisaid

## Overview

- Downloads a YouTube video via a user-provided URL (using pytube).
- Processes the video’s audio with OpenAI’s Whisper (via whisper-timestamped) to generate a word-level timestamped transcript.
- Serves a web interface—built using Flask for the backend and HTML/CSS/JavaScript (with responsive design) for the frontend—that displays the video alongside a synchronized, interactive transcript.

##### And Label Main Components
- Frontend Client:
- Web Browser/User Interface displaying the video and transcript.
- Static assets: HTML templates (found in yt_whisper_sync/templates), CSS, and JavaScript files (in yt_whisper_sync/static/js and /css).
- Backend Server:
- The Flask Application (mainly defined in yt_whisper_sync/app.py, __main__.py, and run.py). This component handles HTTP requests, routing, and rendering views.
- API Endpoints that accept the YouTube URL, trigger video downloading, and respond back with the transcript data.
- Video & Audio Processing Module:
- The YouTube downloader that uses pytube to fetch video and audio.
- The transcription service that leverages whisper-timestamped to generate synchronized timestamps.
- A module (possibly encapsulated in yt_whisper_sync/benchmark.py or setup code in run.py) for processing benchmarks, emphasizing performance metrics.
- External Dependencies:
- FFmpeg (installed on the host machine, as noted in the README, which is essential for audio extraction/processing).
- Dev/Deployment Tools:
- Docker configuration files (inside .devcontainer), which indicate that developers can use a containerized environment to run the project.
- Setup and requirements files (setup.py and requirements.txt) ensure reproducibility.

##### Interactions and Data Flow
- Flask Backend splitting the work:
- One branch sends the URL to the “YouTube Downloader” component (and then funnels the video/audio into processing).
- Another branch handles rendering the web page (delivering the HTML/CSS/JS assets).
- The “YouTube Downloader” uses pytube to fetch the video and downloads it to the server’s file system (note: the README mentions that uploads and processed videos are stored in a designated static folder).
- The “Transcription Service” (using whisper-timestamped and FFmpeg for audio extraction) then processes the downloaded video’s audio, generating a transcript with word-level timestamps.
- The generated transcript is then sent back to the Flask backend which renders it on the client side. JavaScript in the frontend synchronizes the transcript highlighting with the video’s playback.

##### Architectural Patterns, Technologies, and Design Principles
- Modular Python Design: The project is organized as a Python module (yt_whisper_sync) with clearly separated responsibilities (video processing, benchmarking, and serving views). This modularity is crucial and should be emphasized.
- MVC-like Separation: Although not strictly MVC, the separation between "views" (HTML templates), "controller logic" (Flask routes in app.py) and "data/service" layers (download and transcription processing) is a central architectural idea.
- External Service Integration: Note the use of external libraries (pytube, whisper-timestamped) and external tools (FFmpeg).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend Layer"
        A("User Browser"):::frontend
        B("HTML Templates"):::frontend
        C("CSS & JS Assets"):::frontend
    end

    subgraph "Backend Layer"
        D("Flask Web Server"):::backend
        E("YouTube Downloader & Audio Extractor (pytube, FFmpeg)"):::backend
        F("Transcription Module (whisper-timestamped)"):::processing
    end

    subgraph "Dev/Deployment Tools"
        G("Docker & Setup"):::dev
    end

    %% Data Flow
    A -->|"Submit_YouTube_URL"| D
    D -->|"Serve_Assets"| B
    D -->|"Serve_Assets"| C
    D -->|"Trigger_Download"| E
    E -->|"Provide_Video/Audio_Data"| F
    F -->|"Return_Transcript_Data"| D
    D -->|"Render_Synced_Transcript"| A

    %% Click Events for Frontend Client
    click B "https://github.com/jpistone/notwhatisaid/tree/master/yt_whisper_sync/templates"
    click C "https://github.com/jpistone/notwhatisaid/tree/master/yt_whisper_sync/static/css"
    click C "https://github.com/jpistone/notwhatisaid/tree/master/yt_whisper_sync/static/js"

    %% Click Events for Backend Server
    click D "https://github.com/jpistone/notwhatisaid/blob/master/yt_whisper_sync/app.py"
    click D "https://github.com/jpistone/notwhatisaid/blob/master/yt_whisper_sync/__main__.py"
    click D "https://github.com/jpistone/notwhatisaid/blob/master/run.py"
    
    %% Click Event for Video & Audio Processing Module
    click F "https://github.com/jpistone/notwhatisaid/blob/master/yt_whisper_sync/benchmark.py"

    %% Click Events for Dev/Deployment Tools
    click G "https://github.com/jpistone/notwhatisaid/blob/master/.devcontainer"
    click G "https://github.com/jpistone/notwhatisaid/blob/master/setup.py"
    click G "https://github.com/jpistone/notwhatisaid/blob/master/requirements.txt"

    %% Styles
    classDef frontend fill:#f9f9a1,stroke:#333,stroke-width:2px;
    classDef backend fill:#a1d1f9,stroke:#333,stroke-width:2px;
    classDef processing fill:#a1f9a1,stroke:#333,stroke-width:2px;
    classDef dev fill:#f9d1a1,stroke:#333,stroke-width:2px;
```
