How shokoanime/shokoserver works
This project is a full-featured server-side application designed to manage large anime collections – it is essentially the “Shoko Server.” It has a heavy emphasis on data modeling, external integrations (with AniDB, TMDB, TraktTV), a rich REST API (supporting multiple API versions), background/scheduled task processing, and integration with external media players such as Plex, Jellyfin, and Kodi. In addition, separate components (such as the tray service and CLI) exist either as alternative user interfaces or as system utilities.
Main components
• API Gateway & REST endpoints: Represent the Shoko.Server/API folder, which is organized by multiple versions (v0, v1, v2, v3) and includes SignalR hubs and Swagger integration. These endpoints serve as the primary interface for external clients.
• Service Layer: Show the backend services implemented in Shoko.Server/Services (for example, AnimeEpisodeService, AnimeGroupService, VideoLocalService) which provide core business functionalities.
• Data Models & Domain Layer: Include the Shoko.Models project that provides all data models (for AniDB, Plex, MediaInfo, etc.) and the extensive mapping, conversion, and repository layers (Repositories folder) which use the repository and unit-of-work patterns.
• Providers & External Integrations: Represent the various providers (in Shoko.Server/Providers) that handle connectivity and data fetching from external services like AniDB, TMDB, and TraktTV. This module is responsible for handling HTTP and UDP connections, rate limiting, and parsing responses.
• Plugin Framework: Highlight the plugin abstraction layer (Shoko.Plugin.Abstractions) and how it facilitates integration with external media player plugins (e.g., Plex, Jellyfin, Kodi).
• User Interfaces / Clients: Illustrate the alternative frontends (CLI – Shoko.CLI, and Tray Service – Shoko.TrayService) that offer different ways to interact or trigger operations.
• Configuration & Dependency Management: Include the configuration files (e.g., Dockerfile, .devcontainer, settings in Shoko.Server/Settings) showing the support for varied deployment environments and dependency injection patterns. The use of NHibernate (and SQL providers for MySQL, SQLite, SQLServer) should be noted in this part.
Relationships and interactions
• Client/Media Players make API calls through the API Gateway.
• The API layer forwards requests to the appropriate business service, such as the AnimeEpisodeService or GroupService.
• Business services interact with repositories to fetch/store data in the underlying database. This layer abstracts over databases like MySQL, SQLite, or SQLServer.
• External integrations (providers) are invoked either directly by services or scheduled jobs to update data from external systems (AniDB, TMDB, TraktTV).
• The Scheduler orchestrates background jobs (e.g., file scans, renaming, image processing) and these tasks may trigger service calls, repository actions, or provider interactions.
• The plugin framework allows media players to communicate or hook into the core system, providing a clear extension point for metadata exchange.
• Real-time updates and notifications using SignalR are sent from the API layer to connected clients.
Architectural patterns/design principles to highlight
• Clear separation of concerns: The project is organized by domain (models, providers, scheduling, repositories, API), which ensures modularity.
• Repository and Unit-of-Work Patterns: Repositories abstract data-access and caching, visible in the multiple directories for both direct and cached repositories.
• Dependency Injection: The configuration files and DI folders (like Shoko.Server/Settings/DI) indicate an emphasis on loosely coupled components.
• Background processing and job scheduling via Quartz.
• Multi-layer architecture, with distinct API, service, data, and integration layers.
• Use of abstraction layers for plugin and external media player integrations.
• Clear labels for each component: API Gateway, Service Layer, Repository/Data Layer, Providers/External Integrations, Scheduling & Job Processing, Plugin Integration, and UI Clients.