LogoRiven Wiki

Architecture

Understanding how Riven works under the hood

Architecture Overview

Riven is a comprehensive media management and streaming solution that automates the entire process of discovering, acquiring, and organizing media content for streaming through your media server.


System Components

Riven consists of several key components that work together:

1. Backend (Python)

  • Built with FastAPI
  • PostgreSQL database for state management
  • Service-oriented architecture
  • RESTful API for frontend communication
  • Scheduler for automated tasks

2. Frontend (SvelteKit)

  • Modern Svelte-based web interface
  • Configuration management
  • Media browsing and search
  • Role based access control (in development)
  • Sqlite database for user management (different from backend database)

3. RivenVFS (FUSE Filesystem)

  • Virtual filesystem for media streaming
  • Built-in caching and prefetching
  • Direct integration with debrid services
  • No external dependencies (replaces rclone/zurg/decypharr)

4. Database (PostgreSQL)

  • Media item state tracking
  • Filesystem entry management
  • Settings storage
  • Stream metadata

Workflow Architecture

Here's how Riven processes media from request to streaming:


State Machine

Riven has a main MediaItem table and Movie and Show tables with foregin key relationship to MediaItem. There are 2 more tables Episode and Season. Episode has foregin key relationship to Season & MediaItem and Season has foregin key relationship to Show & MediaItem.

Movie, Show, Episode, Season all just store the relationship & ids of the media item.

Each media item has it's own state, so a specific season can be completed but the show can be in ongoing state. The states can be seen below:

StateDescription
UnknownUnknown state of the media
UnreleasedItem has not been released yet
OngoingItem is ongoing
RequestedItem has been requested from content service
IndexedMetadata has been fetched from TMDB/TVDB
ScrapedTorrents have been found and ranked
DownloadedTorrent added to debrid service
SymlinkedFile available and registered in VFS
CompletedMedia servers have been notified
PartiallyCompletedAll the sub-items are not completed
FailedProcessing failed (requires manual intervention)
PausedProcessing paused by user.
Requested → Indexed → Scraped → Downloaded → Completed → Symlinked → Completed

There are additional states like

  • Unreleased - If item is not released it will go from Requested -> Indexed -> Unreleased
  • Ongoing - If item is ongoing it will go from Requested -> Indexed -> .... -> Symlinked -> Ongoing
  • PartiallyCompleted - If item is partially completed it will go from Requested -> Indexed -> .... -> Symlinked -> PartiallyCompleted

States can transition back on failures:

  • Scraped → Failed (if no suitable torrents found)
  • Failed → Scraped (on manual retry)
  • Completed → Scraped (if file deleted from debrid)

Service Architecture

Riven uses a modular service-oriented architecture. Each service is independent and can be enabled/disabled individually.

Content Services

Discover new media to add to your library:

  • Overseerr: Request management system
  • Plex Watchlist: RSS-based watchlist integration
  • Mdblist: Curated media lists
  • Listrr: Trakt list manager
  • Trakt: Watchlists, collections, trending, popular

Scraper Services

Find torrents for requested media:

  • Torrentio: Popular Stremio addon
  • Jackett: Torrent indexer aggregator
  • Prowlarr: Indexer manager
  • Zilean: DMM hash lookup
  • Comet: Debrid-optimized scraper
  • Mediafusion: Multi-source aggregator
  • Orionoid: Premium torrent search
  • Rarbg: Torrent database search

Downloader Services

Add torrents to debrid services:

  • Real-Debrid
  • AllDebrid
  • Debrid-Link

Updater Services

Notify media servers of new content:

  • Plex: Plex Media Server integration
  • Jellyfin: Open-source media server
  • Emby: Feature-rich media server

Post-Processing Services

Enhance downloaded media:

  • Subtitle Service: Fetch subtitles from various providers
  • Media Analysis: Analyze media files for metadata

Database Schema (Simplified)

MediaItem

Core entity representing a movie, show, season, or episode:

ColumnData Type
idinteger
imdb_idcharacter varying
tvdb_idcharacter varying
tmdb_idcharacter varying
titlecharacter varying
poster_pathcharacter varying
typecharacter varying
requested_attimestamp without time zone
requested_bycharacter varying
requested_idinteger
indexed_attimestamp without time zone
scraped_attimestamp without time zone
scraped_timesinteger
active_streamjson
aliasesjson
is_animeboolean
networkcharacter varying
countrycharacter varying
languagecharacter varying
aired_attimestamp without time zone
yearinteger
genresjson
ratingdouble precision
content_ratingcharacter varying
updatedboolean
guidcharacter varying
overseerr_idinteger
last_stateUSER-DEFINED (States enum)
failed_attemptsinteger

FilesystemEntry

Represents a file in the VFS:

ColumnData Type
idinteger
entry_typecharacter varying
file_sizebigint
is_directoryboolean
created_attimestamp without time zone
updated_attimestamp without time zone
available_in_vfsboolean
media_item_idinteger (foreign key)

MediaEntry

Represents a media file entry from a debrid service:

ColumnData Type
idinteger
original_filenamecharacter varying
download_urlcharacter varying
unrestricted_urlcharacter varying
providercharacter varying
provider_download_idcharacter varying
library_profilesjson
media_metadatajson

Show

Represents a TV show:

ColumnData Type
idinteger
tvdb_statuscharacter varying
release_datajson

Season

Represents a season of a TV show:

ColumnData Type
idinteger
numberinteger
parent_idinteger

Episode

Represents an episode of a TV show:

ColumnData Type
idinteger
numberinteger
parent_idinteger
absolute_numberinteger

Stream

Represents a torrent/magnet link:

ColumnData Type
idinteger
infohashcharacter varying
raw_titlecharacter varying
parsed_titlecharacter varying
rankinteger
lev_ratiodouble precision
resolutioncharacter varying

StreamBlacklistRelation

Represents a blacklisted stream for a media item:

ColumnData Type
idinteger
media_item_idinteger
stream_idinteger

StreamRelation

Represents parent-child relationship between streams:

ColumnData Type
idinteger
parent_idinteger
child_idinteger

ScheduledTask

Represents a scheduled task for media item:

ColumnData Type
idinteger
item_idinteger
task_typecharacter varying
scheduled_fortimestamp without time zone
statusUSER-DEFINED
created_attimestamp without time zone
executed_attimestamp without time zone
reasoncharacter varying
offset_secondsinteger

SubtitleEntry

Represents a subtitle file:

ColumnData Type
idinteger
languagecharacter varying
parent_original_filenamecharacter varying
contenttext
file_hashcharacter varying
video_file_sizebigint
opensubtitles_idcharacter varying

RivenVFS Architecture

RivenVFS is a FUSE (Filesystem in Userspace) implementation that acts as a virtual filesystem for media files.

This is under continuous development and rapid changes are expected.


Configuration Management

Riven supports multiple configuration methods:

  1. Web Interface (primary)

    • User-friendly settings UI
    • Real-time validation
    • Stored in settings file
  2. Environment Variables

    • Prefix: RIVEN_
    • Format: RIVEN_CATEGORY_SUBCATEGORY_SETTING
    • Example: RIVEN_FILESYSTEM_MOUNT_PATH=/mount
  3. Settings File

    • JSON-based configuration

Priority: Environment Variables > Settings File > Defaults


Development Architecture

Backend

  • Language: Python 3.12+
  • Framework: FastAPI
  • ORM: SQLAlchemy
  • Database Migrations: Alembic
  • Task Scheduling: APScheduler
  • Async: asyncio, trio (for FUSE)

Frontend

  • Framework: Sveltekit 2 & Svelte 5
  • Language: TypeScript
  • UI Library: Shadcn/UI

Build & Deploy

  • Backend & Frontend: Docker multi-stage builds
  • Database: PostgreSQL 17

Monitoring & Logging

Logging Levels

  • INFO: Standard operations
  • DEBUG: Detailed debugging info
  • WARNING: Non-critical issues
  • ERROR: Critical failures
  • CRITICAL: Critical failures
  • TRACE: Tracing info

Health Checks

  • Database connectivity
  • VFS mount status
  • Debrid service availability
  • Media server connectivity

On this page