🏗️ ROM Farmer Configuration Architecture
Comprehensive analysis of the layered configuration system and proposed enhancements
📋 Executive Summary
ROM Farmer uses a layered configuration architecture that separates concerns across multiple levels. This document analyzes the current architecture, identifies gaps, and proposes enhancements to support target-specific capabilities.
Key Insight: Targets currently have no identity. They exist only as names with output paths. The system cannot answer questions like "Does RocknIX support PDF manuals?" or "What folder name does RocknIX use for Sega CD?"
🏛️ Current Architecture
Configuration Layers Overview
ROM Farmer currently has 7 distinct configuration layers:
graph TB
subgraph "Layer 1: BUILD"
B[1tb-batocera-complete.yaml
rocknix-512gb.yaml]
end
subgraph "Layer 2: PLATFORM"
P[saturn.yaml
ps3.yaml
nes.yaml]
end
subgraph "Layer 3-4"
SEL[Selection Layer
rating-budget-40gb.yaml]
SRC[Sources Layer
sources.yaml]
end
subgraph "Layer 5: LISTS"
L[saturn-delete
saturn+Best-Games]
end
subgraph "Layer 6: DAT PATTERNS"
D[dat_patterns.yaml]
end
subgraph "Layer 7: TARGET (Inline)"
T[Embedded in
platform configs]
end
B --> P
P --> SEL
P --> SRC
P --> L
P --> D
P --> T
style B fill:#3b82f6,stroke:#1d4ed8,color:#fff
style P fill:#10b981,stroke:#047857,color:#fff
style SEL fill:#f59e0b,stroke:#b45309,color:#fff
style SRC fill:#f59e0b,stroke:#b45309,color:#fff
style L fill:#8b5cf6,stroke:#6d28d9,color:#fff
style D fill:#6366f1,stroke:#4338ca,color:#fff
style T fill:#ef4444,stroke:#b91c1c,color:#fff
📚 Layer Details
BUILD Build Layer
Location: config/builds/
Purpose: Top-level orchestration
Count: 44 build configs
Responsibilities:
- Aggregate sub-builds via
includes
- Exclude platforms via
excludes
- Override platform settings
- Define storage paths
- Post-build hooks
PLATFORM Platform Layer
Location: config/platforms/
Purpose: Per-platform processing
Count: 49 platform configs
Responsibilities:
- DAT file configuration
- Source ROM locations
- Extraction settings
- Compression format
- Multi-disc handling
- Target definitions (inline)
SELECTION Selection Layer
Location: config/selections/
Purpose: Reusable filtering criteria
Count: 6 selection configs
Responsibilities:
- Selection strategy
- Size limits
- Rating thresholds
- Pattern matching
TARGET Target Layer (Inline)
Location: Embedded in platform configs
Purpose: Output configuration
Current (Limited):
- Output path
- Organization style
- Metadata toggle
⚠️ Missing: Media support, compression support, platform support, folder mapping
Additional Layers
| Layer |
Location |
Purpose |
Example |
| Sources |
config/sources.yaml |
Registry of source root paths |
myrient_nointro, myrient_redump |
| Lists |
/path/to/... |
Human-curated game lists |
saturn-delete, saturn+Best-Games |
| DAT Patterns |
config/dat_patterns.yaml |
Platform to DAT name mapping |
saturn: "sega - saturn" |
🔄 Data Flow
sequenceDiagram
participant User
participant Build as Build Layer
participant Platform as Platform Layer
participant Selection as Selection Layer
participant Lists as Lists Layer
participant Target as Target (Inline)
participant Output
User->>Build: romfarmer build run 1tb-batocera-complete
Build->>Build: Resolve includes/excludes
Build->>Platform: Load platform configs
loop For each platform
Platform->>Selection: Apply selection filters
Platform->>Lists: Apply list files
Platform->>Target: Get output config
Target->>Output: Organize & generate metadata
end
Output-->>User: Build complete
Build Resolution Flow
flowchart TD
A[1tb-batocera-complete] --> B{Resolve Includes}
B --> C[nointro-1g1r-eng-7z-batocera
26 platforms]
B --> D[redump-1g1r-eng-chd-batocera
8 platforms]
B --> E[nintendo-disc-1g1r-eng-rvz-batocera
3 platforms]
C --> F{Apply Excludes}
D --> F
E --> F
F --> G[Excluded: 3ds]
F --> H[37 unique platforms
to process]
style A fill:#3b82f6,stroke:#1d4ed8,color:#fff
style H fill:#10b981,stroke:#047857,color:#fff
style G fill:#ef4444,stroke:#b91c1c,color:#fff
⚠️ Current Limitations
Problem 1: Target Capabilities Unknown
The system has no way to know what a target can or cannot do.
// Current: Hardcoded check buried in metadata.py
if context.target_name == 'rocknix' and media_type == 'manual':
continue // Skip manuals for RocknIX
Issues: Hardcoded logic scattered throughout codebase. Adding new targets requires code changes.
Problem 2: Platform-Target Constraints Missing
The system can't prevent impossible combinations.
// This will fail at runtime, not at config validation:
platforms:
- ps3
targets:
- name: rocknix // RocknIX can't emulate PS3!
Issues: No early validation. Wasted processing time. Confusing errors.
Problem 3: Folder Name Mapping Fragmented
Different targets use different folder names.
| Internal | Batocera | RocknIX |
| megacd | megacd | segacd |
| pspminis | psp/pspminis | pspminis |
Workaround: platform_folder_map duplicated across builds
Problem 4: Compression Fallback Missing
If a target doesn't support 7z, the build produces unusable output.
Current: No validation or fallback
Needed: Automatic fallback (7z → zip)
🚀 Proposed Architecture
New Layer: Target Definitions
Solution: Create standalone target definition files that declare capabilities and constraints.
graph TB
subgraph "Proposed Structure"
direction TB
T1[config/targets/batocera.yaml]
T2[config/targets/rocknix.yaml]
T3[config/targets/everdrive.yaml]
end
subgraph "Target Contents"
M[Media Support
image, video, manual?]
C[Compression Support
zip, 7z, chd?]
P[Platform Support
nes, ps3?]
F[Folder Mapping
megacd → segacd]
end
T1 --> M
T1 --> C
T1 --> P
T1 --> F
T2 --> M
T2 --> C
T2 --> P
T2 --> F
style T1 fill:#10b981,stroke:#047857,color:#fff
style T2 fill:#10b981,stroke:#047857,color:#fff
style T3 fill:#10b981,stroke:#047857,color:#fff
Target Definition Schema
❌ Current: RocknIX (Inline)
// Inside platform config
targets:
- name: rocknix
output_path: /path/to/output/rocknix/saturn
organization:
style: balanced
metadata: true
No capabilities defined!
✅ Proposed: RocknIX Target File
// config/targets/rocknix.yaml
name: rocknix
media_support:
- image
- mix
- wheel
- video
// NO manual - no PDF viewer
compression_support:
- zip
- chd
- cso
// NO 7z
compression_fallback:
7z: zip
platform_support:
- nes
- snes
- psx
// NO ps3, xbox360
folder_mapping:
megacd: segacd
Decision Matrix
flowchart LR
subgraph "Platform Constraints"
PC1[disc_swap: false
3DO can't swap]
PC2[disc_swap: true
Saturn can swap]
end
subgraph "Target Constraints"
TC1[media_support
No manuals on RocknIX]
TC2[compression_support
No 7z on RocknIX]
TC3[platform_support
No PS3 on RocknIX]
TC4[folder_mapping
megacd → segacd]
end
PC1 --> D1{Create M3U?}
PC2 --> D1
D1 --> |3DO: No| R1[Skip M3U]
D1 --> |Saturn: Yes| R2[Create M3U]
TC1 --> D2{Include Manual?}
D2 --> |RocknIX: No| R3[Skip]
D2 --> |Batocera: Yes| R4[Include]
style PC1 fill:#f59e0b,stroke:#b45309,color:#fff
style PC2 fill:#10b981,stroke:#047857,color:#fff
style TC1 fill:#3b82f6,stroke:#1d4ed8,color:#fff
style TC2 fill:#3b82f6,stroke:#1d4ed8,color:#fff
style TC3 fill:#3b82f6,stroke:#1d4ed8,color:#fff
style TC4 fill:#3b82f6,stroke:#1d4ed8,color:#fff
Updated Data Flow
flowchart TD
A[User Request
romfarmer build run rocknix-512gb] --> B[Load Target Definition
config/targets/rocknix.yaml]
B --> C{Platform Validation}
C --> |ps3 requested| D[Check platform_support]
D --> |NOT SUPPORTED| E[❌ Skip with warning]
C --> |saturn requested| F[Check platform_support]
F --> |SUPPORTED| G[✅ Continue]
G --> H{Compression Resolution}
H --> |7z requested| I[Check compression_support]
I --> |NOT SUPPORTED| J[Fallback: 7z → zip]
J --> K{Folder Resolution}
K --> |megacd| L[Check folder_mapping]
L --> M[Output: segacd/]
M --> N{Media Filtering}
N --> |manual available| O[Check media_support]
O --> |NOT SUPPORTED| P[Skip manual]
P --> Q[✅ Build Complete]
style A fill:#3b82f6,stroke:#1d4ed8,color:#fff
style B fill:#10b981,stroke:#047857,color:#fff
style E fill:#ef4444,stroke:#b91c1c,color:#fff
style G fill:#10b981,stroke:#047857,color:#fff
style Q fill:#10b981,stroke:#047857,color:#fff
📋 Implementation Priority
-
Phase 1: Target Definition Files (High Priority)
Create the target definition layer with media support and platform support.
- Create Pydantic models for target definitions
- Create
config/targets/batocera.yaml
- Create
config/targets/rocknix.yaml
- Create target loader
- Wire into metadata stage
- Add platform support validation
-
Phase 2: Compression Handling (Medium Priority)
Add compression support and fallback logic.
- Add
compression_support to target schema
- Add
compression_fallback mapping
- Wire into compression stage
- Add validation warnings
-
Phase 3: Folder Mapping (Medium Priority)
Centralize folder name mapping in targets.
- Add
folder_mapping to target schema
- Wire into organize stage
- Remove
platform_folder_map from builds
- Migrate existing configs
-
Phase 4: Platform Capabilities (Lower Priority)
Formalize platform hardware capabilities.
- Add
capabilities section to platform schema
- Rename
multi_disc_handling to capabilities.disc_swap
- Migrate existing platform configs
- Document capability patterns
✨ Benefits
❌ Before (Current State)
// Scattered hardcoded checks
if context.target_name == 'rocknix'
&& media_type == 'manual':
continue
// Duplicated folder maps
platform_folder_map:
rocknix:
megacd: segacd
// No validation - fails at runtime
platforms:
- ps3 // Will break on RocknIX
✅ After (Proposed State)
// Target capabilities declared once
// config/targets/rocknix.yaml
media_support:
- image
- mix
- wheel
- video
// No manual
platform_support:
- nes
- snes
- psx
// No PS3
folder_mapping:
megacd: segacd
compression_fallback:
7z: zip
🎯 Declarative
Capabilities declared in YAML instead of scattered hardcoded checks throughout the codebase.
⚡ Early Validation
Impossible combinations caught at config load time, not after hours of processing.
🔄 Centralized
Folder mappings defined once in target files, not duplicated across every build.
📚 Self-Documenting
Target files serve as documentation of what each device supports.
Summary
The proposed architecture introduces a first-class Target layer that declares capabilities instead of scattering hardcoded checks, validates early instead of failing at runtime, centralizes mappings instead of duplicating across builds, enables fallbacks instead of producing unusable output, and documents constraints as code instead of tribal knowledge.
This is foundational work that will make ROM Farmer more maintainable, extensible, and user-friendly.