Updates the technical documentation of the music library, the plugins, and the architecture decisions

This commit is contained in:
BinaryAlley committed 2026-10-06 11:30:00 +03:00
1 parent 012d702b17
commit bf8b49653d
26 files changed
+1836 -620

No files matched your search

@@ -39,13 +39,25 @@ end note
interface IBooksFileSystemDiscoveryJob {
}
interface IMusicFileSystemDiscoveryJob {
}
interface IMusicMetadataExtractionJob {
}
interface IMediaLibraryScanDiffJob {
}
interface IMediaLibraryScanHashJob {
}
interface IGoodReadsMetadataScrapJob {
interface IMediaLibraryScanProviderConfigurationInvalidationJob {
}
interface IMediaLibraryScanMetadataEnrichmentJob {
}
interface IMediaLibraryScanArtworkEnrichmentJob {
}
interface IMediaLibraryScanResultsSaveJob {
@@ -56,6 +68,16 @@ class BooksFileSystemDiscoveryJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class MusicFileSystemDiscoveryJob {
- STAGING_BATCH_SIZE: int = 1000
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class MusicMetadataExtractionJob {
- EXTRACTION_BATCH_SIZE: int = 1000
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class MediaLibraryScanDiffJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
@@ -65,8 +87,15 @@ class MediaLibraryScanHashJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class GoodReadsMetadataScrapJob {
- ENRICHMENT_PAGE_SIZE: int = 1000
class MediaLibraryScanProviderConfigurationInvalidationJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class MediaLibraryScanMetadataEnrichmentJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
class MediaLibraryScanArtworkEnrichmentJob {
+ ExecuteAsync<TInput>(id: Guid, input: TInput, token: CancellationToken): Task
}
@@ -94,8 +123,8 @@ end note
note right of MediaLibraryScanResultsSaveJob
Persists the results of the current scan and swaps the scan
snapshot in a single transaction. Always the last job in the
directed acyclic job graph.
snapshot in a single transaction, then triggers the provider
configuration invalidation job.
end note
class ScanFailurePublisher {
@@ -108,30 +137,6 @@ note top of ScanFailurePublisher
releases its processing resources (see ADR-0009).
end note
' ============================== HOOKS AND REGISTRY ==============================
class ScanJobHooks {
+ AFTER_FILE_SYSTEM_DISCOVERY: string
+ AFTER_SCAN_DIFF: string
+ BEFORE_METADATA_ENRICHMENT: string
+ AFTER_METADATA_ENRICHMENT: string
+ BEFORE_SCAN_RESULTS_SAVE: string
}
note bottom of ScanJobHooks
Named junction points of the scan job graph where plugin
jobs can be injected (see ADR-0008).
end note
interface IScanJobRegistry {
+ GetJobsForHook(hookName: string, libraryId: LibraryId): IEnumerable<IMediaLibraryScanJob>
}
class ScanJobRegistry {
- _jobsByHook: IReadOnlyDictionary<string, IReadOnlyList<Type>>
+ GetJobsForHook(hookName: string, libraryId: LibraryId): IEnumerable<IMediaLibraryScanJob>
}
' ============================== FACTORIES AND SCANNERS ==============================
interface IMediaLibraryScanJobFactory {
@@ -151,25 +156,103 @@ class MediaLibraryScannerFactory {
}
interface IMediaTypeScanner {
+ SupportedType: LibraryType
+ CreateScanJobsForLibrary(libraryId: LibraryId, downloadMetadataFromWeb: bool): IEnumerable<IMediaLibraryScanJob>
+ SupportedLibraryType: LibraryType
+ CreateScanJobsForLibrary(libraryId: LibraryId): IEnumerable<IMediaLibraryScanJob>
}
interface IBookLibraryTypeScanner {
}
interface IMusicLibraryTypeScanner {
}
class BookLibraryTypeScanner {
- _mediaScanJobFactory: IMediaLibraryScanJobFactory
- _scanJobRegistry: IScanJobRegistry
+ SupportedType: LibraryType
+ CreateScanJobsForLibrary(libraryId: LibraryId, downloadMetadataFromWeb: bool): IEnumerable<IMediaLibraryScanJob>
+ SupportedLibraryType: LibraryType
+ CreateScanJobsForLibrary(libraryId: LibraryId): IEnumerable<IMediaLibraryScanJob>
}
class MusicLibraryTypeScanner {
- _mediaScanJobFactory: IMediaLibraryScanJobFactory
+ SupportedLibraryType: LibraryType
+ CreateScanJobsForLibrary(libraryId: LibraryId): IEnumerable<IMediaLibraryScanJob>
}
' ============================== MEDIA TYPE STRATEGIES ==============================
interface IMediaLibraryScanItemMaterializer {
+ SupportedLibraryType: LibraryType
+ ResetEnrichmentStateForChangedPathsAsync(unitOfWork: IUnitOfWork, libraryId: Guid, paths: IReadOnlyCollection<string>, token: CancellationToken): Task<Result<Updated>>
+ MaterializeItemsAsync(unitOfWork: IUnitOfWork, libraryId: Guid, scanId: Guid, paths: IReadOnlyList<string>, token: CancellationToken): Task<Result<Success>>
+ ResetMetadataStatusForLibraryAsync(unitOfWork: IUnitOfWork, libraryId: Guid, token: CancellationToken): Task<Result<Updated>>
+ ResetArtworkStatusForLibraryAsync(unitOfWork: IUnitOfWork, libraryId: Guid, token: CancellationToken): Task<Result<Updated>>
}
interface IMediaLibraryScanMetadataEnricher {
+ SupportedLibraryType: LibraryType
+ EnrichAsync(libraryId: LibraryId, scanId: ScanId, userId: UserId, token: CancellationToken): Task
}
interface IMediaLibraryScanArtworkEnricher {
+ SupportedLibraryType: LibraryType
+ EnrichAsync(libraryId: LibraryId, scanId: ScanId, userId: UserId, token: CancellationToken): Task
}
class BooksMediaLibraryScanItemMaterializer {
}
class MusicMediaLibraryScanItemMaterializer {
}
class BooksMediaLibraryScanMetadataEnricher {
- ENRICHMENT_PAGE_SIZE: int = 1000
}
class MusicMediaLibraryScanMetadataEnricher {
- ENRICHMENT_PAGE_SIZE: int = 200
}
class BooksMediaLibraryScanArtworkEnricher {
- ENRICHMENT_PAGE_SIZE: int = 1000
}
class MusicMediaLibraryScanArtworkEnricher {
- ENRICHMENT_PAGE_SIZE: int = 200
}
note top of BookLibraryTypeScanner
Builds the books scan job graph: file system discovery,
scan diff, hashing, optional GoodReads metadata enrichment
and scan results save, splicing the plugin jobs registered
at the ScanJobHooks hook points (see ADR-0008).
scan diff, hashing, scan results save, provider configuration
invalidation, metadata enrichment and artwork enrichment.
end note
' ============================== PATH TEMPLATE ==============================
interface ILibraryPathTemplateService {
+ GetDefaultTemplate(libraryType: LibraryType): LibraryPathTemplate
+ ResolveTemplate(libraryType: LibraryType, providedParts: IReadOnlyList<LibraryPathPart>): Result<LibraryPathTemplate>
+ Validate(libraryType: LibraryType, template: LibraryPathTemplate): Result<Success>
+ Parse(libraryType: LibraryType, template: LibraryPathTemplate, relativePath: string, pathSeparator: char): Result<Optional<ParsedLibraryPath>>
}
class LibraryPathTemplateService {
}
interface ILibraryPathPartCatalog {
+ SupportedLibraryType: LibraryType
+ GetPartDefinitions(): IReadOnlyList<LibraryPathPartDefinition>
+ GetDefaultTemplate(): LibraryPathTemplate
}
class MusicLibraryPathPartCatalog {
}
class BookLibraryPathPartCatalog {
}
note bottom of ILibraryPathTemplateService
Validates media library path templates and derives item
metadata from paths, using the catalog of each library type.
end note
' ============================== SCAN ORCHESTRATION ==============================
@@ -179,12 +262,12 @@ class LibraryScan {
+ LibraryId: LibraryId
+ UserId: UserId
+ Status: LibraryScanJobStatus
+ {static} Create(libraryId: LibraryId, userId: UserId, pastScans: List<LibraryScan>): ErrorOr<LibraryScan>
+ QueueScan(): ErrorOr<Success>
+ StartScan(): ErrorOr<Success>
+ FinishScan(): ErrorOr<Success>
+ CancelScan(): ErrorOr<Success>
+ FailScan(): ErrorOr<Success>
+ {static} Create(libraryId: LibraryId, userId: UserId, pastScans: List<LibraryScan>): Result<LibraryScan>
+ QueueScan(): Result<Success>
+ StartScan(): Result<Success>
+ FinishScan(): Result<Success>
+ CancelScan(): Result<Success>
+ FailScan(): Result<Success>
}
note right of LibraryScan
@@ -193,8 +276,8 @@ note right of LibraryScan
end note
interface IMediaLibraryScanningService {
+ StartScanAsync(scan: LibraryScan, libraryType: LibraryType, downloadMetadataFromWeb: bool, token: CancellationToken): Task<ErrorOr<Success>>
+ CancelScan(scan: LibraryScan): ErrorOr<Success>
+ StartScanAsync(scan: LibraryScan, libraryType: LibraryType, token: CancellationToken): Task<Result<Success>>
+ CancelScan(scan: LibraryScan): Result<Success>
}
class MediaLibraryScanningService {
@@ -202,9 +285,9 @@ class MediaLibraryScanningService {
- _mediaLibraryScannerFactory: IMediaLibraryScannerFactory
- _mediaLibrariesScanCancellationTracker: IMediaLibrariesScanCancellationTracker
- _mediaLibrariesScanProgressTracker: IMediaLibrariesScanProgressTracker
- _publisher: IPublisher
+ StartScanAsync(scan: LibraryScan, libraryType: LibraryType, downloadMetadataFromWeb: bool, token: CancellationToken): Task<ErrorOr<Success>>
+ CancelScan(scan: LibraryScan): ErrorOr<Success>
- _domainEventPublisher: IDomainEventPublisher
+ StartScanAsync(scan: LibraryScan, libraryType: LibraryType, token: CancellationToken): Task<Result<Success>>
+ CancelScan(scan: LibraryScan): Result<Success>
}
note top of MediaLibraryScanningService
@@ -259,11 +342,11 @@ class MediaLibrariesScanCancellationTracker {
}
interface IMediaLibrariesScanProgressTracker {
+ InitializeScanProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId, totalJobs: int): ErrorOr<Created>
+ UpdateScanProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId): ErrorOr<Updated>
+ UpdateScanJobProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId, progress: MediaLibraryScanJobProgress): ErrorOr<Updated>
+ GetScanProgress(compositeKey: MediaLibraryScanCompositeId): ErrorOr<MediaLibraryScanProgress>
+ RemoveScanProgress(compositeKey: MediaLibraryScanCompositeId): ErrorOr<MediaLibraryScanProgress>
+ InitializeScanProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId, totalJobs: int): Result<Created>
+ UpdateScanProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId): Result<Updated>
+ UpdateScanJobProgress(libraryId: LibraryId, compositeKey: MediaLibraryScanCompositeId, progress: MediaLibraryScanJobProgress): Result<Updated>
+ GetScanProgress(compositeKey: MediaLibraryScanCompositeId): Result<MediaLibraryScanProgress>
+ RemoveScanProgress(compositeKey: MediaLibraryScanCompositeId): Result<MediaLibraryScanProgress>
}
class MediaLibrariesScanProgressTracker {
@@ -285,7 +368,7 @@ class DebouncedMediaLibraryScanProgressNotifier {
}
class MediaLibraryScanProgressHub {
+ SubscribeToScan(scanId: Guid, userId: Guid): Task
+ SubscribeToScan(scanId: Guid): Task
}
note top of MediaLibraryScanProgressHub
@@ -296,31 +379,31 @@ end note
' ============================== DOMAIN EVENT HANDLERS ==============================
class LibraryScanQueuedDomainEventHandler {
+ Handle(domainEvent: LibraryScanQueuedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanQueuedDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanStartedDomainEventHandler {
+ Handle(domainEvent: LibraryScanStartedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanStartedDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanFinishedDomainEventHandler {
+ Handle(domainEvent: LibraryScanFinishedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanFinishedDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanFailedDomainEventHandler {
+ Handle(domainEvent: LibraryScanFailedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanFailedDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanCancelledDomainEventHandler {
+ Handle(domainEvent: LibraryScanCancelledDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanCancelledDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanProgressChangedDomainEventHandler {
+ Handle(domainEvent: LibraryScanProgressChangedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanProgressChangedDomainEvent, token: CancellationToken): ValueTask
}
class LibraryScanJobProgressChangedDomainEventHandler {
+ Handle(domainEvent: LibraryScanJobProgressChangedDomainEvent, token: CancellationToken): ValueTask
+ HandleAsync(domainEvent: LibraryScanJobProgressChangedDomainEvent, token: CancellationToken): ValueTask
}
' ============================== JOB MODEL RELATIONSHIPS ==============================
@@ -328,30 +411,46 @@ class LibraryScanJobProgressChangedDomainEventHandler {
IMediaLibraryScanJob <|.. MediaLibraryScanJob : implements
IMediaLibraryScanJob <|-- IBooksFileSystemDiscoveryJob
IMediaLibraryScanJob <|-- IMusicFileSystemDiscoveryJob
IMediaLibraryScanJob <|-- IMusicMetadataExtractionJob
IMediaLibraryScanJob <|-- IMediaLibraryScanDiffJob
IMediaLibraryScanJob <|-- IMediaLibraryScanHashJob
IMediaLibraryScanJob <|-- IGoodReadsMetadataScrapJob
IMediaLibraryScanJob <|-- IMediaLibraryScanProviderConfigurationInvalidationJob
IMediaLibraryScanJob <|-- IMediaLibraryScanMetadataEnrichmentJob
IMediaLibraryScanJob <|-- IMediaLibraryScanArtworkEnrichmentJob
IMediaLibraryScanJob <|-- IMediaLibraryScanResultsSaveJob
MediaLibraryScanJob <|-- BooksFileSystemDiscoveryJob : inherits
MediaLibraryScanJob <|-- MusicFileSystemDiscoveryJob : inherits
MediaLibraryScanJob <|-- MusicMetadataExtractionJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanDiffJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanHashJob : inherits
MediaLibraryScanJob <|-- GoodReadsMetadataScrapJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanProviderConfigurationInvalidationJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanMetadataEnrichmentJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanArtworkEnrichmentJob : inherits
MediaLibraryScanJob <|-- MediaLibraryScanResultsSaveJob : inherits
IBooksFileSystemDiscoveryJob <|.. BooksFileSystemDiscoveryJob : implements
IMusicFileSystemDiscoveryJob <|.. MusicFileSystemDiscoveryJob : implements
IMusicMetadataExtractionJob <|.. MusicMetadataExtractionJob : implements
IMediaLibraryScanDiffJob <|.. MediaLibraryScanDiffJob : implements
IMediaLibraryScanHashJob <|.. MediaLibraryScanHashJob : implements
IGoodReadsMetadataScrapJob <|.. GoodReadsMetadataScrapJob : implements
IMediaLibraryScanProviderConfigurationInvalidationJob <|.. MediaLibraryScanProviderConfigurationInvalidationJob : implements
IMediaLibraryScanMetadataEnrichmentJob <|.. MediaLibraryScanMetadataEnrichmentJob : implements
IMediaLibraryScanArtworkEnrichmentJob <|.. MediaLibraryScanArtworkEnrichmentJob : implements
IMediaLibraryScanResultsSaveJob <|.. MediaLibraryScanResultsSaveJob : implements
' ============================== JOB TRIGGER CHAIN ==============================
BooksFileSystemDiscoveryJob ..> MediaLibraryScanDiffJob : triggers
MusicFileSystemDiscoveryJob ..> MediaLibraryScanDiffJob : triggers
MediaLibraryScanDiffJob ..> MediaLibraryScanHashJob : triggers
MediaLibraryScanHashJob ..> GoodReadsMetadataScrapJob : triggers when metadata enrichment is enabled
GoodReadsMetadataScrapJob ..> MediaLibraryScanResultsSaveJob : triggers
MediaLibraryScanHashJob ..> MediaLibraryScanResultsSaveJob : triggers when metadata enrichment is disabled
MediaLibraryScanHashJob ..> MediaLibraryScanResultsSaveJob : triggers
MediaLibraryScanHashJob ..> MusicMetadataExtractionJob : triggers
MusicMetadataExtractionJob ..> MediaLibraryScanResultsSaveJob : triggers
MediaLibraryScanResultsSaveJob ..> MediaLibraryScanProviderConfigurationInvalidationJob : triggers
MediaLibraryScanProviderConfigurationInvalidationJob ..> MediaLibraryScanMetadataEnrichmentJob : triggers
MediaLibraryScanMetadataEnrichmentJob ..> MediaLibraryScanArtworkEnrichmentJob : triggers
MediaLibraryScanJob ..> ScanFailurePublisher : publishes failure on unhandled exception
@@ -359,21 +458,48 @@ MediaLibraryScanJob ..> ScanFailurePublisher : publishes failure on unhandled ex
IMediaLibraryScannerFactory <|.. MediaLibraryScannerFactory : implements
IMediaLibraryScanJobFactory <|.. MediaLibraryScanJobFactory : implements
IScanJobRegistry <|.. ScanJobRegistry : implements
IMediaTypeScanner <|-- IBookLibraryTypeScanner
IBookLibraryTypeScanner <|.. BookLibraryTypeScanner : implements
IMediaTypeScanner <|-- IMusicLibraryTypeScanner
IMusicLibraryTypeScanner <|.. MusicLibraryTypeScanner : implements
MediaLibraryScannerFactory ..> IMediaTypeScanner : creates
BookLibraryTypeScanner --> IMediaLibraryScanJobFactory : uses
BookLibraryTypeScanner --> IScanJobRegistry : splices plugin jobs
BookLibraryTypeScanner ..> IBooksFileSystemDiscoveryJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanDiffJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanHashJob : creates
BookLibraryTypeScanner ..> IGoodReadsMetadataScrapJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanResultsSaveJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanProviderConfigurationInvalidationJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanMetadataEnrichmentJob : creates
BookLibraryTypeScanner ..> IMediaLibraryScanArtworkEnrichmentJob : creates
MusicLibraryTypeScanner --> IMediaLibraryScanJobFactory : uses
MusicLibraryTypeScanner ..> IMusicFileSystemDiscoveryJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanDiffJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanHashJob : creates
MusicLibraryTypeScanner ..> IMusicMetadataExtractionJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanResultsSaveJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanProviderConfigurationInvalidationJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanMetadataEnrichmentJob : creates
MusicLibraryTypeScanner ..> IMediaLibraryScanArtworkEnrichmentJob : creates
IMediaLibraryScanResultsSaveJob --> IMediaLibraryScanItemMaterializer : delegates to
IMediaLibraryScanProviderConfigurationInvalidationJob --> IMediaLibraryScanItemMaterializer : delegates to
IMediaLibraryScanMetadataEnrichmentJob --> IMediaLibraryScanMetadataEnricher : delegates to
IMediaLibraryScanArtworkEnrichmentJob --> IMediaLibraryScanArtworkEnricher : delegates to
IMediaLibraryScanItemMaterializer <|.. BooksMediaLibraryScanItemMaterializer : implements
IMediaLibraryScanItemMaterializer <|.. MusicMediaLibraryScanItemMaterializer : implements
IMediaLibraryScanMetadataEnricher <|.. BooksMediaLibraryScanMetadataEnricher : implements
IMediaLibraryScanMetadataEnricher <|.. MusicMediaLibraryScanMetadataEnricher : implements
IMediaLibraryScanArtworkEnricher <|.. BooksMediaLibraryScanArtworkEnricher : implements
IMediaLibraryScanArtworkEnricher <|.. MusicMediaLibraryScanArtworkEnricher : implements
ILibraryPathTemplateService <|.. LibraryPathTemplateService : implements
ILibraryPathPartCatalog <|.. MusicLibraryPathPartCatalog : implements
ILibraryPathPartCatalog <|.. BookLibraryPathPartCatalog : implements
LibraryPathTemplateService --> ILibraryPathPartCatalog : uses
MusicMetadataExtractionJob --> ILibraryPathTemplateService : derives metadata from paths
ScanJobRegistry ..> IMediaLibraryScanJob : resolves plugin jobs for hooks
MediaLibraryScanJobFactory ..> IMediaLibraryScanJob : creates
' ============================== SERVICE RELATIONSHIPS ==============================
@@ -392,7 +518,7 @@ IMediaLibrariesScanQueue <|.. MediaLibrariesScanQueue : implements
MediaLibraryScanJobProcessorJob --> IMediaLibrariesScanQueue : reads from
MediaLibraryScanJobProcessorJob --> IMediaLibrariesScanCancellationTracker : links scan token
MediaLibraryScanJobProcessorJob ..> BooksFileSystemDiscoveryJob : triggers root job
MediaLibraryScanJobProcessorJob ..> IMediaLibraryScanJob : triggers root job
' ============================== TRACKER RELATIONSHIPS ==============================
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="4878px" preserveAspectRatio="none" style="width:3794px;height:4878px;background:#FFFFFF;" version="1.1" viewBox="0 0 3794 4878" width="3794px" zoomAndPan="magnify"><title>Code diagram for Background Services 3.2.1</title><defs/><g><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacing" textLength="297.9922" x="1741.4482" y="24.5332">Code diagram for Background Services 3.2.1</text><!--class IMediaLibraryScanJob--><g id="elem_IMediaLibraryScanJob"><rect codeLine="13" fill="#FFFFFF" height="312.1406" id="IMediaLibraryScanJob" rx="2.5" ry="2.5" style="stroke:#000000;stroke-width:0.5;" width="210.4336" x="2495" y="3008.6094"/><ellipse cx="2527.612" cy="3024.6094" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1;"/><path d="M2528.5651,3021.25 L2528.5651,3027.9063 L2530.2838,3027.9063 Q2530.8932,3027.9063 2531.1588,3028.1406 Q2531.4245,3028.375 2531.4245,3028.7656 Q2531.4245,3029.1406 2531.1588,3029.375 Q2530.8932,3029.6094 2530.2838,3029.6094 L2525.1432,3029.6094 Q2524.5338,3029.6094 2524.2682,3029.375 Q2524.0026,3029.1406 2524.0026,3028.75 Q2524.0026,3028.375 2524.2682,3028.1406 Q2524.5338,3027.9063 2525.1432,3027.9063 L2526.862,3027.9063 L2526.862,3021.25 L2525.1432,3021.25 Q2524.5338,3021.25 2524.2682,3021.0156 Q2524.0026,3020.7813 2524.0026,3020.3906 Q2524.0026,3020.0156 2524.2682,3019.7813 Q2524.5338,3019.5469 2525.1432,3019.5469 L2530.2838,3019.5469 Q2530.8932,3019.5469 2531.1588,3019.7813 Q2531.4245,3020.0156 2531.4245,3020.3906 Q2531.4245,3020.7813 2531.1588,3021.0156 Q2530.8932,3021.25 2530.2838,3021.25 L2528.5651,3021.25 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="139.2959" x="2545.5257" y="3030.3379">IMediaLibraryScanJob</text><line style="stroke:#000000;stroke-width:0.5;" x1="2496" x2="2704.4336" y1="3040.6094" y2="3040.6094"/><ellipse cx="2506" cy="3054.9141" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="47.4756" x="2515" y="3059.1426">ScanId:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="3.8896" x="2562.4756" y="3059.1426">&#160;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="43.5859" x="2566.3652" y="3059.1426">ScanId</text><ellipse cx="2506" cy="3072.5234" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="45.124" x="2515" y="3076.752">UserId:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="3.8896" x="2560.124" y="3076.752">&#160;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="41.2344" x="2564.0137" y="3076.752">UserId</text><ellipse cx="2506" cy="3090.1328" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="58.3584" x="2515" y="3094.3613">LibraryId:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="3.8896" x="2573.3584" y="3094.3613">&#160;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="54.4688" x="2577.248" y="3094.3613">LibraryId</text><ellipse cx="2506" cy="3116.5469" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="56.0273" x="2515" y="3111.9707">Children:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="177.4336" x="2515" y="3129.5801">List&lt;IMediaLibraryScanJob&gt;</text><ellipse cx="2506" cy="3151.7656" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="52.1377" x="2515" y="3147.1895">Parents:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="177.4336" x="2515" y="3164.7988">List&lt;IMediaLibraryScanJob&gt;</text><ellipse cx="2506" cy="3178.1797" fill="none" rx="3" ry="3" style="stroke:#038048;stroke-width:1;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="43.5791" x="2515" y="3182.4082">Status:</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="3.8896" x="2558.5791" y="3182.4082">&#160;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="136.9648" x="2562.4688" y="3182.4082">LibraryScanJobSLine truncated
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" data-diagram-type="CLASS" style="width:4278px;height:5609px;background:#FFFFFF;" width="4278px" height="5609px" viewBox="0 0 4278 5609" zoomAndPan="magnify" preserveAspectRatio="none" contentStyleType="text/css"><?plantuml 1.2026.7?><defs/><g font-family="sans-serif" lengthAdjust="spacing"><g class="title" data-source-line="4"><text x="1986.931" y="24.533" fill="#000" font-size="14" textLength="297.992" font-weight="700">Code diagram for Background Services 3.2.1</text></g><!--class IMediaLibraryScanJob--><g class="entity" data-qualified-name="IMediaLibraryScanJob" id="ent0001" data-source-line="13"><rect x="2288.5" y="2658.609" width="210.434" height="312.141" fill="#FFF" style="stroke:#000;stroke-width:0.5;" rx="2.5" ry="2.5"/><ellipse cx="2321.112" cy="2674.609" rx="11" ry="11" fill="#B4A7E5" style="stroke:#181818;stroke-width:1;"/><path d="M2322.065,2671.25 L2322.065,2677.906 L2323.784,2677.906 Q2324.393,2677.906 2324.659,2678.141 Q2324.924,2678.375 2324.924,2678.766 Q2324.924,2679.141 2324.659,2679.375 Q2324.393,2679.609 2323.784,2679.609 L2318.643,2679.609 Q2318.034,2679.609 2317.768,2679.375 Q2317.503,2679.141 2317.503,2678.75 Q2317.503,2678.375 2317.768,2678.141 Q2318.034,2677.906 2318.643,2677.906 L2320.362,2677.906 L2320.362,2671.25 L2318.643,2671.25 Q2318.034,2671.25 2317.768,2671.016 Q2317.503,2670.781 2317.503,2670.391 Q2317.503,2670.016 2317.768,2669.781 Q2318.034,2669.547 2318.643,2669.547 L2323.784,2669.547 Q2324.393,2669.547 2324.659,2669.781 Q2324.924,2670.016 2324.924,2670.391 Q2324.924,2670.781 2324.659,2671.016 Q2324.393,2671.25 2323.784,2671.25 L2322.065,2671.25 Z " fill="#000"/><text x="2339.026" y="2680.338" fill="#000" font-size="14" textLength="139.296" font-style="italic">IMediaLibraryScanJob</text><line x1="2289.5" y1="2690.609" x2="2497.934" y2="2690.609" style="stroke:#000;stroke-width:0.5;"/><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2704.914" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2709.143" fill="#000" font-size="14" textLength="47.476">ScanId:</text><text x="2355.976" y="2709.143" fill="#000" font-size="14"> </text><text x="2359.865" y="2709.143" fill="#000" font-size="14" textLength="43.586">ScanId</text><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2722.523" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2726.752" fill="#000" font-size="14" textLength="45.124">UserId:</text><text x="2353.624" y="2726.752" fill="#000" font-size="14"> </text><text x="2357.514" y="2726.752" fill="#000" font-size="14" textLength="41.234">UserId</text><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2740.133" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2744.361" fill="#000" font-size="14" textLength="58.358">LibraryId:</text><text x="2366.858" y="2744.361" fill="#000" font-size="14"> </text><text x="2370.748" y="2744.361" fill="#000" font-size="14" textLength="54.469">LibraryId</text><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2766.547" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2761.971" fill="#000" font-size="14" textLength="56.027">Children:</text><text x="2308.5" y="2779.58" fill="#000" font-size="14" textLength="177.434">List&lt;IMediaLibraryScanJob></text><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2801.766" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2797.189" fill="#000" font-size="14" textLength="52.138">Parents:</text><text x="2308.5" y="2814.799" fill="#000" font-size="14" textLength="177.434">List&lt;IMediaLibraryScanJob></text><g data-visibility-modifier="PUBLIC_FIELD"><ellipse cx="2299.5" cy="2828.18" rx="3" ry="3" fill="none" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2832.408" fill="#000" font-size="14" textLength="43.579">Status:</text><text x="2352.079" y="2832.408" fill="#000" font-size="14"> </text><text x="2355.969" y="2832.408" fill="#000" font-size="14" textLength="136.965">LibraryScanJobStatus</text><line x1="2289.5" y1="2839.484" x2="2497.934" y2="2839.484" style="stroke:#000;stroke-width:0.5;"/><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="2299.5" cy="2862.594" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2858.018" fill="#000" font-size="14" textLength="84.048">AddChild(job:</text><text x="2308.5" y="2875.627" fill="#000" font-size="14" textLength="143.958">IMediaLibraryScanJob)</text><g data-visibility-modifier="PUBLIC_METHOD"><ellipse cx="2299.5" cy="2897.813" rx="3" ry="3" fill="#84BE84" style="stroke:#038048;stroke-width:1;"/></g><text x="2308.5" y="2893.236" fill="#000" font-size="14" textLength="93.393">AddParent(job:</text><text x="2308.5" y="Line truncated

Before

Width:  |  Height:  |  Size: 310 KiB

After

Width:  |  Height:  |  Size: 326 KiB

@@ -36,6 +36,10 @@ internal sealed class FileSystemDiscoveryJob : MediaLibraryScanJob, IFileSystemD
}
}
```
## Amendments
- **2026-10-09**: The generic `FileSystemDiscoveryJob` / `IFileSystemDiscoveryJob` was split into per-type discovery jobs (`BooksFileSystemDiscoveryJob`, `MusicFileSystemDiscoveryJob`), and the job execution contract is now `ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken token)` on `IMediaLibraryScanJob`. The `IServiceScopeFactory` decision itself is unchanged.
## Consequences
### Positive Outcomes
@@ -26,7 +26,11 @@ private static List<FileInfo> GetFiles(...)
```
## Consequences
## Amendments
- **2026-10-09**: The single generic `FileSystemDiscoveryJob` was split into per-type discovery jobs (`BooksFileSystemDiscoveryJob`, `MusicFileSystemDiscoveryJob`). The `System.IO` guidance of this ADR applies to the books discovery job, which still traverses the file system directly. The music discovery job uses the domain file system provider services (`IFileProviderService`, `IDirectoryProviderService`) instead.
## Consequences
### Performance vs Purity Tradeoff
| Metric | Before (Domain) | After (System.IO) | Delta |
@@ -4,13 +4,13 @@
**Accepted** (2026-08-08)
## Context
The media library scan pipeline stages the file system items discovered during a scan before comparing them against the `LibraryScanSnapshots` table (ADR-0004). A staging store is needed that:
The media library scan pipeline stages the file system items discovered during a scan before comparing them against the `LibraryScanSnapshots` table ([ADR-0004](architecture-decision-record-0004.md)). A staging store is needed that:
1. receives the discovered file system items in bounded batches,
2. is read by the diff, hash and metadata enrichment jobs,
3. is written by the discovery job and read by later jobs, which run in separate dependency injection scopes (see ADR-0001), hence on separate database connections.
3. is written by the discovery job and read by later jobs, which run in separate dependency injection scopes (see [ADR-0001](architecture-decision-record-0001.md)), hence on separate database connections.
A real SQLite `TEMP` table was considered, but SQLite `TEMP` tables are scoped to a single database connection. Because each media library scan job creates its own `AsyncServiceScope`, and therefore its own `LuminaDbContext` and connection (ADR-0001), a `TEMP` table created by the discovery job would be invisible to the diff job, which runs on a different connection. Making a `TEMP` table work would require pinning a single dedicated connection for the whole staging phase of a scan, a larger architectural carve-out.
A real SQLite `TEMP` table was considered, but SQLite `TEMP` tables are scoped to a single database connection. Because each media library scan job creates its own `AsyncServiceScope`, and therefore its own `LuminaDbContext` and connection ([ADR-0001](architecture-decision-record-0001.md)), a `TEMP` table created by the discovery job would be invisible to the diff job, which runs on a different connection. Making a `TEMP` table work would require pinning a single dedicated connection for the whole staging phase of a scan, a larger architectural carve-out.
## Decision
Use a permanent table, `LibraryScanStagingResults`, keyed by `(LibraryScanId, Path)`. Its rows are deleted at the end of the scan (as part of the snapshot swap transaction of the save job) and on scan failure or cancellation. Leftover rows of a crashed scan are inert, because every scan has a unique id, and can be purged by the audit cleanup job.
@@ -35,9 +35,9 @@ Use a permanent table, `LibraryScanStagingResults`, keyed by `(LibraryScanId, Pa
### 1. SQLite `TEMP` table with a single pinned connection
The whole staging phase would hold one dedicated connection open, and all jobs would share it.
**Rejected**: It conflicts with the per-job scope model of ADR-0001, holds a database connection open for the entire scan duration, and makes the pipeline harder to compose and test.
**Rejected**: It conflicts with the per-job scope model of [ADR-0001](architecture-decision-record-0001.md), holds a database connection open for the entire scan duration, and makes the pipeline harder to compose and test.
### 2. In-memory staging (list of discovered items passed between jobs)
The discovery job would pass the full list of discovered items to the diff job.
**Rejected**: It brings back the unbounded memory problem that ADR-0004 eliminates. The staging table is what allows bounded, batched writes.
**Rejected**: It brings back the unbounded memory problem that [ADR-0004](architecture-decision-record-0004.md) eliminates. The staging table is what allows bounded, batched writes.
@@ -1,7 +1,7 @@
# Architecture Decision Record (ADR): 0008 - Plugin Hook Points and the Media Library Scan Job Graph
## Status
**Accepted** (2026-08-08)
**Superseded by [ADR-0015](architecture-decision-record-0015.md)** (2026-10-09)
## Context
The media library scanning subsystem is meant to be modular: generic jobs, like the scan diff, hashing and results save jobs, are shared by all media library types, while media-type specific jobs, like the GoodReads metadata scrap job for books or a TMDB cover art job for movies, are decoupled and composed into a directed acyclic graph.
@@ -15,24 +15,30 @@ Define named hook points for the scan job graph in `ScanJobHooks`: `AfterFileSys
Define the `IScanJobRegistry` interface, which maps a hook name to the plugin jobs registered at that hook. The media type scanners (for example `BookLibraryTypeScanner`) splice the plugin jobs returned by the registry into the graph at the corresponding hook points, preserving the parent-child relationships. The composition root of the plugin system provides the registry with the plugin job types; the default registry registers no plugin jobs.
The payload passing between jobs keeps the generic `ExecuteAsync<TInput>` contract. The core scan jobs are database-centric and ignore the payload, because they exchange the scan state through the staging and snapshot tables (ADR-0004, ADR-0005). Payload passing remains available for plugin jobs that need to exchange data in memory, and the runtime type switching that was used in the previous `HashComparerJob` is eliminated.
The payload passing between jobs keeps the generic `ExecuteAsync<TInput>` contract. The core scan jobs are database-centric and ignore the payload, because they exchange the scan state through the staging and snapshot tables ([ADR-0004](architecture-decision-record-0004.md), [ADR-0005](architecture-decision-record-0005.md)). Payload passing remains available for plugin jobs that need to exchange data in memory, and the runtime type switching that was used in the previous `HashComparerJob` is eliminated.
## Amendments
- **2026-10-09**: Superseded by [ADR-0015](architecture-decision-record-0015.md). The `ScanJobHooks` hook points and the `IScanJobRegistry` / `ScanJobRegistry` were removed, and plugins now contribute capability providers (`IMetadataProvider`, `IArtworkProvider`, `IBookReader`) instead of scan jobs. This ADR is marked superseded rather than amended because its decision is replaced in full by [ADR-0015](architecture-decision-record-0015.md); [ADR-0001](architecture-decision-record-0001.md), [ADR-0003](architecture-decision-record-0003.md) and [ADR-0010](architecture-decision-record-0010.md) stay accepted because only part of their decisions changed.
## Consequences
> The rows struck through reflect the superseded hook point and scan job registry model. They no longer hold, see [ADR-0015](architecture-decision-record-0015.md).
### Positive Outcomes
| Aspect | Benefit |
|-----------------------|-----------------------------------------------------------|
| Modularity | Media-type specific jobs are composed per scanner |
| Extensibility | Plugins inject jobs at documented hook points |
| ~~Extensibility~~ | ~~Plugins inject jobs at documented hook points~~ (removed, see [ADR-0015](architecture-decision-record-0015.md)) |
| Multi-parent support | The base job model keeps full parent-child capabilities |
| Fail fast composition | Wrong payload wiring produces loud errors instead of silent no-ops |
| ~~Fail fast composition~~ | ~~Wrong payload wiring produces loud errors instead of silent no-ops~~ (removed, see [ADR-0015](architecture-decision-record-0015.md)) |
### Risks and Tradeoffs
| Risk | Mitigation Strategy |
|-------------------------------|-------------------------------------------------------------------|
| Plugin job conflicts | Hook points are named and documented, the composition is validated when the graph is built |
| ~~Plugin job conflicts~~ | ~~Hook points are named and documented, the composition is validated when the graph is built~~ (removed, see [ADR-0015](architecture-decision-record-0015.md)) |
| Payload contract misuse | Jobs that expect a payload fail loudly when the edge type does not match |
| Scope creep | Only the sensible hook points are defined, arbitrary injection is not supported |
| ~~Scope creep~~ | ~~Only the sensible hook points are defined, arbitrary injection is not supported~~ (removed, see [ADR-0015](architecture-decision-record-0015.md)) |
## Alternatives Considered
@@ -4,7 +4,7 @@
**Accepted** (2026-08-08)
## Context
Media library scan jobs are launched in a fire-and-forget manner from the background job processor (`MediaLibraryScanJobProcessorJob`), because only the root jobs are placed on the in-memory queue, and they trigger their children recursively (see ADR-0001 and ADR-0008). The launch mechanism uses `FireAndForgetSafeAsync`, which observes the launched task but does not crash the queue consumer.
Media library scan jobs are launched in a fire-and-forget manner from the background job processor (`MediaLibraryScanJobProcessorJob`), because only the root jobs are placed on the in-memory queue, and they trigger their children recursively (see [ADR-0001](architecture-decision-record-0001.md) and [ADR-0008](architecture-decision-record-0008.md)). The launch mechanism uses `FireAndForgetSafeAsync`, which observes the launched task but does not crash the queue consumer.
The scan jobs must report their failures through the existing eventual consistency mechanism, the `LibraryScanFailedDomainEvent`, whose handler marks the scan as failed, releases the scan processing resources and notifies the clients. The previous job implementations only published the failure event on a few specific error paths, so any other exception was silently swallowed, leaving the scan stuck in the `Running` state, leaking its cancellation source and progress entry.
@@ -4,20 +4,28 @@
**Accepted** (2026-08-09)
## Context
ADR-0009 established that every media library scan job wraps its execution in a catch-all that marks the job as `Failed` and publishes the `LibraryScanFailedDomainEvent`. That decision applies to the mandatory scan jobs: file system discovery, scan diff, content hashing and scan results save. These jobs are transactional in nature, and a failure in any of them means the file state of the library was not committed.
[ADR-0009](architecture-decision-record-0009.md) established that every media library scan job wraps its execution in a catch-all that marks the job as `Failed` and publishes the `LibraryScanFailedDomainEvent`. That decision applies to the mandatory scan jobs: file system discovery, scan diff, content hashing and scan results save. These jobs are transactional in nature, and a failure in any of them means the file state of the library was not committed.
The metadata enrichment phase runs after the scan results save job, once the file state of the library is committed and the books are materialized. The enrichment phase is best-effort: a book whose metadata could not be retrieved is still browsable with its shell metadata (path and filename-derived title), and a crash mid-enrichment must not roll back the already committed scan results, nor hide the successfully enriched books. This was an explicit product decision: partial enrichment survives a crash, and the scan is not considered failed because a remote metadata provider was unreachable or a provider crashed.
## Decision
The metadata enrichment job (`MediaLibraryScanMetadataEnrichmentJob`) is a best-effort job with failure semantics that differ from the mandatory jobs of ADR-0009:
The metadata enrichment job (`MediaLibraryScanMetadataEnrichmentJob`) is a best-effort job with failure semantics that differ from the mandatory jobs of [ADR-0009](architecture-decision-record-0009.md):
- Per-book failures are isolated: a metadata provider that throws, returns unusable metadata, or fails to be applied marks the book as `Failed` (`MetadataStatus.Failed`) and moves to the next book. The other providers are still tried for the same book, and the other books are still processed.
- Per-provider failures are isolated: a crashing metadata provider does not prevent the other providers from being tried, in their configured order.
- The scan is considered completed (`LibraryScanFinishedDomainEvent`) after the enrichment phase, even when some books failed to be enriched. The failure is recorded on the books, not on the scan.
- Only a host-side catastrophic failure of the enrichment job itself (e.g., a storage error) fails the scan, through the existing catch-all of ADR-0009. In that case the file state is already committed, and a re-scan retries the enrichment.
- Only a host-side catastrophic failure of the enrichment job itself (e.g., a storage error) fails the scan, through the existing catch-all of [ADR-0009](architecture-decision-record-0009.md). In that case the file state is already committed, and a re-scan retries the enrichment.
The `MediaLibraryScanResultsSaveJob` no longer publishes `LibraryScanFinishedDomainEvent`. The event is published by the last job of the directed acyclic job graph: the save job when the library does not permit downloading data from the web (no enrichment phase), or the metadata enrichment job otherwise.
## Amendments
- **2026-10-09**: The enrichment phase is now three sequential jobs, and the last job of the graph is the artwork enrichment job.
- `MediaLibraryScanProviderConfigurationInvalidationJob` invalidates the enrichment state of the items whose metadata or artwork providers changed since the last scan, and the metadata derived from the paths when the path template changed.
- `MediaLibraryScanMetadataEnrichmentJob` enriches the metadata and links the media contributors.
- `MediaLibraryScanArtworkEnrichmentJob` resolves the artwork and is always the last job, publishing `LibraryScanFinishedDomainEvent` (see `MediaLibraryScanArtworkEnrichmentJob`).
- **2026-10-09**: The `MediaLibraryScanResultsSaveJob` no longer publishes `LibraryScanFinishedDomainEvent`; it triggers the provider configuration invalidation job. The metadata enrichment semantics described below apply to both the metadata and the artwork enrichment jobs, and across every media library type with enrichers, including music (`MusicMediaLibraryScanMetadataEnricher`, `MusicMediaLibraryScanArtworkEnricher`), not only books.
## Consequences
### Positive Outcomes
@@ -37,7 +45,7 @@ The `MediaLibraryScanResultsSaveJob` no longer publishes `LibraryScanFinishedDom
## Alternatives Considered
### 1. Fail the scan on any enrichment failure
Keep ADR-0009 semantics for the enrichment job.
Keep [ADR-0009](architecture-decision-record-0009.md) semantics for the enrichment job.
**Rejected**: The file state is already committed, and partial enrichment is better than failing a scan that saved the library. Failing the scan would also roll back nothing, while misleading the user about the scan outcome.
@@ -12,7 +12,7 @@ Key constraints that shaped this decision:
1. **Licensing Change**: MediatR became a commercial product for .NET 8+ projects, requiring a paid license for continued use in production systems.
2. **Narrow Usage Scope**: MediatR is used for command and query dispatching, with a single pipeline behavior (automatic application validation) and no stream requests. Its notification publishing is used for domain event publishing, which is outside the scope of this ADR and is replaced separately (see ADR-0013).
2. **Narrow Usage Scope**: MediatR is used for command and query dispatching, with a single pipeline behavior (automatic application validation) and no stream requests. Its notification publishing is used for domain event publishing, which is outside the scope of this ADR and is replaced separately (see [ADR-0013](architecture-decision-record-0013.md)).
3. **Zero Abstraction Value at Scale**: With only a validation pipeline behavior registered, the command and query dispatching provides no runtime value beyond a dispatch indirection that can be replaced by direct handler injection. It actually hurts performance by runtime dispatching of handlers via reflection.
@@ -14,7 +14,7 @@ Domain event publishing, the mechanism that fires the `IDomainEvent` objects rai
3. **Publishing sites**: Mediator's `IPublisher` is used from `EventualConsistencyMiddleware` (queued events, published after the transaction commits), from `MediaLibraryScanningService` (scan start events), and from the scan jobs and `ScanFailurePublisher` (progress and failure events).
The remaining publish half carries the same third-party dependency and source-generated registration that ADR-0011 removed from the dispatch half.
The remaining publish half carries the same third-party dependency and source-generated registration that [ADR-0011](architecture-decision-record-0011.md) removed from the dispatch half.
## Decision
@@ -38,7 +38,7 @@ The existing assembly scan that registers `ICommandHandler<>`, `IQueryHandler<>`
### Consistency Guarantees Preserved
- Commit-before-publish ordering in `EventualConsistencyMiddleware` is unchanged (see ADR-0002).
- Commit-before-publish ordering in `EventualConsistencyMiddleware` is unchanged (see [ADR-0002](architecture-decision-record-0002.md)).
- Re-entrant publishing (a handler publishing another event) is safe: each publish resolves handlers fresh from the scoped provider.
- Jobs publish from their own scopes, so handlers receive a fresh unit of work and `DbContext`.
@@ -73,4 +73,4 @@ Introduce `IIntegrationEvent` now, with a durable outbox, for inter-bounded-cont
Keep the Mediator library for the domain event publishing half.
**Rejected**: for the same reason ADR-0011 rejected it for command and query dispatching - an external dependency, with source-generated registration, for functionality that is fully implementable in-house.
**Rejected**: for the same reason [ADR-0011](architecture-decision-record-0011.md) rejected it for command and query dispatching - an external dependency, with source-generated registration, for functionality that is fully implementable in-house.
@@ -0,0 +1,79 @@
# Architecture Decision Record (ADR): 0015 - Plugin Capability Providers for Media Library Enrichment
## Status
**Accepted** (2026-10-09)
Supersedes [ADR-0008](architecture-decision-record-0008.md).
## Context
[ADR-0008](architecture-decision-record-0008.md) extended the media library scanning subsystem with plugin jobs: it defined named scan job hook points in `ScanJobHooks` and a scan job registry (`IScanJobRegistry` / `ScanJobRegistry`) that mapped a hook name to the plugin job types to splice into the scan job graph at that junction.
That model coupled plugins to the host scan graph. A plugin had to know the internal job model and the junction semantics to contribute anything, the host had to know every plugin job type up front to build the graph, and the resulting graph mixed host jobs and plugin jobs with no clear ownership of the enrichment behavior. It also kept the `HashComparerJob` runtime type switching around, because jobs of different types exchanged differently typed payloads.
What a plugin actually contributes is data: metadata for a media item, artwork for a media item, or the ability to decode a book. Which jobs run, in what order, and how their results are persisted is a host concern that should not be delegated to plugins.
## Decision
Separate plugin capabilities from the host scan graph. Plugins contribute capability providers, and the host owns the graph and decides when to invoke the capabilities.
### Plugin contracts
- `IPlugin` carries the identity of the plugin (`Id`, `Name`, `Author`, `Version`, `Description`) and its settings schema (`GetSettingsSchema()`).
- `IPluginServiceRegistrator` registers the services of the plugin into the host dependency injection container through `RegisterServices(IServiceCollection)`.
### Capability contracts
The host defines the capability contracts, and a plugin implements the ones it supports:
| Capability | Contract | Purpose |
|---|---|---|
| Metadata provider | `IMetadataProvider` | Searches for and returns the metadata of a media item (`GetSearchResultsAsync`, `GetMetadataAsync`), declaring its `SupportedLibraryTypes`, the `LookupType` it accepts, and whether it `RequiresWebAccess` |
| Artwork provider | `IArtworkProvider` | Returns the artwork of a media item (`GetArtworkAsync`), declaring its `SupportedLibraryTypes` and whether it `RequiresWebAccess` |
| Book reader | `IBookReader` | Decodes a book format into a normalized reading document (`OpenAsync`, `GetResourceAsync`), declaring its `SupportedExtensions` and `SupportedLibraryTypes` |
### Registration and selection
- A plugin registers each capability as a keyed transient service, keyed by its plugin `Id` (for example `AddKeyedTransient<IMetadataProvider, MusicBrainzTrackMetadataProvider>(pluginId)`). A single plugin can register several providers, of the same or of different capabilities.
- Plugins contribute zero scan jobs. The scan job graph of each media library type is built entirely by its own scanner from host jobs created through `IMediaLibraryScanJobFactory`.
- The host persists which providers are enabled for each media library and their rank, and exposes that configuration through the media library management endpoints.
- The enrichment jobs resolve the configured, enabled providers of the media library and invoke them in rank order: the metadata enrichment job delegates to `IMediaLibraryScanMetadataEnricher`, the artwork enrichment job delegates to `IMediaLibraryScanArtworkEnricher`, and the results save job delegates to `IMediaLibraryScanItemMaterializer`.
### Removed
`ScanJobHooks`, `IScanJobRegistry` and `ScanJobRegistry` are removed, along with the `HashComparerJob` runtime type switching they depended on. [ADR-0008](architecture-decision-record-0008.md) is superseded.
## Consequences
### Positive Outcomes
| Aspect | Benefit |
|---|---|
| Ownership | Plugins contribute data capabilities; the host owns the scan graph and when to invoke them |
| Decoupling | A plugin depends only on the capability contracts, not on the internal job model or the graph junctions |
| Extensibility | A new plugin adds keyed capability services and no host code, and a plugin can expose several capabilities |
| Per-library control | Providers are enabled and ranked per media library, independent of plugin installation |
| Simplicity | No hook registry, no graph splicing across the plugin boundary, and no runtime payload type switching |
### Risks and Mitigations
| Risk | Mitigation Strategy |
|---|---|
| A plugin registers a capability a library type does not support | Providers declare `SupportedLibraryTypes`, and the host only offers and invokes providers that support the library being processed |
| Two enabled providers return conflicting metadata | Providers are tried in the configured rank order, so precedence is explicit and user controlled |
| A crashing provider fails the enrichment | Enrichment is best effort and isolates provider failures ([ADR-0010](architecture-decision-record-0010.md)), so one provider cannot fail the scan |
## Alternatives Considered
### 1. Keep the scan job hook points and the scan job registry
**Rejected**: it couples plugins to the host scan graph, forces the host to know plugin job types up front, and mixes host and plugin jobs without a clear owner. It is the model this ADR replaces.
### 2. Let plugins register scan jobs directly, without a registry
**Rejected**: it removes the named junction points but keeps the coupling: plugins still have to know the job model, the graph shape and the payload contracts, and the graph still has no single owner.
### 3. Resolve capability providers by convention, without per-library configuration
**Rejected**: enabling and ranking providers per media library is a requirement. It lets a user run several metadata or artwork sources for one library, in a chosen precedence, and turn providers off without uninstalling the plugin.