# stupside/castor architecture

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

- Interactive diagram: https://gitdiagram.com/stupside/castor
- Repository: https://github.com/stupside/castor

## Overview

Castor discovers network TVs, resolves web pages or direct streams, adapts media, and controls playback. The principal API workflow is client request → API cast orchestration → optional page scraping → media ranking/playback → device delivery, with status/watch and stop controls. The CLI also provides interactive TMDB browsing and local casting. The tree and README establish several capabilities, but unsampled internals are represented by directory-level nodes; edges are limited to documented or excerpt-supported relationships.

Main entry points: [`services/mediaserver/internal/cast/service.go`](https://github.com/stupside/castor/blob/main/services/mediaserver/internal/cast/service.go) (Cast processing), [`services/apiserver/internal/cast/service.go`](https://github.com/stupside/castor/blob/main/services/apiserver/internal/cast/service.go) (Cast lifecycle), [`services/apiserver/server.go`](https://github.com/stupside/castor/blob/main/services/apiserver/server.go) (API server), [`cmd/castor/commands.go`](https://github.com/stupside/castor/blob/main/cmd/castor/commands.go) (CLI commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User clients"]
  node_cli["CLI commands<br/>[commands.go]"]
  node_tui["Title browser"]
  node_webui["Web app<br/>[page.tsx]"]
end

subgraph group_control["Cast control"]
  node_publicapi["API server<br/>[server.go]"]
  node_castflow["Cast lifecycle<br/>[service.go]"]
  node_deviceindex["Device discovery"]
  node_apimedia["Media client<br/>[client.go]"]
  node_apiscape["Scraping client<br/>[client.go]"]
end

subgraph group_resolution["Source resolution"]
  node_scraper["Page extraction"]
  node_tmdb["TMDB browser"]
end

subgraph group_media["Media processing"]
  node_mediaserver["Media server API<br/>[server.go]"]
  node_mediaservice["Cast processing<br/>[service.go]"]
  node_source["Stream sources"]
  node_probe["Media probing<br/>[program.go]"]
  node_encoding["Transcoding"]
  node_delivery["Media delivery"]
  node_ffmpeg["FFmpeg tools"]
end

subgraph group_devices["Playback devices"]
  node_deviceprotocols["Device protocols"]
  node_tv(("Network TV"))
end

node_user(("User / app"))
node_origin(("Web stream origin"))

node_user -->|"runs commands"| node_cli
node_user -->|"uses"| node_webui
node_user -->|"calls API"| node_publicapi
node_cli -->|"casts through"| node_publicapi
node_cli -->|"opens browser"| node_tui
node_tui -->|"searches titles"| node_tmdb
node_webui -->|"calls services"| node_publicapi
node_publicapi -->|"routes cast API"| node_castflow
node_castflow -->|"selects device"| node_deviceindex
node_castflow -->|"ranks and starts"| node_apimedia
node_castflow -->|"resolves pages"| node_apiscape
node_apiscape -->|"requests extraction"| node_scraper
node_scraper -->|"extracts streams"| node_origin
node_apimedia -->|"calls media API"| node_mediaserver
node_mediaserver -->|"routes cast operations"| node_mediaservice
node_mediaservice -->|"ranks candidates"| node_source
node_mediaservice -->|"delivers playback"| node_delivery
node_mediaservice -->|"plays streams"| node_encoding
node_source -.->|"reads media"| node_origin
node_mediaservice -.->|"probes streams"| node_probe
node_encoding -.->|"encodes with"| node_ffmpeg
node_delivery -->|"serves media"| node_tv
node_deviceindex -.->|"connects devices"| node_deviceprotocols
node_deviceprotocols -->|"controls playback"| node_tv

click node_cli "https://github.com/stupside/castor/blob/main/cmd/castor/commands.go"
click node_tui "https://github.com/stupside/castor/tree/main/cmd/castor/internal/browse"
click node_webui "https://github.com/stupside/castor/blob/main/app/app/page.tsx"
click node_publicapi "https://github.com/stupside/castor/blob/main/services/apiserver/server.go"
click node_castflow "https://github.com/stupside/castor/blob/main/services/apiserver/internal/cast/service.go"
click node_deviceindex "https://github.com/stupside/castor/tree/main/services/apiserver/internal/device"
click node_apimedia "https://github.com/stupside/castor/blob/main/services/apiserver/internal/mediaclient/client.go"
click node_apiscape "https://github.com/stupside/castor/blob/main/services/apiserver/internal/scrapingclient/client.go"
click node_scraper "https://github.com/stupside/castor/tree/main/services/scrapingserver/internal/extract"
click node_tmdb "https://github.com/stupside/castor/tree/main/cmd/castor/internal/browse/tmdb"
click node_mediaserver "https://github.com/stupside/castor/blob/main/services/mediaserver/server.go"
click node_mediaservice "https://github.com/stupside/castor/blob/main/services/mediaserver/internal/cast/service.go"
click node_source "https://github.com/stupside/castor/tree/main/services/mediaserver/internal/source"
click node_probe "https://github.com/stupside/castor/blob/main/services/mediaserver/internal/probe/program.go"
click node_encoding "https://github.com/stupside/castor/tree/main/services/mediaserver/internal/cast/transcode"
click node_delivery "https://github.com/stupside/castor/tree/main/services/mediaserver/internal/cast/deliver"
click node_ffmpeg "https://github.com/stupside/castor/tree/main/services/mediaserver/internal/ffmpeg"
click node_deviceprotocols "https://github.com/stupside/castor/tree/main/services/apiserver/internal/device"

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_cli,node_tui,node_webui,node_user toneBlue
class node_publicapi,node_castflow,node_deviceindex,node_apimedia,node_apiscape toneAmber
class node_scraper,node_tmdb toneMint
class node_mediaserver,node_mediaservice,node_source,node_probe,node_encoding,node_delivery,node_ffmpeg toneRose
class node_deviceprotocols,node_tv,node_origin toneIndigo
```

## Components

### User clients

- [CLI commands](https://github.com/stupside/castor/blob/main/cmd/castor/commands.go): `cmd/castor/commands.go`
- [Title browser](https://github.com/stupside/castor/tree/main/cmd/castor/internal/browse): `cmd/castor/internal/browse`
- [Web app](https://github.com/stupside/castor/blob/main/app/app/page.tsx): `app/app/page.tsx`

### Cast control

- [API server](https://github.com/stupside/castor/blob/main/services/apiserver/server.go): `services/apiserver/server.go`
- [Cast lifecycle](https://github.com/stupside/castor/blob/main/services/apiserver/internal/cast/service.go): `services/apiserver/internal/cast/service.go`
- [Device discovery](https://github.com/stupside/castor/tree/main/services/apiserver/internal/device): `services/apiserver/internal/device`
- [Media client](https://github.com/stupside/castor/blob/main/services/apiserver/internal/mediaclient/client.go): `services/apiserver/internal/mediaclient/client.go`
- [Scraping client](https://github.com/stupside/castor/blob/main/services/apiserver/internal/scrapingclient/client.go): `services/apiserver/internal/scrapingclient/client.go`

### Source resolution

- [Page extraction](https://github.com/stupside/castor/tree/main/services/scrapingserver/internal/extract): `services/scrapingserver/internal/extract`
- [TMDB browser](https://github.com/stupside/castor/tree/main/cmd/castor/internal/browse/tmdb): `cmd/castor/internal/browse/tmdb`

### Media processing

- [Media server API](https://github.com/stupside/castor/blob/main/services/mediaserver/server.go): `services/mediaserver/server.go`
- [Cast processing](https://github.com/stupside/castor/blob/main/services/mediaserver/internal/cast/service.go): `services/mediaserver/internal/cast/service.go`
- [Stream sources](https://github.com/stupside/castor/tree/main/services/mediaserver/internal/source): `services/mediaserver/internal/source`
- [Media probing](https://github.com/stupside/castor/blob/main/services/mediaserver/internal/probe/program.go): `services/mediaserver/internal/probe/program.go`
- [Transcoding](https://github.com/stupside/castor/tree/main/services/mediaserver/internal/cast/transcode): `services/mediaserver/internal/cast/transcode`
- [Media delivery](https://github.com/stupside/castor/tree/main/services/mediaserver/internal/cast/deliver): `services/mediaserver/internal/cast/deliver`
- [FFmpeg tools](https://github.com/stupside/castor/tree/main/services/mediaserver/internal/ffmpeg): `services/mediaserver/internal/ffmpeg`

### Playback devices

- [Device protocols](https://github.com/stupside/castor/tree/main/services/apiserver/internal/device): `services/apiserver/internal/device`
- **Network TV**

### Other components

- **User / app**
- **Web stream origin**

## Connections

- User / app → CLI commands: runs commands (evidence: `README.md`)
- User / app → Web app: uses (evidence: `README.md`)
- User / app → API server: calls API (evidence: `README.md`)
- CLI commands → API server: casts through (evidence: `README.md`)
- CLI commands → Title browser: opens browser (evidence: `README.md`)
- Title browser → TMDB browser: searches titles (evidence: `cmd/castor/internal/browse/search.go`)
- Web app → API server: calls services
- API server → Cast lifecycle: routes cast API (evidence: `services/apiserver/server.go`)
- Cast lifecycle → Device discovery: selects device (evidence: `services/apiserver/internal/cast/service.go`)
- Cast lifecycle → Media client: ranks and starts (evidence: `services/apiserver/internal/cast/service.go`)
- Cast lifecycle → Scraping client: resolves pages (evidence: `services/apiserver/internal/cast/service.go`)
- Scraping client → Page extraction: requests extraction (evidence: `services/apiserver/internal/scrapingclient/client.go`)
- Page extraction → Web stream origin: extracts streams (evidence: `README.md`)
- Media client → Media server API: calls media API (evidence: `services/apiserver/internal/mediaclient/client.go`)
- Media server API → Cast processing: routes cast operations (evidence: `services/mediaserver/server.go`)
- Cast processing → Stream sources: ranks candidates (evidence: `services/mediaserver/internal/cast/service.go`)
- Cast processing → Media delivery: delivers playback (evidence: `services/mediaserver/internal/cast/service.go`)
- Cast processing → Transcoding: plays streams (evidence: `services/mediaserver/internal/cast/service.go`)
- Stream sources → Web stream origin: reads media
- Cast processing → Media probing: probes streams
- Transcoding → FFmpeg tools: encodes with
- Media delivery → Network TV: serves media (evidence: `README.md`)
- Device discovery → Device protocols: connects devices
- Device protocols → Network TV: controls playback (evidence: `README.md`)
