# minerchu/dongguatv architecture

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

- Interactive diagram: https://gitdiagram.com/minerchu/dongguatv
- Repository: https://github.com/minerchu/dongguatv

## Overview

#### Purpose and Entry Points
DongguaTV is a self-hosted Node.js video-resource aggregation service. It searches multiple third-party video APIs, returns detail/playback metadata, checks source latency, and exposes a small browser UI plus an administrator UI.

Runtime entry point: `server.js`. User interfaces: `public/index.html` and `public/admin.html`.

#### HTTP Service and API Boundary
The Express server serves the static frontend and owns the application API surface:
- search: `GET /api/search?wd=...`
- source-specific detail: `GET /api/detail?site_key=...&id=...`
- hot content: `GET /api/hot`
- source health/latency: `GET /api/check?key=...`
- administrator login and source configuration endpoints.

`server.js` is the boundary between untrusted browser requests and external resource-site APIs. It uses Axios for outbound requests, CORS for browser access, and Node-cache for transient caching.

#### Multi-Source Aggregation Pipeline
Search requests fan out from `server.js` to enabled upstream video-source APIs, normalize their returned items, and aggregate results for the frontend. The service is designed around a configurable catalog of 30+ resource providers, each identified by a key, name, API endpoint, and activation state.

Detail requests remain source-scoped: the selected `site_key` determines which provider endpoint receives the movie ID. This preserves provider-specific playback and metadata handling rather than attempting to merge detail records globally.

#### Source Health and Result Prioritization
The source-check endpoint in `server.js` measures whether an individual provider is reachable and responsive. The README indicates that response speed is used to prefer faster resources, making source latency a first-class operational signal alongside source enablement.

Failure isolation is important: upstream providers are external, heterogeneous, and may be unavailable; one failed provider should not prevent aggregate search responses from other providers.

#### Browser Clients
The public client, `public/index.html`, implements search, hot-content display, result browsing, detail presentation, and playback-link selection. It also carries the TMDb API-key configuration described in the README, so TMDb enrichment occurs from the client-side integration boundary.

`public/admin.html` is a separate administrative client for authenticating and reading/updating provider configuration. Shared presentation assets live in `public/style.css`.

#### Persistence and Administration
Provider configuration is persisted as a JSON-file database according to the README (including active/inactive switches and custom upstream URLs). The server’s admin routes in `server.js` load and update this configuration, which directly controls the aggregation fan-out set. The documented default administrator password is a deployment risk and should be overridden outside local development.

#### Deployment Model
The application runs on Node.js 16+ and defaults to port 3000. Container deployment is defined by `Dockerfile`, orchestrated with `docker-compose.yml`, and bootstrapped through `entrypoint.sh`. Static UI and API share one server/container, with optional production reverse-proxy placement recommended by the project documentation.

Main entry points: [`server.js`](https://github.com/minerchu/dongguatv/blob/main/server.js) (Express server), [`public/index.html`](https://github.com/minerchu/dongguatv/blob/main/public/index.html) (Public UI), [`public/style.css`](https://github.com/minerchu/dongguatv/blob/main/public/style.css) (Shared styles), [`docker-compose.yml`](https://github.com/minerchu/dongguatv/blob/main/docker-compose.yml) (Container orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Browser clients"]
  node_public_ui["Public UI<br/>browser client<br/>[index.html]"]
  node_admin_ui["Admin UI<br/>browser client<br/>[admin.html]"]
  node_styles["Shared styles<br/>presentation assets<br/>[style.css]"]
end

subgraph group_service["Node.js service"]
  node_server["Express server<br/>Node.js entry point<br/>[server.js]"]
  node_search_pipeline["Search aggregation<br/>fan-out pipeline<br/>[server.js]"]
  node_detail_handler["Source-scoped detail<br/>detail handler<br/>[server.js]"]
  node_health_check["Source health check<br/>latency probe<br/>[server.js]"]
  node_admin_api["Admin API<br/>configuration API<br/>[server.js]"]
  node_source_catalog[("Source catalog<br/>provider configuration")]
  node_source_db[("JSON-file database<br/>file persistence")]
end

subgraph group_external["External services"]
  node_tmdb{{"TMDb<br/>metadata API"}}
  node_video_sources{{"Video-source APIs<br/>third-party providers"}}
end

subgraph group_deployment["Deployment"]
  node_dockerfile["Container image<br/>Docker build"]
  node_compose["Container orchestration<br/>Docker Compose<br/>[docker-compose.yml]"]
  node_entrypoint["Container bootstrap<br/>startup script<br/>[entrypoint.sh]"]
  node_reverse_proxy{{"Optional reverse proxy<br/>production edge"}}
end

node_public_ui -->|"static UI and public API"| node_server
node_admin_ui -->|"admin API"| node_server
node_styles -->|"styles"| node_public_ui
node_styles -->|"styles"| node_admin_ui
node_public_ui -->|"client enrichment"| node_tmdb
node_server -->|"GET /api/search"| node_search_pipeline
node_server -->|"GET /api/detail"| node_detail_handler
node_server -->|"GET /api/check"| node_health_check
node_server -->|"admin routes"| node_admin_api
node_search_pipeline -->|"enabled sources"| node_source_catalog
node_search_pipeline -->|"fan-out search"| node_video_sources
node_detail_handler -->|"resolve site_key"| node_source_catalog
node_detail_handler -->|"provider detail"| node_video_sources
node_health_check -->|"latency probe"| node_video_sources
node_health_check -.->|"prioritize faster sources"| node_source_catalog
node_admin_api -->|"read and update"| node_source_catalog
node_source_catalog -->|"persisted in"| node_source_db
node_compose -->|"builds"| node_dockerfile
node_compose -->|"runs"| node_entrypoint
node_entrypoint -->|"starts"| node_server
node_reverse_proxy -.->|"optional production routing"| node_server

click node_public_ui "https://github.com/minerchu/dongguatv/blob/main/public/index.html"
click node_admin_ui "https://github.com/minerchu/dongguatv/blob/main/public/admin.html"
click node_styles "https://github.com/minerchu/dongguatv/blob/main/public/style.css"
click node_server "https://github.com/minerchu/dongguatv/blob/main/server.js"
click node_search_pipeline "https://github.com/minerchu/dongguatv/blob/main/server.js"
click node_detail_handler "https://github.com/minerchu/dongguatv/blob/main/server.js"
click node_health_check "https://github.com/minerchu/dongguatv/blob/main/server.js"
click node_admin_api "https://github.com/minerchu/dongguatv/blob/main/server.js"
click node_dockerfile "https://github.com/minerchu/dongguatv/tree/main/Dockerfile"
click node_compose "https://github.com/minerchu/dongguatv/blob/main/docker-compose.yml"
click node_entrypoint "https://github.com/minerchu/dongguatv/blob/main/entrypoint.sh"

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_public_ui,node_admin_ui,node_styles toneBlue
class node_server,node_search_pipeline,node_detail_handler,node_health_check,node_admin_api,node_source_catalog,node_source_db toneAmber
class node_tmdb,node_video_sources toneMint
class node_dockerfile,node_compose,node_entrypoint,node_reverse_proxy toneRose
```

## Components

### Browser clients

- [Public UI](https://github.com/minerchu/dongguatv/blob/main/public/index.html): browser client · Searches, browses results, and selects playback links. · `public/index.html`
- [Admin UI](https://github.com/minerchu/dongguatv/blob/main/public/admin.html): browser client · Authenticates and manages video sources. · `public/admin.html`
- [Shared styles](https://github.com/minerchu/dongguatv/blob/main/public/style.css): presentation assets · `public/style.css`

### Node.js service

- [Express server](https://github.com/minerchu/dongguatv/blob/main/server.js): Node.js entry point · Serves static clients and owns the API boundary. · `server.js`
- [Search aggregation](https://github.com/minerchu/dongguatv/blob/main/server.js): fan-out pipeline · Queries enabled sources, normalizes items, and isolates source failures. · `server.js`
- [Source-scoped detail](https://github.com/minerchu/dongguatv/blob/main/server.js): detail handler · Routes a movie ID to its selected provider. · `server.js`
- [Source health check](https://github.com/minerchu/dongguatv/blob/main/server.js): latency probe · Measures provider reachability and response speed. · `server.js`
- [Admin API](https://github.com/minerchu/dongguatv/blob/main/server.js): configuration API · Authenticates administrators and updates source settings. · `server.js`
- **Source catalog**: provider configuration · Provider keys, endpoints, and active states.
- **JSON-file database**: file persistence · Persists provider configuration.

### External services

- **TMDb**: metadata API · Client-side enrichment integration.
- **Video-source APIs**: third-party providers · Heterogeneous upstream search and detail APIs.

### Deployment

- [Container image](https://github.com/minerchu/dongguatv/tree/main/Dockerfile): Docker build · `Dockerfile`
- [Container orchestration](https://github.com/minerchu/dongguatv/blob/main/docker-compose.yml): Docker Compose · `docker-compose.yml`
- [Container bootstrap](https://github.com/minerchu/dongguatv/blob/main/entrypoint.sh): startup script · `entrypoint.sh`
- **Optional reverse proxy**: production edge

## Connections

- Public UI → Express server: static UI and public API
- Admin UI → Express server: admin API
- Shared styles → Public UI: styles
- Shared styles → Admin UI: styles
- Public UI → TMDb: client enrichment
- Express server → Search aggregation: GET /api/search
- Express server → Source-scoped detail: GET /api/detail
- Express server → Source health check: GET /api/check
- Express server → Admin API: admin routes
- Search aggregation → Source catalog: enabled sources
- Search aggregation → Video-source APIs: fan-out search
- Source-scoped detail → Source catalog: resolve site_key
- Source-scoped detail → Video-source APIs: provider detail
- Source health check → Video-source APIs: latency probe
- Source health check → Source catalog: prioritize faster sources
- Admin API → Source catalog: read and update
- Source catalog → JSON-file database: persisted in
- Container orchestration → Container image: builds
- Container orchestration → Container bootstrap: runs
- Container bootstrap → Express server: starts
- Optional reverse proxy → Express server: optional production routing
