# jellyfin/jellyfin-plugin-tvheadend architecture

> Architecture diagram of the GitHub repository jellyfin/jellyfin-plugin-tvheadend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jellyfin/jellyfin-plugin-tvheadend
- Repository: https://github.com/jellyfin/jellyfin-plugin-tvheadend

## Overview

1. This repository is a Jellyfin server plugin that acts as a bridge to a TVHeadend backend. The architectural boundary is: Jellyfin on one side, TVHeadend on the other, with this plugin translating between Jellyfin’s plugin/service model and TVHeadend’s HTSP protocol.

2. The plugin entry point is centered around `Plugin.cs`, `ServiceRegistrator.cs`, and `LiveTvService.cs`. These files are the main integration surface with Jellyfin: they register services, expose plugin metadata/configuration, and provide the live-TV functionality Jellyfin consumes.

3. The core backend connection layer is split into `HTSConnectionHandler.cs` and the `HTSP/` folder. This is the transport/protocol subsystem responsible for opening and maintaining the connection to TVHeadend, sending requests, and receiving responses asynchronously.

4. `HTSP/HTSConnectionAsync.cs`, `HTSP/HTSConnectionListener.cs`, `HTSP/HTSMessage.cs`, and `HTSP/HTSResponseHandler.cs` form the protocol stack. The design suggests a message-based async client: one part handles socket/listener behavior, one part models messages, and one part dispatches responses back to typed handlers.

5. The `HTSP_Responses/` folder contains response-specific handlers such as `GetEventsResponseHandler.cs` and `LoopBackResponseHandler.cs`. This indicates a command/response pattern where protocol replies are parsed and routed to specialized processors rather than handled in a single monolithic connection class.

6. The `DataHelper/` folder is the domain-mapping layer. `ChannelDataHelper.cs`, `DvrDataHelper.cs`, `AutorecDataHelper.cs`, and `TunerDataHelper.cs` appear to transform TVHeadend data into the shapes Jellyfin expects for channels, DVR/recordings, autorecord rules, and tuner status.

7. `RecordingsChannel.cs` and `AccessTicketHandler.cs` suggest additional domain concerns beyond basic channel listing. `RecordingsChannel` likely exposes recorded content as a dedicated logical channel/source, while `AccessTicketHandler` likely manages TVHeadend ticket or token-based access for stream or recording URLs.

8. `Configuration/PluginConfiguration.cs` is the persistent plugin settings model. This is the boundary for user-configurable TVHeadend connection details and plugin behavior, separating runtime protocol logic from configuration stored by Jellyfin.

9. `Web/tvheadend.html` and `Web/tvheadend.js` provide the plugin’s configuration UI inside Jellyfin’s admin surface. This is the only front-end artifact in the repo, and it is narrowly scoped to settings/editing rather than a standalone web application.

10. The `Helper/` and `TimeoutHelper/` folders are infrastructure utilities that support the main flow. They include low-level buffer and queue primitives, SHA1/date helpers, and timeout wrappers, which indicate the plugin needs careful protocol framing, hashing, and bounded waits around backend calls.

11. Overall data flow is: Jellyfin invokes plugin services, services consult configuration, the plugin opens/maintains an HTSP session to TVHeadend, response handlers parse backend replies, data helpers adapt those replies into Jellyfin-facing models, and web assets allow administrators to configure the bridge.

12. Operationally, this is a .NET 8 plugin project (`TVHeadEnd.csproj`) intended to be published as a DLL and dropped into Jellyfin’s plugins folder. The GitHub Actions files are build/test/publish automation around that packaging flow, not part of the runtime architecture.

Main entry points: [`TVHeadEnd/HTSConnectionHandler.cs`](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSConnectionHandler.cs) (Connection handler), [`TVHeadEnd/LiveTvService.cs`](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/LiveTvService.cs) (Live TV), [`TVHeadEnd/Plugin.cs`](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Plugin.cs) (Plugin), [`TVHeadEnd/HTSP/HTSResponseHandler.cs`](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSResponseHandler.cs) (Response router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Jellyfin integration"]
  node_n1["Plugin<br/>entry point<br/>[Plugin.cs]"]
  node_n2["Services<br/>registrar"]
  node_n3["Live TV<br/>[LiveTvService.cs]"]
  node_n4["Recordings<br/>channel"]
  node_n5["Access tickets<br/>auth helper"]
  node_n6["Config<br/>settings model"]
end

subgraph group_g2["HTSP backend"]
  node_n7["Connection handler<br/>session manager"]
  node_n8["Async client<br/>protocol client"]
  node_n9["Listener"]
  node_n10["HTSP message<br/>protocol model<br/>[HTSMessage.cs]"]
  node_n11["Response router<br/>dispatch layer"]
  node_n12["Events handler<br/>response handler"]
  node_n13["Loopback handler<br/>response handler"]
end

subgraph group_g3["Domain mapping"]
  node_n14["Channels<br/>mapper"]
  node_n15["DVR<br/>mapper<br/>[DvrDataHelper.cs]"]
  node_n16["Autorec<br/>mapper"]
  node_n17["Tuners<br/>mapper<br/>[TunerDataHelper.cs]"]
end

subgraph group_g4["Support utilities"]
  node_n18["Buffers<br/>low-level utils<br/>[ByteBuffer.cs]"]
  node_n19["Helpers<br/>shared utils<br/>[DateTimeHelper.cs]"]
  node_n20["Timeouts<br/>async guard"]
end

subgraph group_g5["Admin UI"]
  node_n21["Admin page<br/>config UI<br/>[tvheadend.html]"]
  node_n22["Admin script<br/>ui script<br/>[tvheadend.js]"]
end

node_n1 -->|"registers"| node_n2
node_n1 -->|"uses"| node_n6
node_n2 -->|"wires"| node_n3
node_n3 -->|"connects"| node_n7
node_n3 -->|"serves"| node_n4
node_n3 -->|"authorizes"| node_n5
node_n7 -->|"drives"| node_n8
node_n7 -->|"listens"| node_n9
node_n8 -->|"formats"| node_n10
node_n9 -->|"dispatches"| node_n11
node_n11 -->|"routes"| node_n12
node_n11 -->|"routes"| node_n13
node_n12 -->|"feeds"| node_n14
node_n12 -->|"feeds"| node_n15
node_n15 -->|"relates"| node_n16
node_n7 -->|"uses"| node_n18
node_n7 -->|"uses"| node_n19
node_n7 -->|"bounds"| node_n20
node_n1 -->|"hosts"| node_n21
node_n21 -->|"drives"| node_n22
node_n22 -->|"edits"| node_n6
node_n6 -->|"configures"| node_n7
node_n14 -->|"supports"| node_n3
node_n15 -->|"supports"| node_n4
node_n16 -->|"supports"| node_n3
node_n17 -->|"supports"| node_n3

click node_n1 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Plugin.cs"
click node_n2 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/ServiceRegistrator.cs"
click node_n3 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/LiveTvService.cs"
click node_n4 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/RecordingsChannel.cs"
click node_n5 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/AccessTicketHandler.cs"
click node_n6 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Configuration/PluginConfiguration.cs"
click node_n7 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSConnectionHandler.cs"
click node_n8 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSConnectionAsync.cs"
click node_n9 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSConnectionListener.cs"
click node_n10 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSMessage.cs"
click node_n11 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSResponseHandler.cs"
click node_n12 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP_Responses/GetEventsResponseHandler.cs"
click node_n13 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP_Responses/LoopBackResponseHandler.cs"
click node_n14 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/ChannelDataHelper.cs"
click node_n15 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/DvrDataHelper.cs"
click node_n16 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/AutorecDataHelper.cs"
click node_n17 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/TunerDataHelper.cs"
click node_n18 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Helper/ByteBuffer.cs"
click node_n19 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Helper/DateTimeHelper.cs"
click node_n20 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/TimeoutHelper/TaskWithTimeoutRunner.cs"
click node_n21 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Web/tvheadend.html"
click node_n22 "https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Web/tvheadend.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2,node_n3,node_n4,node_n5,node_n6 toneBlue
class node_n7,node_n8,node_n9,node_n10,node_n11,node_n12,node_n13 toneAmber
class node_n14,node_n15,node_n16,node_n17 toneMint
class node_n18,node_n19,node_n20 toneRose
class node_n21,node_n22 toneIndigo
```

## Components

### Jellyfin integration

Plugin entry points and Jellyfin-facing live TV services.

- [Plugin](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Plugin.cs): entry point · Jellyfin plugin metadata, lifecycle, and top-level integration. · `TVHeadEnd/Plugin.cs`
- [Services](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/ServiceRegistrator.cs): registrar · Registers plugin services into Jellyfin's container. · `TVHeadEnd/ServiceRegistrator.cs`
- [Live TV](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/LiveTvService.cs): service · Main Jellyfin live-TV surface exposed by the plugin. · `TVHeadEnd/LiveTvService.cs`
- [Recordings](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/RecordingsChannel.cs): channel · Logical recordings source/channel exposed to Jellyfin. · `TVHeadEnd/RecordingsChannel.cs`
- [Access tickets](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/AccessTicketHandler.cs): auth helper · Manages TVHeadend access tickets for stream and recording URLs. · `TVHeadEnd/AccessTicketHandler.cs`
- [Config](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Configuration/PluginConfiguration.cs): settings model · Persistent plugin configuration stored by Jellyfin. · `TVHeadEnd/Configuration/PluginConfiguration.cs`

### HTSP backend

Transport and protocol stack for talking to TVHeadend.

- [Connection handler](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSConnectionHandler.cs): session manager · Coordinates backend connectivity and higher-level connection behavior. · `TVHeadEnd/HTSConnectionHandler.cs`
- [Async client](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSConnectionAsync.cs): protocol client · Asynchronous HTSP connection and request execution. · `TVHeadEnd/HTSP/HTSConnectionAsync.cs`
- [Listener](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSConnectionListener.cs): socket listener · Receives backend data and drives protocol event handling. · `TVHeadEnd/HTSP/HTSConnectionListener.cs`
- [HTSP message](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSMessage.cs): protocol model · Represents HTSP requests, replies, and payload framing. · `TVHeadEnd/HTSP/HTSMessage.cs`
- [Response router](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP/HTSResponseHandler.cs): dispatch layer · Maps protocol responses to typed handlers. · `TVHeadEnd/HTSP/HTSResponseHandler.cs`
- [Events handler](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP_Responses/GetEventsResponseHandler.cs): response handler · Processes event-related HTSP responses. · `TVHeadEnd/HTSP_Responses/GetEventsResponseHandler.cs`
- [Loopback handler](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/HTSP_Responses/LoopBackResponseHandler.cs): response handler · Handles loopback or ping-style protocol responses. · `TVHeadEnd/HTSP_Responses/LoopBackResponseHandler.cs`

### Domain mapping

Transforms TVHeadend payloads into Jellyfin-facing shapes.

- [Channels](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/ChannelDataHelper.cs): mapper · Maps TVHeadend channel data into Jellyfin channel models. · `TVHeadEnd/DataHelper/ChannelDataHelper.cs`
- [DVR](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/DvrDataHelper.cs): mapper · Transforms recordings and DVR data for Jellyfin consumption. · `TVHeadEnd/DataHelper/DvrDataHelper.cs`
- [Autorec](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/AutorecDataHelper.cs): mapper · Maps automatic recording rule data. · `TVHeadEnd/DataHelper/AutorecDataHelper.cs`
- [Tuners](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/DataHelper/TunerDataHelper.cs): mapper · Converts tuner and status data into plugin-facing form. · `TVHeadEnd/DataHelper/TunerDataHelper.cs`

### Support utilities

Low-level helpers used by protocol and domain code.

- [Buffers](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Helper/ByteBuffer.cs): low-level utils · Byte buffer, queue, and framing primitives. · `TVHeadEnd/Helper/ByteBuffer.cs`
- [Helpers](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Helper/DateTimeHelper.cs): shared utils · Date, hashing, and size utilities used across the plugin. · `TVHeadEnd/Helper/DateTimeHelper.cs`
- [Timeouts](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/TimeoutHelper/TaskWithTimeoutRunner.cs): async guard · Wraps tasks with bounded waiting and timeout behavior. · `TVHeadEnd/TimeoutHelper/TaskWithTimeoutRunner.cs`

### Admin UI

Plugin configuration UI inside Jellyfin.

- [Admin page](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Web/tvheadend.html): config UI · Jellyfin admin configuration page for the plugin. · `TVHeadEnd/Web/tvheadend.html`
- [Admin script](https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/master/TVHeadEnd/Web/tvheadend.js): ui script · Client-side logic for the plugin configuration page. · `TVHeadEnd/Web/tvheadend.js`

## Connections

- Plugin → Services: registers · Plugin startup wires services into Jellyfin.
- Plugin → Config: uses · Plugin exposes and consumes persisted settings.
- Services → Live TV: wires · Service registration provides the live-TV service.
- Live TV → Connection handler: connects · Live-TV operations depend on the backend session manager.
- Live TV → Recordings: serves · Live-TV surface exposes recordings as a source.
- Live TV → Access tickets: authorizes · Stream and recording access may require tickets.
- Connection handler → Async client: drives · Connection handler coordinates the async HTSP client.
- Connection handler → Listener: listens · Connection handler relies on listener behavior.
- Async client → HTSP message: formats · Client sends and receives HTSP messages.
- Listener → Response router: dispatches · Listener forwards responses into the response router.
- Response router → Events handler: routes · Typed response handler processes event replies.
- Response router → Loopback handler: routes · Typed response handler processes loopback replies.
- Events handler → Channels: feeds · Event data is converted into channel shapes where needed.
- Events handler → DVR: feeds · Event and recording data inform DVR mappings.
- DVR → Autorec: relates · Recording workflows connect to autorecord rules.
- Connection handler → Buffers: uses · Protocol handling depends on byte-level primitives.
- Connection handler → Helpers: uses · Connection logic reuses common helpers.
- Connection handler → Timeouts: bounds · Backend calls are guarded by timeout wrappers.
- Plugin → Admin page: hosts · Plugin exposes its admin configuration page.
- Admin page → Admin script: drives · Admin page is backed by client-side scripting.
- Admin script → Config: edits · UI reads and writes plugin configuration.
- Config → Connection handler: configures · Connection settings shape backend session behavior.
- Channels → Live TV: supports · Channel mappings feed Jellyfin live-TV features.
- DVR → Recordings: supports · DVR mappings feed recordings exposure.
- Autorec → Live TV: supports · Autorecord rules contribute to live-TV workflows.
- Tuners → Live TV: supports · Tuner status informs live-TV availability.
