ROM Farmer Build Orchestration System Analysis

Generated: December 6, 2025

Executive Summary

ROM Farmer is a sophisticated build orchestration system designed for processing ROM collections at scale. It provides a flexible, configuration-driven architecture that separates platform-specific concerns from build orchestration logic, enabling:


1. Architecture Overview

High-Level Architecture

The system is organized into four distinct layers: CLI, Orchestration, Configuration, and Processing.

flowchart TB subgraph CLI["CLI Layer"] cmd[romfarmer build run] end subgraph Orchestration["Build Orchestration Layer"] BO[BuildOrchestrator] PP[PlatformProcessor] end subgraph Config["Configuration Layer"] BC[BuildConfig] PC[PlatformConfig] OV[Override System] end subgraph Processing["Processing Layer"] PL[Pipeline] ST[Stages] CTX[StageContext] end subgraph Output["Output Layer"] OUT[Organized ROMs] META[Metadata/Gamelists] RPT[Build Reports] end cmd --> BO BO --> BC BO --> PP PP --> PC PC --> OV OV --> PC PP --> PL PL --> ST ST --> CTX CTX --> OUT CTX --> META BO --> RPT

Core Module Relationships

The class diagram below shows the relationships between the core components:

classDiagram class BuildOrchestrator { +config: BuildConfig +state: BuildState +run(resume: bool) +validate() bool +get_status() dict } class BuildConfig { +name: str +includes: List~str~ +excludes: List~str~ +platforms: List~str~ +platform_overrides: Dict +storage: Dict +settings: Dict } class PlatformProcessor { +platform_name: str +config: PlatformConfig +overrides: Dict +process() Dict } class PlatformConfig { +name: str +dat: DATConfig +sources: List~SourceConfig~ +extraction: ExtractionConfig +compression: CompressionConfig +selection: SelectionConfig +targets: List~TargetProfile~ } class Pipeline { +stages: List~Stage~ +add_stage(stage) +execute() List~StageResult~ } class Stage { +name: str +execute(context) StageResult } BuildOrchestrator --> BuildConfig BuildOrchestrator --> PlatformProcessor PlatformProcessor --> PlatformConfig PlatformProcessor --> Pipeline Pipeline --> Stage

2. Build Orchestration

BuildOrchestrator

The BuildOrchestrator is the central coordinator for multi-platform builds. It manages:

Build Execution Sequence
sequenceDiagram participant CLI as CLI participant BO as BuildOrchestrator participant BC as BuildConfig participant PP as PlatformProcessor participant PL as Pipeline participant ST as Stages CLI->>BO: run(build_name) BO->>BC: load_build_config() BC-->>BO: config with merged includes BO->>BO: validate() loop For each platform BO->>PP: process(platform) PP->>PP: load_platform_config() PP->>PP: apply_overrides() PP->>PL: create_pipeline() loop For each stage PL->>ST: execute(context) ST-->>PL: StageResult end PP-->>BO: platform_result BO->>BO: save_state() end BO->>BO: run_post_build_hooks() BO->>BO: generate_report() BO-->>CLI: complete

Build State & Resume

ROM Farmer persists build state to enable resumable builds:

# .build_state_{name}.yaml
build_name: "1tb-batocera-complete"
started_at: "2025-12-06T10:30:00"
completed_platforms:
  - nes
  - snes
  - gb
failed_platforms: []
current_platform: gbc
status: running
last_updated: "2025-12-06T11:45:32"

When --resume is passed, completed platforms are skipped automatically.


3. Configuration System

Configuration Hierarchy

ROM Farmer uses a two-level configuration system:

flowchart TB subgraph BuildLevel["Build Level (config/builds/)"] BC[BuildConfig YAML] BC --> INC[includes: list] BC --> EXC[excludes: list] BC --> PLAT[platforms: list] BC --> PO[platform_overrides: dict] BC --> STOR[storage: dict] BC --> SET[settings: dict] end subgraph PlatformLevel["Platform Level (config/platforms/)"] PC[PlatformConfig YAML] PC --> DAT[dat: DATConfig] PC --> SRC[sources: List] PC --> EXT[extraction: ExtractionConfig] PC --> CMP[compression: CompressionConfig] PC --> SEL[selection: SelectionConfig] PC --> TGT[targets: List TargetProfile] end BC -.->|references| PC PO -.->|overrides| PC

Nested Orchestration (includes)

Build configs can include other build configs, creating composable deployment profiles:

flowchart TB subgraph Master["1tb-batocera-complete.yaml"] M[Master Build] end subgraph Children["Included Orchestrations"] N[nointro-1g1r-eng-7z-batocera] R[redump-1g1r-eng-chd-batocera] D[nintendo-disc-1g1r-eng-rvz-batocera] end subgraph Platforms["Resolved Platforms - 37 total"] NP["NES, SNES, GB, GBC, GBA... 26 cartridge systems"] RP["PSX, PS2, Saturn, Dreamcast... 8 disc systems"] DP["GameCube, Wii, Wii U 3 Nintendo disc systems"] end M --> N M --> R M --> D N --> NP R --> RP D --> DP

Example Master Orchestration:

# 1tb-batocera-complete.yaml
name: 1tb-batocera-complete
description: "Complete 1TB Batocera build"

includes:
  - nointro-1g1r-eng-7z-batocera   # 26 cartridge platforms
  - redump-1g1r-eng-chd-batocera   # 8 disc platforms
  - nintendo-disc-1g1r-eng-rvz-batocera  # 3 platforms

excludes:
  - ps3  # Too large for 1TB

storage:
  temp_path: /path/to/...
  output_base: /path/to/...

Key Configuration Models

BuildConfig

Field Type Description
namestrBuild identifier
includesList[str]Other build configs to merge
excludesList[str]Platforms to remove after merge
platformsList[str]Additional platforms (after includes)
platform_overridesDictPer-platform overrides
storageDictPaths for temp/output
settingsDictExecution settings
post_buildListCommands to run after completion
deployDictRsync deployment config

PlatformConfig

Field Type Description
namestrPlatform identifier
datDATConfigDAT file source/path
sourcesList[SourceConfig]Where to find ROMs
extractionExtractionConfigHow to extract archives
compressionCompressionConfigOutput compression format
selectionSelectionConfigROM selection/filtering
targetsList[TargetProfile]Output targets (Batocera, RocknIX, etc.)

4. Override System

The override system is one of ROM Farmer's most powerful features. It allows build configs to modify platform configs without duplicating them.

Override Merge Semantics

flowchart LR subgraph PlatformYAML["Platform YAML - saturn.yaml"] P1[compression: chd] P2[selection: rating_budget] P3["targets: rocknix, batocera"] end subgraph BuildOverrides["Build Overrides"] O1[compression: 7z] O2["targets: batocera"] end subgraph Merged["Merged Config"] M1[compression: 7z] M2[selection: rating_budget] M3["targets: batocera"] end P1 --> M1 P2 --> M2 P3 --> M3 O1 -.->|overrides| M1 O2 -.->|overrides| M3

Override Types

Field Type Merge Behavior
Simple (enabled, name)Direct replacement
Nested objects (dat, compression)Deep merge (field-level)
Lists (targets, sources)Replace or filter
None valuesExplicitly disable/clear

YAML Anchor Patterns

ROM Farmer uses YAML anchors for DRY configuration:

platform_overrides:
  nes: &standard_override
    targets:
      - name: batocera
        organization: flat
    compression:
      format: 7z
  
  snes: *standard_override
  gb: *standard_override
  gbc: *standard_override
  gba: *standard_override
  # ... applies same override to all

Override Application Flow

flowchart TB subgraph Input PC[PlatformConfig YAML] BO[Build platform_overrides] SC[storage_config] end subgraph Processing["apply_overrides()"] direction TB S1[Parse simple fields] S2[Merge DAT config] S3[Merge compression config] S4[Merge extraction config] S5[Merge selection config] S6[Process targets override] S7[Apply storage paths] end subgraph Output MC[Merged PlatformConfig] end PC --> S1 BO --> S1 S1 --> S2 --> S3 --> S4 --> S5 --> S6 SC --> S6 S6 --> S7 --> MC

Override Examples

Example 1: Change compression format

platform_overrides:
  saturn:
    compression:
      format: 7z  # Override CHD to 7z

Example 2: Filter to single target

platform_overrides:
  saturn:
    targets:
      - batocera  # Only output to Batocera, not RocknIX

Example 3: Test mode with random sampling

platform_overrides:
  saturn:
    selection:
      strategy: random
      limit: 10
      seed: 42

Example 4: Disable extraction (passthrough)

platform_overrides:
  saturn:
    extraction:
      enabled: false
    compression:
      format: none

5. Stage Pipeline

Pipeline Architecture

The Pipeline orchestrates sequential stage execution with shared context:

flowchart LR subgraph Input SRC[Source ROMs] DAT[DAT File] end subgraph Pipeline["Stage Pipeline"] S1[FilterDATStage] S2[Filter1G1RStage] S3[SelectionFilter] S4[ApplyListsStage] S5[ExtractArchiveStage] S6[CompressCHDStage] S7[CreateM3UStage] S8[OrganizeStage] S9[GenerateMetadataStage] end subgraph Output OUT[Organized ROMs] META[gamelist.xml] end SRC --> S1 DAT --> S1 S1 --> S2 --> S3 --> S4 --> S5 --> S6 --> S7 --> S8 --> S9 S9 --> OUT S9 --> META

Available Stages

Stage Purpose When Used
FilterDATStageMatch files against DATAlways
Filter1G1RStageApply 1G1R filteringAlways
SelectionFilterApply selection criteriaWhen selection configured
ApplyListsStageApply include/exclude listsWhen lists configured
ExtractArchiveStageExtract ZIP archivesCartridge/Disc extraction
ExtractPS3StageDecrypt PS3 ISOsPS3 extraction
UnzipRVZStageExtract RVZ archivesWii/GameCube
ConvertXISOStageConvert to XISO formatXbox/Xbox 360
CompressCHDStageCompress to CHDDisc systems
CompressArchiveStageCompress to 7z/ZIPCartridge systems
CompressSquashfsStageCompress to SquashfsXbox (optional)
CreateM3UStageCreate M3U playlistsMulti-disc games
OrganizeStageOrganize output filesAlways
GenerateMetadataStageCreate gamelist.xmlAlways

Stage Context Flow

flowchart TB subgraph Context["StageContext - shared state"] direction TB C1["platform_config"] C2["source_files: List Path"] C3["matched_files: List Path"] C4["filtered_files: List Path"] C5["extracted_files: List Path"] C6["compressed_files: List Path"] C7["organized_files: Dict"] C8["stats: Dict"] end subgraph Stages S1[FilterDAT] -->|updates matched_files| S2[Filter1G1R] S2 -->|updates filtered_files| S3[Selection] S3 -->|updates filtered_files| S4[Extract] S4 -->|updates extracted_files| S5[Compress] S5 -->|updates compressed_files| S6[Organize] S6 -->|updates organized_files| S7[Metadata] end Context -.-> S1

Dynamic Stage Routing

The PlatformProcessor dynamically builds the pipeline based on configuration:

flowchart TB subgraph Config EXT["extraction.type"] CMP["compression.format"] end subgraph Routing["Stage Routing Logic"] EXT --> |CARTRIDGE| R1["ExtractArchive → CompressArchive"] EXT --> |DISC| R2["ExtractArchive → CompressCHD → CreateM3U"] EXT --> |RVZ| R3["UnzipRVZ"] EXT --> |PS3| R4["ExtractPS3"] EXT --> |XISO| R5["ExtractArchive → ConvertXISO → CompressSquashfs?"] end subgraph Always A1[FilterDAT] A2[Filter1G1R] A3[ApplyLists] A4[Organize] A5[GenerateMetadata] end

6. CLI Interface

Build Commands

# Run a complete build
romfarmer build run 1tb-batocera-complete

# Run specific platforms only
romfarmer build run 1tb-batocera-complete --platforms saturn,dreamcast

# Resume interrupted build
romfarmer build run 1tb-batocera-complete --resume

# Validate without running
romfarmer build run 1tb-batocera-complete --validate-only

# Test mode: random sample
romfarmer build run 1tb-batocera-complete --test-sample 10 --seed 42

# Fast test: skip processing, copy originals
romfarmer build run 1tb-batocera-complete --test-sample 10 --passthrough

# Check build status
romfarmer build status 1tb-batocera-complete --verbose

# List available builds
romfarmer build list

CLI Options Impact on Overrides

flowchart LR subgraph CLIOptions["CLI Options"] TS[--test-sample N] SEED[--seed N] PT[--passthrough] PLAT[--platforms x,y,z] end subgraph RuntimeOverrides["Injected Overrides"] TS --> SEL["selection: strategy: random limit: N seed: N"] PT --> EXT["extraction: enabled: false compression: format: none"] PLAT --> PL["platforms: x,y,z"] end subgraph Effect["Effective Config"] MC[Merged Config] end SEL --> MC EXT --> MC PL --> MC

7. Practical Examples

Example 1: Simple Cartridge Build

# config/builds/nes-batocera.yaml
name: nes-batocera
platforms:
  - nes

platform_overrides:
  nes:
    targets:
      - name: batocera
        organization: flat
    compression:
      format: 7z

What happens:

  1. Load config/platforms/nes.yaml
  2. Apply overrides (7z compression, batocera target only)
  3. Pipeline: FilterDAT → Filter1G1R → ApplyLists → Extract → Compress7z → Organize → Metadata

Example 2: Disc System with Budget

# config/builds/saturn-40gb.yaml
name: saturn-40gb
platforms:
  - saturn

platform_overrides:
  saturn:
    selection:
      strategy: rating_budget
      max_size_gb: 40.0
    targets:
      - name: batocera

What happens:

  1. Load config/platforms/saturn.yaml
  2. Apply selection filter (top-rated games fitting in 40GB)
  3. Pipeline: FilterDAT → Filter1G1R → SelectionFilter → ApplyLists → Extract → CompressCHD → CreateM3U → Organize → Metadata

Example 3: Nested Device Build

# config/builds/512gb-portable.yaml
name: 512gb-portable
includes:
  - nointro-1g1r-eng-7z-batocera

excludes:
  - 3ds    # Too demanding
  - n64    # Controller issues
  - nds    # Touch screen

storage:
  output_base: /mnt/sdcard/roms

What happens:

  1. Load nointro-1g1r-eng-7z-batocera (26 platforms)
  2. Remove excluded platforms (3)
  3. Process remaining 23 platforms with inherited settings

Example 4: Full Production Build

# config/builds/1tb-batocera-complete.yaml
name: 1tb-batocera-complete

includes:
  - nointro-1g1r-eng-7z-batocera
  - redump-1g1r-eng-chd-batocera
  - nintendo-disc-1g1r-eng-rvz-batocera

settings:
  parallel: false
  stop_on_error: false
  cleanup_temp: true

storage:
  temp_path: /path/to/...
  output_base: /path/to/...

post_build:
  - name: "Deduplicate with jdupes"
    command: "jdupes -r -L {output_base}"
    enabled: true

deploy:
  target: "batocera@192.168.1.100:/userdata/roms"
  rsync_options: "-avH --progress"
  delete_extra: false

Build flow:

flowchart TB subgraph Load["1. Load and Merge"] M[Master Config] I1[nointro-1g1r-eng-7z] I2[redump-1g1r-eng-chd] I3[nintendo-disc-rvz] M --> I1 & I2 & I3 end subgraph Process["2. Process 37 Platforms"] P1["NES → Organize"] P2["SNES → Organize"] P3["..."] P4["Saturn → CHD → Organize"] P5["Wii → RVZ → Organize"] end subgraph PostBuild["3. Post-Build"] D[jdupes -r -L] R[Generate Report] end subgraph Deploy["4. Deploy - optional"] RS[rsync to device] end Load --> Process --> PostBuild --> Deploy

Summary

ROM Farmer's build orchestration system provides:

Capability Implementation
ComposabilityNested includes with merge semantics
FlexibilityDeep override system at build/platform/target levels
ReliabilityState persistence, resume, validation
ExtensibilityPluggable stage pipeline
EfficiencyTest modes, passthrough, parallel processing
AutomationPost-build hooks, deployment integration

The separation of concerns between build orchestration, platform configuration, and processing stages enables ROM Farmer to scale from simple single-platform builds to complex multi-terabyte production deployments.