# chcolte/auto-video-compressor architecture

> Architecture diagram of the GitHub repository chcolte/auto-video-compressor, 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/chcolte/auto-video-compressor
- Repository: https://github.com/chcolte/auto-video-compressor

## Overview

- Service Manager (systemd): Represented by the auto_video_compressor.service file that manages the lifecycle of the script.
- Compression Script (autovideocompressor.sh): The core automation process that executes the compression logic.
- Directories:
- WATCH_DIR: The monitored input directory containing original videos.
- OUTPUT_DIR: The destination directory for compressed videos.
- PROCESSED_DIR: The directory where original files are moved after compression.
- External Dependency: ffmpeg – the tool used for actual video compression.
- Logging: A log component indicating where the process writes execution details (log_file.log).

##### Relationships and Data Flow
- systemd launches the script process using the auto_video_compressor.service when the daemon starts.
- The script continuously monitors WATCH_DIR for new videos.
- When a video is detected, the script calls ffmpeg (with FFMPEG_OPTIONS) to compress the video.
- The compressed video is output to OUTPUT_DIR.
- The original file is then moved to PROCESSED_DIR.
- Throughout this flow, the script logs its actions to the log file specified (LOG_FILE).
- Optionally, indicate the SLEEP_INTERVAL that determines how often the script checks the directory, representing a polling mechanism.

##### Architectural Patterns
- Daemon Pattern: The script runs continuously as a background service via systemd.
- Polling Mechanism: The script uses a sleep interval to repeatedly check the WATCH_DIR.
- Separation of Concerns: The system is modular with clear responsibilities—system management (systemd), file monitoring/processing (script), and external media processing (ffmpeg).

##### Incorporate Relevant Technologies
- systemd for process management.
- ffmpeg for media conversion.
- Bash scripting for automation and control.
- File system directories for organizing input, output, and processed videos.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["systemd Service – auto_video_compressor.service"]:::service
    B["Compression Script – autovideocompressor.sh"]:::script
    C["WATCH_DIR"]:::directory
    D["ffmpeg"]:::external
    E["OUTPUT_DIR"]:::directory
    F["PROCESSED_DIR"]:::directory
    G["Logging – log_file.log"]:::logging

    A -->|"starts"| B
    B -->|"monitors"| C
    B -->|"invokes"| D
    D -->|"returns result"| B
    B -->|"saves compressed"| E
    B -->|"moves original"| F
    B -->|"logs activity"| G

    click A "https://github.com/chcolte/auto-video-compressor/blob/main/auto_video_compressor.service"
    click B "https://github.com/chcolte/auto-video-compressor/blob/main/autovideocompressor.sh"
    click G "https://github.com/chcolte/auto-video-compressor/blob/main/log_file.log"

    classDef service fill:#f9d5d3,stroke:#333,stroke-width:2px;
    classDef script fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef directory fill:#d5f9d5,stroke:#333,stroke-width:2px;
    classDef external fill:#f9f3d3,stroke:#333,stroke-width:2px;
    classDef logging fill:#e2d9f3,stroke:#333,stroke-width:2px;
```
