diff --git a/README.md b/README.md index 8211b28b..2760ceb3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,19 @@ Stay tuned as we build something amazing together. Lumina is about to light up y P.S. This README is just a spark. Watch it grow into a supernova! ✨ +## Documentation + +For those with technical curiosities, here are some goodies to browse through: +- This application was written following Clean Architecture and Domain Driven Design. Although you've probably seen it countless times before, here is the diagram of how the structure looks like. +- A tree-like schematic of the Lumina's Server Domain layer can be seen [here](./docs/technical/domain/Domain.md). +- The Ubiquitous Language used by Lumina's Server Domain layer can be read [here](./docs/technical/domain/UbiquitousLanguage.md). +- For Software Architects, the architecture documents of Lumina were designed using the [C4 model](https://c4model.com/), therefor, you can visualize: +1. [1 System Context diagram](./docs/technical/architecture/1%20system-context-diagram.svg) +2. [2 Container diagram](./docs/technical/architecture/2%20container-diagram.svg) +3. [3.1 Component Web Client diagram](./docs/technical/architecture/3.1%20component-web-client-diagram.svg) +4. [3.2 Component API Server diagram](./docs/technical/architecture/3.2%20component-api-server-diagram.svg) +5. [4.1 Code media library scanning diagram](./docs/technical/architecture/4.1%20code-media-library-scanning-diagram.svg) + ## Contributing Lumina welcomes community contributions. All forms of input, be it code, bug reports, or feature suggestions, are appreciated. Be sure to read the [guidelines](./docs/CONTRIBUTING.md) for contributing first! diff --git a/docs/technical/architecture/1 system-context-diagram.puml b/docs/technical/architecture/1 system-context-diagram.puml index e48c00f1..acd64d25 100644 --- a/docs/technical/architecture/1 system-context-diagram.puml +++ b/docs/technical/architecture/1 system-context-diagram.puml @@ -1,4 +1,4 @@ -@startuml test +@startuml Lumina System Context Diagram !include LAYOUT_WITH_LEGEND() @@ -7,7 +7,7 @@ title System Context diagram for Lumina Media Library Manager Person(user, "Home User", "A person who wants to manage and stream their personal media collection") Person(admin, "Administrator", "A person who manages the media library system") -System(lumina, "Lumina", "Allows users to organize, manage and stream their personal media content") +System(lumina, "Lumina 1.1", "Allows users to organize, manage and stream their personal media content [detailed in '2 container-diagram.puml']") System_Ext(metadataProvider, "Media Metadata Services", "External services that provide media information and metadata (TMDB, TVDB, GoodReads, MusicBrainz, etc)") diff --git a/docs/technical/architecture/1 system-context-diagram.svg b/docs/technical/architecture/1 system-context-diagram.svg new file mode 100644 index 00000000..6b09f770 --- /dev/null +++ b/docs/technical/architecture/1 system-context-diagram.svg @@ -0,0 +1 @@ +System Context diagram for Lumina Media Library ManagerHome User A person who wants to manageand stream their personalmedia collectionAdministrator A person who manages themedia library systemLumina 1.1 Allows users to organize,manage and stream theirpersonal media content[detailed in '2container-diagram.puml']Media Metadata Services External services that providemedia information andmetadata (TMDB, TVDB,GoodReads, MusicBrainz, etc)Views and streams mediacontentManages media libraryand system settingsRetrieves media metadataand artworkLegend personsystemexternal personexternal system[System Context] LuminaThe system context diagram for the Lumina Media Library Manager - created with PlantUML \ No newline at end of file diff --git a/docs/technical/architecture/2 container-diagram.puml b/docs/technical/architecture/2 container-diagram.puml index 3fabf113..26c852c8 100644 --- a/docs/technical/architecture/2 container-diagram.puml +++ b/docs/technical/architecture/2 container-diagram.puml @@ -2,15 +2,15 @@ !include LAYOUT_WITH_LEGEND() -title Container diagram for Lumina Media Library Manager +title Container diagram for Lumina 1.1 Person(user, "Home User", "A person who wants to manage and stream their personal media collection") Person(admin, "Administrator", "A person who manages the media library system") -System_Boundary(c1, "Lumina") { - Container(webapp, "Web Application Client", "ASP.NET Core MVC", "Delivers server-rendered views with dynamic client-side functionality for media management and playback") +System_Boundary(c1, "Lumina 1.1") { + Container(webapp, "Web Application Client 2.1", "ASP.NET Core MVC", "Delivers server-rendered views with dynamic client-side functionality for media management and playback [detailed in '3.1 component-web-client-diagram.puml']") - Container(api, "API Server", "ASP.NET Core", "Provides media management functionality via a REST API, processes media tasks, and manages metadata synchronization") + Container(api, "API Server 2.2", "ASP.NET Core", "Provides media management functionality via a REST API, processes media tasks, and manages metadata synchronization [detailed in '3.2 component-api-server-diagram.puml']") ContainerDb(db, "Database", "SQLite", "Stores user data, media metadata, library configuration, automated jobs information, etc") @@ -26,7 +26,7 @@ Rel(api, db, "Reads from and writes to", "SQL") Rel(api, filestore, "Reads from and writes to") Rel(api, metadata, "Retrieves metadata from", "HTTPS") -caption [Container] Lumina +caption [Container] Lumina 1.1 -footer The container diagram for the Lumina Media Library Manager - created with PlantUML +footer The container diagram for the Lumina 1.1 - created with PlantUML @enduml diff --git a/docs/technical/architecture/2 container-diagram.svg b/docs/technical/architecture/2 container-diagram.svg new file mode 100644 index 00000000..6d54a096 --- /dev/null +++ b/docs/technical/architecture/2 container-diagram.svg @@ -0,0 +1 @@ +Container diagram for Lumina 1.1Lumina 1.1[System]Web Application Client 2.1[ASP.NET Core MVC] Delivers server-rendered viewswith dynamic client-sidefunctionality for mediamanagement and playback[detailed in '3.1component-web-client-diagram.puml']API Server 2.2[ASP.NET Core] Provides media managementfunctionality via a REST API,processes media tasks, andmanages metadatasynchronization [detailed in '3.2component-api-server-diagram.puml']Database[SQLite] Stores user data, mediametadata, library configuration,automated jobs information, etcMedia Store[File System] Stores the actual media filesHome User A person who wants to manageand stream their personalmedia collectionAdministrator A person who manages themedia library systemMedia InformationServices External services like TMDB,TVDB, GoodReads,MusicBrainz, that provide mediametadataUses[HTTPS]Manages media libraryand system settings[HTTPS]Makes API calls to[JSON/HTTPS]Reads from and writes to[SQL]Reads from and writes toRetrieves metadata from[HTTPS]Legend personsystemcontainerexternal personexternal systemexternal container[Container] Lumina 1.1The container diagram for the Lumina 1.1 - created with PlantUML \ No newline at end of file diff --git a/docs/technical/architecture/3.1 component-web-client-diagram.puml b/docs/technical/architecture/3.1 component-web-client-diagram.puml index 132b6072..6cac77f4 100644 --- a/docs/technical/architecture/3.1 component-web-client-diagram.puml +++ b/docs/technical/architecture/3.1 component-web-client-diagram.puml @@ -2,11 +2,11 @@ !include LAYOUT_WITH_LEGEND() -title Component diagram for Lumina Web Application Client +title Component diagram for Lumina Web Application Client 2.1 -Container_Ext(api, "API Server", "Lumina.Presentation.Api", "Provides media management functionality via JSON/HTTPS API") +Container_Ext(api, "API Server 2.2", "Lumina.Presentation.Api", "Provides media management functionality via JSON/HTTPS API [detailed in '3.2 component-api-server-diagram.puml']") -Container_Boundary(wb, "Web Application") { +Container_Boundary(wb, "Web Application 2.1") { Component(fileSystem, "File System Management", "ASP.NET MVC Controllers", "Handles file system operations including drives, directories, and files browsing") Component(library, "Library Management", "ASP.NET MVC Controllers", "Manages media libraries and their content (books, etc)") @@ -30,7 +30,7 @@ Rel(clientJs, library, "Makes AJAX calls to") Rel(clientJs, admin, "Makes AJAX calls to") Rel(clientJs, users, "Makes AJAX calls to") -caption [Component] Lumina - Web Application (Lumina.Presentation.Web) +caption [Component] Lumina - Web Application Client 2.1 (Lumina.Presentation.Web) -footer The component diagram for the Lumina Web Application Client - created with PlantUML +footer The component diagram for the Lumina Web Application Client 2.1 - created with PlantUML @enduml \ No newline at end of file diff --git a/docs/technical/architecture/3.1 component-web-client-diagram.svg b/docs/technical/architecture/3.1 component-web-client-diagram.svg new file mode 100644 index 00000000..2468239d --- /dev/null +++ b/docs/technical/architecture/3.1 component-web-client-diagram.svg @@ -0,0 +1 @@ +Component diagram for Lumina Web Application Client 2.1Web Application 2.1[Container]File System Management[ASP.NET MVC Controllers] Handles file system operationsincluding drives, directories,and files browsingLibrary Management[ASP.NET MVC Controllers] Manages media libraries andtheir content (books, etc)Administration[ASP.NET MVC Controllers] Handles system administrationand configurationUser Management[ASP.NET MVC Controllers] Handles authentication anduser managementClient-Side Logic[JavaScript] Handles dynamic page updatesand persistent media playbackAPI HTTP Client[C# TypedHttpClient] Handles communication withthe API serverAPI Server 2.2[Lumina.Presentation.Api] Provides media managementfunctionality via JSON/HTTPSAPI [detailed in '3.2component-api-server-diagram.puml']UsesUsesUsesUsesMakes API calls to[JSON/HTTPS]Makes AJAX calls toMakes AJAX calls toMakes AJAX calls toMakes AJAX calls toLegend personsystemcontainercomponentexternal personexternal systemexternal containerexternal component[Component] Lumina - Web Application Client 2.1 (Lumina.Presentation.Web)The component diagram for the Lumina Web Application Client 2.1 - created with PlantUML \ No newline at end of file diff --git a/docs/technical/architecture/3.2 component-server-diagram.puml b/docs/technical/architecture/3.2 component-api-server-diagram.puml similarity index 69% rename from docs/technical/architecture/3.2 component-server-diagram.puml rename to docs/technical/architecture/3.2 component-api-server-diagram.puml index c30abb52..e6230aea 100644 --- a/docs/technical/architecture/3.2 component-server-diagram.puml +++ b/docs/technical/architecture/3.2 component-api-server-diagram.puml @@ -2,11 +2,11 @@ !include LAYOUT_WITH_LEGEND() -title Component diagram for Lumina API Server +title Component diagram for Lumina API Server 2.2 -Container_Ext(webapp, "Web Application Client", "Lumina.Presentation.Web", "Provides the user interface") +Container_Ext(webapp, "Web Application Client 2.1", "Lumina.Presentation.Web", "Provides the user interface [detailed in '3.1 component-web-client-diagram.puml']") -Container_Boundary(api, "API Application") { +Container_Boundary(api, "API Server 2.2") { Component(endpoints, "API Endpoints", "FastEndpoints", "Provides REST API endpoints for media management and streaming") Component(mediaManagement, "Media Library Management", "Domain Services", "Handles media libraries operations and metadata management") @@ -15,7 +15,7 @@ Container_Boundary(api, "API Application") { Component(fileSystem, "File System Management", "Domain Services", "Manages file system operations and media access") - Component(backgroundServices, "Background Services", ".NET Worker Services", "Handles media scanning, metadata synchronization and other maintenance tasks") + Component(backgroundServices, "Background Services 3.2.1", ".NET Worker Services", "Handles media scanning, metadata synchronization and other maintenance tasks [detailed in '4.1 code-media-library-scanning-diagram.puml']") Component(repositories, "Repositories", "EF Core", "Provides data access abstraction for domain entities") } @@ -35,7 +35,7 @@ Rel(backgroundServices, mediaManagement, "Uses") Rel(repositories, db, "Reads from and writes to", "SQL") Rel(mediaManagement, metadataServices, "Retrieves metadata from", "HTTPS") -caption [Component] Lumina - API Server (Lumina.Presentation.Api) +caption [Component] Lumina - API Server 2.2 (Lumina.Presentation.Api) -footer The component diagram for the Lumina API Server - created with PlantUML +footer The component diagram for the Lumina API Server 2.2 - created with PlantUML @enduml diff --git a/docs/technical/architecture/3.2 component-api-server-diagram.svg b/docs/technical/architecture/3.2 component-api-server-diagram.svg new file mode 100644 index 00000000..62d32557 --- /dev/null +++ b/docs/technical/architecture/3.2 component-api-server-diagram.svg @@ -0,0 +1 @@ +Component diagram for Lumina API Server 2.2API Server 2.2[Container]API Endpoints[FastEndpoints] Provides REST API endpointsfor media management andstreamingMedia LibraryManagement[Domain Services] Handles media librariesoperations and metadatamanagementUser Management[Domain Services] Handles user authenticationand authorizationFile System Management[Domain Services] Manages file system operationsand media accessBackground Services3.2.1[.NET Worker Services] Handles media scanning,metadata synchronization andother maintenance tasks[detailed in '4.1code-media-library-scanning-diagram.puml']Repositories[EF Core] Provides data accessabstraction for domain entitiesWeb Application Client 2.1[Lumina.Presentation.Web] Provides the user interface[detailed in '3.1component-web-client-diagram.puml']Database[SQLite] Stores user data, mediametadata, and systemconfigurationExternal MetadataServices Provides media information(TMDB, TVDB, GoodReads,MusicBrainz, etc)Makes API calls to[JSON/HTTPS]UsesUsesUsesUsesUsesUsesUsesReads from and writes to[SQL]Retrieves metadata from[HTTPS]Legend personsystemcontainercomponentexternal personexternal systemexternal containerexternal component[Component] Lumina - API Server 2.2 (Lumina.Presentation.Api)The component diagram for the Lumina API Server 2.2 - created with PlantUML \ No newline at end of file diff --git a/docs/technical/architecture/4.1 code-media-library-scanning-diagram.puml b/docs/technical/architecture/4.1 code-media-library-scanning-diagram.puml new file mode 100644 index 00000000..ad491da6 --- /dev/null +++ b/docs/technical/architecture/4.1 code-media-library-scanning-diagram.puml @@ -0,0 +1,137 @@ +@startuml Media Library Scanning System Code +!include + +LAYOUT_WITH_LEGEND() +title Code diagram for Background Services 3.2.1 + +skinparam class { + BackgroundColor White + BorderColor Black +} + +abstract class MediaLibraryScanJob { + + ScanId: Guid + + UserId: Guid + + Library: Library + + Status: LibraryScanJobStatus + # parentsPayloadsExecuted: int + + Children: List + + Parents: List + + AddChild(job: MediaLibraryScanJob) + + AddParent(job: MediaLibraryScanJob) + + {abstract} ExecuteAsync(id: Guid, input: TInput, token: CancellationToken): Task +} + +note right of MediaLibraryScanJob + Base class for all scan jobs that defines the parent-child + relationship and execution pattern +end note + +class HashComparerJob { + + ExecuteAsync(id: Guid, input: TInput, token: CancellationToken): Task +} + +class FileSystemDiscoveryJob { + ExecuteAsync(id: Guid, input: TInput, token: CancellationToken): Task +} + +class RepositoryMetadataDiscoveryJob { + ExecuteAsync(id: Guid, input: TInput, token: CancellationToken): Task +} + +class GoodReadsMetadataScrapJob { + ExecuteAsync(id: Guid, input: TInput, token: CancellationToken): Task +} + +interface IMediaTypeScanner { + + SupportedType: LibraryType + + CreateScanJobsForLibrary(library: Library): IEnumerable +} + +note top of IMediaTypeScanner + Determine the library type (audio, video, etc) and create a scanner for that particular type +end note + +interface IBookLibraryTypeScanner { +} + +class BookLibraryTypeScanner { + - _mediaScanJobFactory: IMediaLibraryScanJobFactory + + SupportedType: LibraryType + + CreateScanJobsForLibrary(library: Library): IEnumerable +} + +class MediaLibraryScanningService { + - _mediaScanQueue: IMediaLibrariesScanQueue + - _libraryScannerFactory: IMediaLibraryScannerFactory + - _librariesScanTracker: IMediaLibrariesScanTracker + - _currentUserService: ICurrentUserService + + StartScanAsync(library: Library, token: CancellationToken): Task + + CancelScan(scanId: Guid) +} + +note top of MediaLibraryScanningService + Central service for managing execution and cancellation of media library scans +end note + +class MediaLibrariesScanQueue { + - _channel: Channel + + Writer: ChannelWriter + + Reader: ChannelReader +} + +note bottom of MediaLibrariesScanQueue + In-memory queue of media library scan jobs +end note + +class MediaLibraryScanJobProcessorJob { + - _mediaScanQueue: IMediaLibrariesScanQueue + - _librariesScanTracker: IMediaLibrariesScanTracker + # ExecuteAsync(token: CancellationToken): Task +} + +note top of MediaLibraryScanJobProcessorJob + Launch the payload execution of scan jobs that arrive on the in-memory queue +end note + +class MediaLibrariesScanTracker { + - _runningScans: ConcurrentDictionary + + RegisterScan(scanId: Guid, userId: Guid) + + GetTokenForScan(scanId: Guid, userId: Guid): CancellationToken + + CancelScan(scanId: Guid, userId: Guid) + + CancelUserScans(userId: Guid) + + Dispose() +} + +note bottom of MediaLibrariesScanTracker + Track the state of each running scan job and allow for cancelling at any time +end note + +MediaLibraryScanJob <|-- HashComparerJob : inherits +MediaLibraryScanJob <|-- FileSystemDiscoveryJob : inherits +MediaLibraryScanJob <|-- RepositoryMetadataDiscoveryJob : inherits +MediaLibraryScanJob <|-- GoodReadsMetadataScrapJob : inherits + +FileSystemDiscoveryJob ..> HashComparerJob : triggers +RepositoryMetadataDiscoveryJob ..> HashComparerJob : triggers +HashComparerJob ..> GoodReadsMetadataScrapJob : triggers + +IMediaTypeScanner <|-- IBookLibraryTypeScanner +IBookLibraryTypeScanner <|.. BookLibraryTypeScanner + +MediaLibraryScanningService --> IMediaTypeScanner : uses +MediaLibraryScanningService --> MediaLibrariesScanQueue : writes to +MediaLibraryScanningService --> MediaLibrariesScanTracker : uses + +MediaLibraryScanJobProcessorJob --> MediaLibrariesScanQueue : reads from +MediaLibraryScanJobProcessorJob --> MediaLibrariesScanTracker : uses + +BookLibraryTypeScanner ..> MediaLibraryScanJob : creates + +MediaLibraryScanJobProcessorJob ..> FileSystemDiscoveryJob : triggers +MediaLibraryScanJobProcessorJob ..> RepositoryMetadataDiscoveryJob : triggers + +caption [Code] Lumina - Background Services 3.2.1 + +footer The code diagram for the Background Services 3.2.1 - created with PlantUML +@enduml diff --git a/docs/technical/architecture/4.1 code-media-library-scanning-diagram.svg b/docs/technical/architecture/4.1 code-media-library-scanning-diagram.svg new file mode 100644 index 00000000..9e2ac5e4 --- /dev/null +++ b/docs/technical/architecture/4.1 code-media-library-scanning-diagram.svg @@ -0,0 +1 @@ +Code diagram for Background Services 3.2.1MediaLibraryScanJobScanId: GuidUserId: GuidLibrary: LibraryStatus: LibraryScanJobStatusparentsPayloadsExecuted: intChildren:List<MediaLibraryScanJob>Parents:List<MediaLibraryScanJob>AddChild(job:MediaLibraryScanJob)AddParent(job:MediaLibraryScanJob)ExecuteAsync<TInput>(id:Guid, input: TInput, token:CancellationToken): TaskBase class for all scan jobs thatdefines the parent-childrelationship and execution patternHashComparerJobExecuteAsync<TInput>(id:Guid, input: TInput, token:CancellationToken): TaskFileSystemDiscoveryJobExecuteAsync<TInput>(id:Guid, input: TInput, token:CancellationToken): TaskRepositoryMetadataDiscoveryJobExecuteAsync<TInput>(id:Guid, input: TInput, token:CancellationToken): TaskGoodReadsMetadataScrapJobExecuteAsync<TInput>(id:Guid, input: TInput, token:CancellationToken): TaskIMediaTypeScannerSupportedType: LibraryTypeCreateScanJobsForLibrary(library:Library):IEnumerable<MediaLibraryScanJob>Determine the library type (audio,video, etc) and create a scannerfor that particular typeIBookLibraryTypeScannerBookLibraryTypeScanner_mediaScanJobFactory:IMediaLibraryScanJobFactorySupportedType: LibraryTypeCreateScanJobsForLibrary(library:Library):IEnumerable<MediaLibraryScanJob>MediaLibraryScanningService_mediaScanQueue:IMediaLibrariesScanQueue_libraryScannerFactory:IMediaLibraryScannerFactory_librariesScanTracker:IMediaLibrariesScanTracker_currentUserService:ICurrentUserServiceStartScanAsync(library: Library,token: CancellationToken):Task<Guid>CancelScan(scanId: Guid)Central service for managingexecution and cancellation ofmedia library scansMediaLibrariesScanQueue_channel:Channel<MediaLibraryScanJob>Writer:ChannelWriter<MediaLibraryScanJob>Reader:ChannelReader<MediaLibraryScanJob>In-memory queue of media libraryscan jobsMediaLibraryScanJobProcessorJob_mediaScanQueue:IMediaLibrariesScanQueue_librariesScanTracker:IMediaLibrariesScanTrackerExecuteAsync(token:CancellationToken): TaskLaunch the payload execution ofscan jobs that arrive on thein-memory queueMediaLibrariesScanTracker_runningScans:ConcurrentDictionary<MediaScanTrackerModel,CancellationTokenSource>RegisterScan(scanId: Guid,userId: Guid)GetTokenForScan(scanId:Guid, userId: Guid):CancellationTokenCancelScan(scanId: Guid,userId: Guid)CancelUserScans(userId: Guid)Dispose()Track the state of each runningscan job and allow for cancellingat any timeinheritsinheritsinheritsinheritstriggerstriggerstriggersuseswrites tousesreads fromusescreatestriggerstriggersLegend personsystemcontainercomponentexternal personexternal systemexternal containerexternal component[Code] Lumina - Background Services 3.2.1The code diagram for the Background Services 3.2.1 - created with PlantUML \ No newline at end of file