# luongnv89/wav-shrink architecture

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

- Interactive diagram: https://gitdiagram.com/luongnv89/wav-shrink
- Repository: https://github.com/luongnv89/wav-shrink

## Overview

##### Main components
- User Interface (CLI) – Represented by the command-line entry-point in main.py, which parses arguments and dispatches conversion tasks.
- Conversion Engine – Encapsulated in waveshrink.py, where the actual logic for converting audio files is located.
- External Dependencies – Highlight libraries such as pydub (which is used for audio processing), and the external FFmpeg dependency that pydub relies on to perform the conversions.
- File System/Directory Handling – Since WaveShrink supports both single-file and batch directory conversions, this component shows the component handling file and directory I/O.

##### Relationships and interactions
- The user initiates the process via the CLI (main.py), supplying parameters (such as file path, directory, output format, bitrate, and whether to keep or delete original files).
- main.py validates the inputs and then invokes functions in waveshrink.py to perform the conversion.
- waveshrink.py interacts with pydub methods that, in turn, call upon FFmpeg installed on the system.
- After processing, the conversion results (new audio file) are output to the file system and the process status is relayed back to the CLI for user feedback.

##### Architectural patterns/design principles
- Modular Design: Separation between the CLI handler (main.py) and the audio conversion logic (waveshrink.py).
- External Dependency Abstraction: The reliance on pydub and FFmpeg is abstracted away from the core business logic.
- Simplicity and Clarity: The design emphasizes a straightforward pipeline from input parsing to processing to output.

##### Technologies and frameworks
- Python 3.7+ (core language)
- pydub (main audio library for processing)
- FFmpeg (external dependency required for audio processing)
- Optional: rich (for enhanced CLI feedback as indicated in the installation instructions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        U["User Input (CLI)"]:::system
        M["main.py (Entry Point)"]:::internal
    end

    %% Conversion Engine Layer
    subgraph "Conversion Engine Layer"
        W["waveshrink.py (Conversion Engine)"]:::internal
        D["Decision: File_or_Directory?"]:::internal
    end

    %% External Dependencies
    subgraph "External Dependencies"
        P["pydub Library"]:::external
        F["FFmpeg Dependency"]:::external
        R["requirements.txt"]:::external
    end

    %% System Interaction
    subgraph "System Interaction"
        FS["File System I/O"]:::fileSystem
    end

    %% Connections between components
    U -->|"initiates"| M
    M -->|"invokes_conversion"| W
    W -->|"calls"| P
    P -->|"utilizes"| F
    W -->|"handles_IO"| FS
    W -->|"determines_input"| D
    D -->|"if_directory_then_batch"| FS

    %% Click Events
    click M "https://github.com/luongnv89/wav-shrink/blob/main/main.py"
    click W "https://github.com/luongnv89/wav-shrink/blob/main/waveshrink.py"
    click R "https://github.com/luongnv89/wav-shrink/blob/main/requirements.txt"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef fileSystem fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef system fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
