# mikhail-ramirez/tv-control architecture

> Architecture diagram of the GitHub repository mikhail-ramirez/tv-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mikhail-ramirez/tv-control
- Repository: https://github.com/mikhail-ramirez/tv-control

## Overview

tv-control is a small browser-based remote for Android TV and Fire TV over network ADB. A user connects or selects a control in the web page; the browser calls the Node HTTP API, which manages connection state and sends commands to the TV. Wake can optionally send a Wake-on-LAN packet and wait before connecting. The README also documents responsive desktop/mobile controls and environment-based configuration. Server behavior is sampled in src/server.js; the page’s markup and styling are present in the tree but were not sampled, so their internal structure is not expanded.

Main entry points: [`src/server.js`](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js) (API handlers), [`public/app.js`](https://github.com/mikhail-ramirez/tv-control/blob/master/public/app.js) (Remote controls), [`public/index.html`](https://github.com/mikhail-ramirez/tv-control/blob/master/public/index.html) (Remote page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser remote"]
  node_webui["Remote controls<br/>[app.js]"]
  node_page["Remote page<br/>[index.html]"]
end

subgraph group_backend["HTTP backend"]
  node_server["HTTP server<br/>[server.js]"]
  node_api["API handlers<br/>[server.js]"]
  node_state["Connection state<br/>[server.js]"]
end

subgraph group_transport["TV transport"]
  node_wake["Wake-on-LAN<br/>[server.js]"]
  node_connection["ADB connection<br/>[server.js]"]
  node_keycommand["Key commands<br/>[server.js]"]
end

node_user(("User"))
node_adb["ADB CLI"]
node_lan["Local network"]
node_tv(("TV device"))

node_user -->|"presses controls"| node_webui
node_server -->|"serves static page"| node_page
node_page -->|"loads script"| node_webui
node_webui -->|"sends HTTP requests"| node_api
node_api -->|"reads state"| node_state
node_state -->|"returns status"| node_api
node_api -->|"connects"| node_connection
node_api -.->|"sends wake packet"| node_wake
node_api -->|"dispatches key"| node_keycommand
node_keycommand -->|"ensures connection"| node_connection
node_connection -->|"runs connect checks"| node_adb
node_keycommand -->|"runs key event"| node_adb
node_adb -->|"controls over ADB"| node_tv
node_wake -.->|"broadcasts packet"| node_lan
node_lan -.->|"wakes device"| node_tv

click node_webui "https://github.com/mikhail-ramirez/tv-control/blob/master/public/app.js"
click node_page "https://github.com/mikhail-ramirez/tv-control/blob/master/public/index.html"
click node_server "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js"
click node_api "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js"
click node_state "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js"
click node_wake "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js"
click node_connection "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js"
click node_keycommand "https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.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_webui,node_page,node_user toneBlue
class node_server,node_api,node_state toneAmber
class node_wake,node_connection,node_keycommand toneMint
class node_adb,node_lan,node_tv toneIndigo
```

## Components

### Browser remote

- [Remote controls](https://github.com/mikhail-ramirez/tv-control/blob/master/public/app.js): `public/app.js`
- [Remote page](https://github.com/mikhail-ramirez/tv-control/blob/master/public/index.html): `public/index.html`

### HTTP backend

- [HTTP server](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`
- [API handlers](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`
- [Connection state](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`

### TV transport

- [Wake-on-LAN](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`
- [ADB connection](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`
- [Key commands](https://github.com/mikhail-ramirez/tv-control/blob/master/src/server.js): `src/server.js`

### Other components

- **User**
- **ADB CLI**
- **Local network**
- **TV device**

## Connections

- User → Remote controls: presses controls
- HTTP server → Remote page: serves static page
- Remote page → Remote controls: loads script
- Remote controls → API handlers: sends HTTP requests
- API handlers → Connection state: reads state
- Connection state → API handlers: returns status
- API handlers → ADB connection: connects
- API handlers → Wake-on-LAN: sends wake packet
- API handlers → Key commands: dispatches key
- Key commands → ADB connection: ensures connection
- ADB connection → ADB CLI: runs connect checks
- Key commands → ADB CLI: runs key event
- ADB CLI → TV device: controls over ADB
- Wake-on-LAN → Local network: broadcasts packet
- Local network → TV device: wakes device
