# mchiaramonte/mister-cdrdao architecture

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

- Interactive diagram: https://gitdiagram.com/mchiaramonte/mister-cdrdao
- Repository: https://github.com/mchiaramonte/mister-cdrdao

## Overview

##### Project type and purpose
- This is a CLI‐based packaging and deployment tool for MiSTer FPGA.
- Purpose: build a Linux cdrdao binary + package it with helper scripts and Redump data for easy deployment on MiSTer.

##### File structure
Top level
- .github/ – CI workflow definition and build helper.
- LICENSE, README.md – documentation and licensing.
- Scripts/ – all runtime scripts and configuration for MiSTer.
Under Scripts/
- .config/mister-cdrdao/ – Redump .dat files (MegaCD, PSX, etc.), binmerge, cdrdao stub, toc2cue, processcue.py.
- ripdisc.sh – the main entry script that runs on MiSTer.

##### README for insights
- Build flow: fetch cdrdao source, compile for Linux on MiSTer, bundle.
- Runtime flow: user adds entry in downloader.ini, runs update to pull .tar.gz onto MiSTer, then uses ripdisc.sh.
- Scripts chain: ripdisc.sh → cdrdao → binmerge/toc2cue → processcue.py → rename using .dat checksums.

##### Main components and their relationships
a. Components
1. GitHub Actions CI
2. Build Script (`.github/build-mister-cdrdao.sh`)
3. cdrdao source (external)
4. Helper binaries/scripts (`binmerge`, `toc2cue`, `processcue.py`)
5. Redump data files (`.dat` files)
6. Packager (creates .tar.gz)
7. MiSTer FPGA device
8. Downloader system on MiSTer (`downloader.ini` + update scripts)
9. ripdisc.sh (runtime entry)

b. Interactions & data flows
- CI pipeline triggers on push → runs build-mister-cdrdao.sh
- Build script clones cdrdao, compiles, then copies in helper scripts + .dat files
- Packager → .tar.gz artifact → published to GitHub releases (or raw URL)
- On MiSTer: downloader.ini points to artifact URL → user runs “update” → artifact downloaded & extracted
- ripdisc.sh invoked from MiSTer UI → calls cdrdao to rip disc, then helper tools process tracks → final BIN/CUE renamed

c. Architectural patterns
- Separation of build vs. runtime: CI builds/packaging in GitHub, target deployment on MiSTer
- Configuration-driven: `.config/mister-cdrdao/*.dat` guides runtime behavior & renaming
- CLI orchestration: shell and Python scripts chained for modularity

d. Key technologies
- GitHub Actions (YAML workflow)
- Bash scripts (`build-mister-cdrdao.sh`, `ripdisc.sh`)
- cdrdao (C library/tool)
- Python (processcue.py)
- Custom utilities (binmerge, toc2cue)
- MiSTer FPGA downloader interface

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI/Build Environment
    subgraph "CI/Build Environment"
        direction TB
        CI["GitHub Actions CI"]:::ci
        Build["Build Script"]:::ci
        CdrdaoSource["cdrdao Source (External)"]:::external
        subgraph "Helper Scripts & Binaries"
            direction TB
            binmerge_help["binmerge"]:::external
            toc2cue_help["toc2cue"]:::external
            processcue_help["processcue.py"]:::external
            cdrdao_stub_help["cdrdao stub"]:::external
        end
        subgraph "Redump Data Files"
            direction TB
            MegaCD_dat["MegaCD.dat"]:::external
            NeoGeo_dat["NeoGeo-CD.dat"]:::external
            PSX_dat["PSX.dat"]:::external
            Saturn_dat["Saturn.dat"]:::external
            TGFX16_dat["TGFX16-CD.dat"]:::external
        end
        Packager["Packager"]:::ci
        Artifact[".tar.gz Artifact"]:::ci
    end

    %% Runtime Environment
    subgraph "MiSTer Device (Runtime)"
        direction TB
        Downloader["Downloader (downloader.ini + update)"]:::runtime
        ripdisc["ripdisc.sh"]:::runtime
        CdrdaoRuntime["cdrdao Runtime Binary"]:::runtime
        binmerge_rt["binmerge"]:::runtime
        toc2cue_rt["toc2cue"]:::runtime
        processcue_rt["processcue.py"]:::runtime
        Output["Final BIN/CUE Files"]:::runtime
    end

    %% Build Flow
    CI -->|"trigger build"| Build
    Build -->|"clone & compile"| CdrdaoSource
    Build -->|"include scripts"| binmerge_help
    Build -->|"include scripts"| toc2cue_help
    Build -->|"include scripts"| processcue_help
    Build -->|"include scripts"| cdrdao_stub_help
    Build -->|"include data"| MegaCD_dat
    Build -->|"include data"| NeoGeo_dat
    Build -->|"include data"| PSX_dat
    Build -->|"include data"| Saturn_dat
    Build -->|"include data"| TGFX16_dat
    Build -->|"package"| Packager
    Packager -->|"produce"| Artifact

    %% Deployment & Runtime Flow
    Artifact -->|"HTTP GET .tar.gz"| Downloader
    Downloader -->|"extract"| ripdisc
    ripdisc -->|"executes"| CdrdaoRuntime
    CdrdaoRuntime -->|"rips tracks"| binmerge_rt
    binmerge_rt -->|"merges tracks"| toc2cue_rt
    toc2cue_rt -->|"generates cue"| processcue_rt
    processcue_rt -->|"rename using .dat"| Output

    %% Click Events
    click CI "https://github.com/mchiaramonte/mister-cdrdao/blob/main/.github/workflows/build_mister_cdrado.yml"
    click Build "https://github.com/mchiaramonte/mister-cdrdao/blob/main/.github/build-mister-cdrdao.sh"
    click binmerge_help "https://github.com/mchiaramonte/mister-cdrdao/tree/main/Scripts/.config/mister-cdrdao/binmerge"
    click toc2cue_help "https://github.com/mchiaramonte/mister-cdrdao/tree/main/Scripts/.config/mister-cdrdao/toc2cue"
    click processcue_help "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/processcue.py"
    click cdrdao_stub_help "https://github.com/mchiaramonte/mister-cdrdao/tree/main/Scripts/.config/mister-cdrdao/cdrdao"
    click MegaCD_dat "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/MegaCD.dat"
    click NeoGeo_dat "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/NeoGeo-CD.dat"
    click PSX_dat "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/PSX.dat"
    click Saturn_dat "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/Saturn.dat"
    click TGFX16_dat "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/.config/mister-cdrdao/TGFX16-CD.dat"
    click ripdisc "https://github.com/mchiaramonte/mister-cdrdao/blob/main/Scripts/ripdisc.sh"

    %% Styles
    classDef ci fill:#CCE5FF,stroke:#000,stroke-width:1px
    classDef runtime fill:#CCFFCC,stroke:#000,stroke-width:1px
    classDef external fill:#FFF5CC,stroke:#000,stroke-width:1px
```
