Files
Piik/docs/research/server-consolidation.md
T
AAA f92162b3bb feat: launch Piik with a unified interface and public website
Piik now has one public presentation and a coordinated App/Server release path. This phase unifies the room UI, rewrites the bilingual README and guides, adds a static website with an inline product film, and prepares matching GitHub/Gitee packages and update links.

The film uses the current homepage and shared product controls on one seekable timeline. Runtime fixes preserve presentation when the App opens a room, normalize Site origins, and keep capture and media-recovery status in the television indicator. New visits use Chinese for a Chinese system language and English otherwise; explicit language and visual-mode choices remain available. An optional site passphrase controls site entry, while room authorization remains enforced.

GitHub is the release authority. Gitee mirrors verified packages and provides update metadata when GitHub is unavailable. Reviewed PR release notes become the GitHub Release description. The separate public demo uses P2P only, with HTTPS and STUN verified.

Validation: 756 Web tests, TypeScript and production build; Go core tests, formatting, vet and available target builds; bounded Windows capture and App/Site interoperability; browser film checks, audible playback and narrow layouts; anonymous Gitee Windows-package download, checksum and launcher/update-link checks. Public demo acceptance covers authenticated WebSocket signaling, synthetic P2P video and room cleanup on one network. macOS/Linux physical capture and the wider device/network/endurance matrix remain explicitly deferred.

Publication builds every package from the merged source SHA. The repository is public, main protection is active, and Pages is configured for piik.tv. CI/publisher and Pages deployment records own publication results.

## Release notes

### 中文

Piik 是免费开源的屏幕共享工具。开个房间,发出邀请,最多 20 位朋友就能用浏览器加入观看。

- 使用浏览器或 Piik App 分享游戏、窗口和整个屏幕。
- 优先建立直连;自托管站点可开启媒体转发作为备用线路。
- Piik App 支持本地房间、临时公网邀请和已有站点。
- Piik Server 内置网页界面、房间管理和连接服务,方便自行部署。
- 提供中英文界面与使用指南,以及 GitHub、Gitee 两条下载线路。

[官网](https://piik.tv) · [在线体验](https://demo.piik.tv) · [使用指南](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.zh-CN.md) · [自行部署](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.zh-CN.md) · [Gitee 下载](https://gitee.com/TNTcraftHIM/Piik/releases)

Windows App 和桌面浏览器是本次主要验证的平台。macOS 和 Linux 尚未经过实机测试,欢迎有设备的朋友测试并反馈。演示站和 App 公网邀请使用 P2P,受限网络下可能无法连接;自托管站点可开启媒体转发。

### English

Piik is free, open-source screen sharing for you and up to 20 viewers. Start a room, send an invitation, and your friends can join in a browser.

- Share games, windows or a whole screen from your browser or Piik App.
- Direct connections come first, with optional media forwarding on self-hosted sites.
- Piik App supports local rooms, temporary public invitations and existing sites.
- Piik Server includes the web interface, rooms and connection services for self-hosting.
- English and Chinese interfaces and guides are available, with GitHub and Gitee downloads.

[Website](https://piik.tv) · [Online demo](https://demo.piik.tv) · [User guide](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.md) · [Self-hosting](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.md) · [Gitee downloads](https://gitee.com/TNTcraftHIM/Piik/releases)

Windows App and desktop browsers are the primary validated paths. macOS and Linux have not yet been tested on physical devices; testing and feedback are welcome. The demo and App public invitations rely on P2P and may not connect on restrictive networks. Self-hosted sites can enable media forwarding.
2026-09-12 22:09:12 +08:00

6.6 KiB

Server Consolidation

  • Reviewed: 2026-09-06
  • Status: implemented in the candidate; the acceptance list below is the remaining boundary
  • Scope: one shared Go backend for Hosted and self-contained App operation

Current Ownership

cmd/piik-server (Hosted) and cmd/piik-app (App) compose the same application from internal/server and own only their defaults, reachability, and lifecycle policy. Within that scope protocol owns wire types, strict decoding, and shared scalars; config owns environment validation plus the Hosted and Local compositions; room owns room authority, participants, and the SQLite database; route decides graph transitions without I/O; signal executes signaling and SFU effects under one lock; sfu owns admission, LiveKit room control, and token issue; app owns HTTP composition, site access, static assets, and lifecycle; and webassets carries the embedded Browser bundle. internal/app keeps the native, launcher, and platform boundaries and supervises no server process. These are useful boundaries, not duplication to remove.

Structural Simplification

  1. Room expiry and abandonment share one terminateRoom path in signal. Preserve the distinct semantics of stopping a share, ending a room, and restarting a persistent server.
  2. The Hybrid connection-ID mirror is gone. The viewer-quality evidence path and the active media-edge lookup read the connection identity from the committed edge, and the evidence gate keeps its own last-observation identity; router tests cover in-place connection adoption during a rebuild and exact direct/peer-relayed evidence sources.

These are structural simplifications, not reproduced functional failures. The engineering reference requires a concrete ownership gain before further extraction.

Product Choice

The graph controller is now universal. The former rollout switch and ordinary Host-star signaling path were removed together, so Hosted and Local share one route authority and LiveKit remains an optional fallback of that graph.

Target Composition

one Go module
cmd/piik-server -> shared server application
cmd/piik-app -> shared server application + launcher + native media
internal/server    -> rooms, routing, HTTP/signaling, persistence, SFU adapters
internal/app       -> current native and platform boundaries
one React/Vite static artifact -> embedded in both binaries

Use packages for cohesive owners and files for local concerns. Do not introduce a framework layer per file, a second product API, or a multi-module build. Hosted and Local construct the same validated application options; entry points own their defaults, reachability and lifecycle policy.

Each room keeps one serialized state owner. Go HTTP/WebSocket handlers must not mutate room, share and route maps independently. Run password derivation and LiveKit I/O outside that owner, then apply results only while the exact session, share and operation identities still match. Preserve the existing distinction between decisions and effects rather than replacing Node serialization with unrelated locks around each map.

Reusable Components

  • Standard net/http and embed serve HTTP and the built assets.
  • Signaling reuses the App's coder/websocket.
  • LiveKit room control and tokens use the standard library only: HS256 JWTs and Twirp JSON requests. The official LiveKit Go SDK adds a large module and license surface for a handful of call shapes and is not used.
  • Room persistence keeps the current schema and transactions on the pure-Go modernc.org/sqlite driver, which builds without cgo and holds one exclusive connection; no ORM is needed.
  • The layout follows Go's shared internal and multiple cmd guidance. Pion, capture sidecars and control-tunnel ownership are unchanged.

Minimum Acceptance

Preserve exact Host/session replacement, grant revocation, atomic room replacement, SQLite restart continuity and Local shutdown semantics. Exercise one graph and one operation through Peer, SFU, same-edge regeneration, bounded overlap and rollback, including stale asynchronous completions. Preserve short-lived SFU authority and release resources only after physical drain confirmation.

Use the same Browser contract scenarios against Hosted and Local, plus one physical mixed Browser/App media flow. Package size, startup and idle memory are measured below. Keep one strict wire contract and one schema owner; avoid hand-maintained parallel TypeScript/Go validation rules. The Node server, bundled runtime, supervisor and old packaging paths retire in this same accepted integration boundary, preserving ADR-0005 and ADR-0010 as amended by ADR-0012.

Measured Before And After

One machine, 2026-09-06: Windows 11, Node 24.15.0, Go 1.26.6. A script spawned each server with the same production configuration (PORT=18787, HTTPS public origin, site-access password, one STUN URL, loopback listen host), polled /healthz every 10 ms until {"status":"ok"}, waited 5 s idle, sampled resident memory through PowerShell WorkingSet64, then killed the process. Five runs per side; the median is reported. Before is the Node baseline at tag baseline-b20fd88; after is piik-server under the same script.

metric before after
cold start to healthy 160 ms 81 ms
idle resident memory 77,242,368 B 10,928,128 B
shipped Hosted bytes ~106.7 MB ~14.0 MB

The before total is the Node runtime (91,694,408 B), the production node_modules tree (12,640,469 B in 1,513 files), dist/client (1,492,721 B) and dist/server (856,898 B). The after total is the linux/amd64 piik-server built with -s -w and embedded assets (13,983,906 B) plus its notices and REVISION. For reference, the windows/amd64 binaries are 14,276,608 B (piik-server) and 22,703,104 B (piik-app, which also carries Pion and the terminal UI); the App package additionally drops the Node runtime and dependency tree it used to ship beside its Go executable.

The first two starts of a freshly built binary took 469 ms and 336 ms, which is consistent with on-access antivirus scanning of a new executable; the median above is the steady state. Not measured: throughput or latency under load, which this port does not change, and the Linux deployment host.