# mouthieu/seanime architecture

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

- Interactive diagram: https://gitdiagram.com/mouthieu/seanime
- Repository: https://github.com/mouthieu/seanime

## Overview

#### Purpose and deployable surfaces
Seanime is a local-first media server for anime/manga libraries, streaming, downloads, tracking, and playback. The Go server starts at `main.go`, with application composition in `internal/core/app.go` and HTTP/server platform handling in `internal/server/server.go`. Clients are a React web UI (`seanime-web/src/main.tsx`) and Electron desktop shell (`seanime-denshi/src/main/index.ts`); mobile exposes Go bindings in `mobile/mobile.go`.

#### Server composition and API boundary
`internal/core/modules.go` and `internal/core/extensions.go` assemble subsystems, configuration, migrations, security, and feature flags. HTTP route registration and request handling live in `internal/handlers/routes.go` and `internal/handlers/request_boundary.go`. Handler endpoints are the client/server boundary; generated TypeScript endpoint types and hooks are consumed from `seanime-web/src/api/generated/endpoints.ts` and `seanime-web/src/api/hooks/`.

Server-to-client invalidation, progress, and playback state flow over WebSockets via `internal/events/websocket.go`, surfaced in the client by `seanime-web/src/app/websocket-provider.tsx`.

#### Persistent domain and library ingestion
The database layer owns persisted accounts, settings, tokens, media records, local files, download queues, playlists, and related state: `internal/database/db/db.go`, `internal/database/models/models.go`, and `internal/database/db_bridge/`. Library scanning traverses user files, normalizes/matches titles, hydrates media metadata, and stores scan results through `internal/library/scanner/scan.go`, `internal/library/scanner/hydrator.go`, and `internal/library/anime/collection.go`. Filesystem watchers and scheduled refreshes provide background control paths (`internal/core/watcher.go`, `internal/cron/refresh_anilist.go`).

#### Metadata, tracker, and provider integrations
AniList is the primary metadata/tracking platform, implemented as a GraphQL client with generated schema/models in `internal/api/anilist/client.go`, `internal/api/anilist/queries/`, and `internal/platforms/anilist_platform/anilist_platform.go`. Metadata/provider adapters isolate other APIs and offline sources (`internal/api/metadata_provider/provider.go`, `internal/api/animeofflinedb/animeofflinedb.go`). Manga, online-stream, torrent-search, and custom sources are provider-oriented domains at `internal/manga/providers/providers.go`, `internal/onlinestream/repository.go`, and `internal/customsource/customsource.go`.

#### Extension runtime and trust boundary
Extensions supply torrent, online-stream, manga, tracker, custom-source, and plugin capabilities behind interfaces in `internal/extension/`. The repository installs/loads builtin or external extensions (`internal/extension_repo/repository.go`, `internal/extension_repo/marketplace.go`) and executes external JavaScript through Goja (`internal/extension_repo/goja_base.go`, `internal/goja/goja_runtime/goja_runtime_manager.go`). Plugin APIs and UI bridges are separately exposed in `internal/plugin/plugin_app.go` and rendered client-side under `seanime-web/src/app/(main)/_features/plugin/`.

#### Acquisition and playback pipeline
Torrent discovery/selection feeds supported clients—built-in, qBittorrent, Transmission—or debrid services: `internal/torrents/torrent/search.go`, `internal/torrent_clients/torrent_client/repository.go`, `internal/debrid/client/repository.go`. Auto-downloader rules turn library/tracker updates into queued acquisition in `internal/library/autodownloader/autodownloader.go`.

Playback resolves local, URL, torrent, debrid, and online sources through `internal/directstream/manager.go` and `internal/torrentstream/stream.go`. Browser playback chooses direct play or transcoding via `internal/mediastream/playback.go` and `internal/mediastream/transcoder/transcoder.go`; external/native player adapters reside in `internal/mediaplayers/` and `internal/mpvcore/mpvcore.go`. Electron adds a built-in libmpv core (`seanime-denshi/src/main/mpv-core.ts`).

#### Client applications
The React SPA uses TanStack Router routes from `seanime-web/src/routes/__root.tsx` and `seanime-web/src/routes/_main.tsx`. Feature modules orchestrate API hooks, local UI state, and websocket events; primary workflows include library/scan (`seanime-web/src/app/(main)/_features/anime-library/`), entry streaming/torrents (`seanime-web/src/app/(main)/entry/`), manga reader (`seanime-web/src/app/(main)/manga/`), and browser video playback (`seanime-web/src/app/(main)/_features/video-core/video-core.tsx`). Denshi embeds this UI while managing Electron lifecycle, desktop runtime settings, and mpv integration.

Main entry points: [`internal/core/app.go`](https://github.com/mouthieu/seanime/blob/main/internal/core/app.go) (Application composition), [`internal/handlers/routes.go`](https://github.com/mouthieu/seanime/blob/main/internal/handlers/routes.go) (HTTP API boundary), [`internal/library/scanner/scan.go`](https://github.com/mouthieu/seanime/blob/main/internal/library/scanner/scan.go) (Library ingestion), [`internal/database/db/db.go`](https://github.com/mouthieu/seanime/blob/main/internal/database/db/db.go) (Persistent domain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Go server"]
  node_entry["Server entrypoint<br/>Go bootstrap<br/>[main.go]"]
  node_app["Application composition<br/>core<br/>[app.go]"]
  node_http["HTTP API boundary<br/>handlers<br/>[routes.go]"]
  node_database[("Persistent domain<br/>database layer<br/>[db.go]")]
  node_library["Library ingestion<br/>scanner<br/>[scan.go]"]
  node_background["Watchers &amp; refresh<br/>background jobs<br/>[watcher.go]"]
  node_events["WebSocket events<br/>event transport<br/>[websocket.go]"]
  node_anilist{{"AniList platform<br/>GraphQL integration"}}
  node_providers{{"Metadata &amp; source adapters<br/>provider domain<br/>[provider.go]"}}
end

subgraph group_extensions["Extensions"]
  node_extension_repo["Extension repository<br/>extension lifecycle<br/>[repository.go]"]
  node_extension_runtime{{"JavaScript extension runtime<br/>Goja runtime"}}
  node_plugin_api["Plugin API bridge<br/>plugin runtime<br/>[plugin_app.go]"]
end

subgraph group_media["Acquisition &amp; playback"]
  node_torrent_search["Torrent discovery<br/>torrent search<br/>[search.go]"]
  node_acquisition{{"Download clients &amp; debrid<br/>acquisition adapters<br/>[repository.go]"}}
  node_autodownloader["Auto-downloader<br/>automation<br/>[autodownloader.go]"]
  node_source_resolution["Stream source resolution<br/>direct stream manager<br/>[manager.go]"]
  node_playback["Browser playback<br/>media playback<br/>[playback.go]"]
  node_mpv["Native player adapters<br/>MPV integration<br/>[mpvcore.go]"]
end

subgraph group_clients["Client surfaces"]
  node_web["React web UI<br/>React SPA<br/>[main.tsx]"]
  node_websocket_ui["WebSocket provider<br/>React provider"]
  node_electron["Denshi desktop shell<br/>Electron app<br/>[index.ts]"]
  node_mobile["Mobile bindings<br/>Go mobile API<br/>[mobile.go]"]
end

node_entry -->|"starts"| node_app
node_app -->|"composes"| node_http
node_app -->|"initializes"| node_database
node_app -->|"runs"| node_background
node_http -->|"reads and writes"| node_database
node_http -->|"triggers"| node_library
node_http -->|"publishes"| node_events
node_library -->|"stores scan results"| node_database
node_background -->|"refreshes"| node_library
node_library -->|"hydrates metadata"| node_anilist
node_anilist -->|"syncs tracking"| node_database
node_app -->|"loads"| node_extension_repo
node_extension_repo -->|"executes external code in"| node_extension_runtime
node_extension_runtime -->|"supplies adapters"| node_providers
node_plugin_api -->|"bridges plugins"| node_extension_runtime
node_providers -->|"provides sources"| node_torrent_search
node_torrent_search -->|"selected torrents"| node_acquisition
node_autodownloader -->|"queues downloads"| node_acquisition
node_library -.->|"library updates"| node_autodownloader
node_acquisition -->|"persists queue state"| node_database
node_source_resolution -->|"resolved source"| node_playback
node_playback -.->|"uses native players"| node_mpv
node_web -->|"generated endpoint hooks"| node_http
node_websocket_ui -->|"receives live state"| node_events
node_web -->|"mounts"| node_websocket_ui
node_electron -->|"embeds"| node_web
node_electron -->|"integrates libmpv"| node_mpv
node_mobile -->|"binds to server core"| node_app

click node_entry "https://github.com/mouthieu/seanime/blob/main/main.go"
click node_app "https://github.com/mouthieu/seanime/blob/main/internal/core/app.go"
click node_http "https://github.com/mouthieu/seanime/blob/main/internal/handlers/routes.go"
click node_database "https://github.com/mouthieu/seanime/blob/main/internal/database/db/db.go"
click node_library "https://github.com/mouthieu/seanime/blob/main/internal/library/scanner/scan.go"
click node_background "https://github.com/mouthieu/seanime/blob/main/internal/core/watcher.go"
click node_events "https://github.com/mouthieu/seanime/blob/main/internal/events/websocket.go"
click node_anilist "https://github.com/mouthieu/seanime/blob/main/internal/platforms/anilist_platform/anilist_platform.go"
click node_providers "https://github.com/mouthieu/seanime/blob/main/internal/api/metadata_provider/provider.go"
click node_extension_repo "https://github.com/mouthieu/seanime/blob/main/internal/extension_repo/repository.go"
click node_extension_runtime "https://github.com/mouthieu/seanime/blob/main/internal/goja/goja_runtime/goja_runtime_manager.go"
click node_plugin_api "https://github.com/mouthieu/seanime/blob/main/internal/plugin/plugin_app.go"
click node_torrent_search "https://github.com/mouthieu/seanime/blob/main/internal/torrents/torrent/search.go"
click node_acquisition "https://github.com/mouthieu/seanime/blob/main/internal/torrent_clients/torrent_client/repository.go"
click node_autodownloader "https://github.com/mouthieu/seanime/blob/main/internal/library/autodownloader/autodownloader.go"
click node_source_resolution "https://github.com/mouthieu/seanime/blob/main/internal/directstream/manager.go"
click node_playback "https://github.com/mouthieu/seanime/blob/main/internal/mediastream/playback.go"
click node_web "https://github.com/mouthieu/seanime/blob/main/seanime-web/src/main.tsx"
click node_websocket_ui "https://github.com/mouthieu/seanime/blob/main/seanime-web/src/app/websocket-provider.tsx"
click node_electron "https://github.com/mouthieu/seanime/blob/main/seanime-denshi/src/main/index.ts"
click node_mobile "https://github.com/mouthieu/seanime/blob/main/mobile/mobile.go"
click node_mpv "https://github.com/mouthieu/seanime/blob/main/internal/mpvcore/mpvcore.go"

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_entry,node_app,node_http,node_database,node_library,node_background,node_events,node_anilist,node_providers toneBlue
class node_extension_repo,node_extension_runtime,node_plugin_api toneAmber
class node_torrent_search,node_acquisition,node_autodownloader,node_source_resolution,node_playback,node_mpv toneMint
class node_web,node_websocket_ui,node_electron,node_mobile toneRose
```

## Components

### Go server

- [Server entrypoint](https://github.com/mouthieu/seanime/blob/main/main.go): Go bootstrap · `main.go`
- [Application composition](https://github.com/mouthieu/seanime/blob/main/internal/core/app.go): core · Assembles modules, extensions, security, migrations, and flags. · `internal/core/app.go`
- [HTTP API boundary](https://github.com/mouthieu/seanime/blob/main/internal/handlers/routes.go): handlers · Registers routes and handles client requests. · `internal/handlers/routes.go`
- [Persistent domain](https://github.com/mouthieu/seanime/blob/main/internal/database/db/db.go): database layer · Accounts, settings, media, files, queues, tokens, and playlists. · `internal/database/db/db.go`
- [Library ingestion](https://github.com/mouthieu/seanime/blob/main/internal/library/scanner/scan.go): scanner · Scans files, matches titles, hydrates metadata, and persists results. · `internal/library/scanner/scan.go`
- [Watchers & refresh](https://github.com/mouthieu/seanime/blob/main/internal/core/watcher.go): background jobs · `internal/core/watcher.go`
- [WebSocket events](https://github.com/mouthieu/seanime/blob/main/internal/events/websocket.go): event transport · Pushes invalidation, progress, and playback state. · `internal/events/websocket.go`
- [AniList platform](https://github.com/mouthieu/seanime/blob/main/internal/platforms/anilist_platform/anilist_platform.go): GraphQL integration · Primary metadata and tracking integration. · `internal/platforms/anilist_platform/anilist_platform.go`
- [Metadata & source adapters](https://github.com/mouthieu/seanime/blob/main/internal/api/metadata_provider/provider.go): provider domain · Supports metadata, manga, online-stream, and custom sources. · `internal/api/metadata_provider/provider.go`

### Extensions

- [Extension repository](https://github.com/mouthieu/seanime/blob/main/internal/extension_repo/repository.go): extension lifecycle · Installs and loads builtin and external extensions. · `internal/extension_repo/repository.go`
- [JavaScript extension runtime](https://github.com/mouthieu/seanime/blob/main/internal/goja/goja_runtime/goja_runtime_manager.go): Goja runtime · Executes external extension code behind extension interfaces. · `internal/goja/goja_runtime/goja_runtime_manager.go`
- [Plugin API bridge](https://github.com/mouthieu/seanime/blob/main/internal/plugin/plugin_app.go): plugin runtime · `internal/plugin/plugin_app.go`

### Acquisition & playback

- [Torrent discovery](https://github.com/mouthieu/seanime/blob/main/internal/torrents/torrent/search.go): torrent search · `internal/torrents/torrent/search.go`
- [Download clients & debrid](https://github.com/mouthieu/seanime/blob/main/internal/torrent_clients/torrent_client/repository.go): acquisition adapters · Routes selected torrents to clients or debrid services. · `internal/torrent_clients/torrent_client/repository.go`
- [Auto-downloader](https://github.com/mouthieu/seanime/blob/main/internal/library/autodownloader/autodownloader.go): automation · Converts library and tracker updates into acquisition work. · `internal/library/autodownloader/autodownloader.go`
- [Stream source resolution](https://github.com/mouthieu/seanime/blob/main/internal/directstream/manager.go): direct stream manager · Resolves local, URL, torrent, debrid, and online sources. · `internal/directstream/manager.go`
- [Browser playback](https://github.com/mouthieu/seanime/blob/main/internal/mediastream/playback.go): media playback · Selects direct play or transcoding. · `internal/mediastream/playback.go`
- [Native player adapters](https://github.com/mouthieu/seanime/blob/main/internal/mpvcore/mpvcore.go): MPV integration · External/native player integration, including Electron libmpv. · `internal/mpvcore/mpvcore.go`

### Client surfaces

- [React web UI](https://github.com/mouthieu/seanime/blob/main/seanime-web/src/main.tsx): React SPA · Route-driven UI consuming generated API hooks. · `seanime-web/src/main.tsx`
- [WebSocket provider](https://github.com/mouthieu/seanime/blob/main/seanime-web/src/app/websocket-provider.tsx): React provider · `seanime-web/src/app/websocket-provider.tsx`
- [Denshi desktop shell](https://github.com/mouthieu/seanime/blob/main/seanime-denshi/src/main/index.ts): Electron app · Embeds the web UI and manages desktop lifecycle. · `seanime-denshi/src/main/index.ts`
- [Mobile bindings](https://github.com/mouthieu/seanime/blob/main/mobile/mobile.go): Go mobile API · `mobile/mobile.go`

## Connections

- Server entrypoint → Application composition: starts
- Application composition → HTTP API boundary: composes
- Application composition → Persistent domain: initializes
- Application composition → Watchers & refresh: runs
- HTTP API boundary → Persistent domain: reads and writes
- HTTP API boundary → Library ingestion: triggers
- HTTP API boundary → WebSocket events: publishes
- Library ingestion → Persistent domain: stores scan results
- Watchers & refresh → Library ingestion: refreshes
- Library ingestion → AniList platform: hydrates metadata
- AniList platform → Persistent domain: syncs tracking
- Application composition → Extension repository: loads
- Extension repository → JavaScript extension runtime: executes external code in
- JavaScript extension runtime → Metadata & source adapters: supplies adapters
- Plugin API bridge → JavaScript extension runtime: bridges plugins
- Metadata & source adapters → Torrent discovery: provides sources
- Torrent discovery → Download clients & debrid: selected torrents
- Auto-downloader → Download clients & debrid: queues downloads
- Library ingestion → Auto-downloader: library updates
- Download clients & debrid → Persistent domain: persists queue state
- Stream source resolution → Browser playback: resolved source
- Browser playback → Native player adapters: uses native players
- React web UI → HTTP API boundary: generated endpoint hooks
- WebSocket provider → WebSocket events: receives live state
- React web UI → WebSocket provider: mounts
- Denshi desktop shell → React web UI: embeds
- Denshi desktop shell → Native player adapters: integrates libmpv
- Mobile bindings → Application composition: binds to server core
