# epakai/hbr architecture

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

- Interactive diagram: https://gitdiagram.com/epakai/hbr
- Repository: https://github.com/epakai/hbr

## Overview

##### Main Components

a) Core Components:
- HBR Main Program
- HBR-Gen Program
- Configuration Manager
- Command Generator
- Validation System
- File System Interface

b) External Dependencies:
- HandBrakeCLI
- ffmpegthumbnailer (optional)
- GLib2.0

**Top Layer: User Interface**
**Middle Layer: Core Processing**
**Bottom Layer: External Systems**

##### Component Relationships

a) Input Flow:
- User → HBR/HBR-Gen (CLI Interface)
- Keyfiles → Configuration Manager
- Global Config → Configuration Manager

b) Processing Flow:
- Configuration Manager → Validation System
- Validation System → Command Generator
- Command Generator → HandBrakeCLI Executor

c) Output Flow:
- HandBrakeCLI Executor → Output Files
- HandBrakeCLI Executor → Log Files
- Preview Generator → Thumbnail Files (when enabled)

##### Detailed Component Descriptions

a) HBR Main Program:
- Entry point for encoding operations
- Handles keyfile processing
- Manages HandBrakeCLI execution

b) HBR-Gen Program:
- Template generator for keyfiles
- Supports episode list processing
- Handles automatic section generation

c) Configuration Manager:
- Processes global config ($XDG_CONFIG_HOME/hbr/hbr.conf)
- Handles keyfile parsing
- Manages configuration inheritance

d) Validation System:
- Validates boolean parameters
- Checks file paths and permissions
- Verifies media type configurations
- Ensures proper filename components

e) Command Generator:
- Constructs HandBrakeCLI commands
- Handles parameter override logic
- Manages output filename generation

##### Notes Section

Notes about:
- Configuration precedence
- Supported HandBrake versions (based on options-*.h files)
- File naming conventions
- Error handling paths

Remember to include version compatibility handling, as indicated by the multiple options-*.h files in the source tree, showing how the system adapts to different HandBrake versions.

## Diagram (Mermaid)

```mermaid
graph LR
    %% Styles
    classDef process fill:#e8f5e9,stroke:#2e7d32
    classDef storage fill:#f3e5f5,stroke:#7b1fa2
    classDef external fill:#fff3e0,stroke:#ff6f00

    %% Main Process Flow
    DVD((DVD/Blu-ray)):::storage
    MakeMKV[MakeMKV]:::process
    RawMKV[(Raw MKV File)]:::storage
    HBR[HandBrake Runner]:::process
    HandBrake{{HandBrakeCLI}}:::external
    Output[(Encoded Video)]:::storage
    Config[(HBR Config)]:::storage

    %% Flow
    DVD --> MakeMKV
    MakeMKV --> RawMKV
    RawMKV --> HBR
    Config --> HBR
    HBR --> HandBrake
    HandBrake --> Output

    %% Click Events
    click HBR "https://github.com/epakai/hbr/blob/master/src/hbr.c"
    click HandBrake "https://handbrake.fr/"
    click Config "https://github.com/epakai/hbr/blob/master/src/keyfile.c"
```
