Architecture

core-service/cmd/tgdl-server is the production process. It serves the embedded browser assets, HTTP API, media and WebSocket connections, and owns SQLite and Telegram account lifetimes through gotd. There is no JavaScript server or runtime fallback; the browser JavaScript is embedded in the binary and runs only in the browser. The build does not need npm, a bundler or generated source outside the Go module. ffmpeg (with ffprobe) is the only external program the server runs: thumbnails, seekbar previews and MP4 faststart. The optional tgdl-faces and tgdl-nsfw sidecars are called over HTTP.

flowchart LR
    browser[Browser dashboard] <-- HTTP and WebSocket --> app[Go application]
    telegram[Telegram MTProto] <-- gotd --> accounts[Account sessions]
    accounts --> engine[Durable queue]
    app --> engine
    engine --> download[Download and dedup]
    download --> files[Media files]
    download --> db[(SQLite)]
    engine --> db
    app --> db
    files --> app

Ownership

Package under core-service/internal/ Responsibility
app HTTP policy, authentication gates, APIs, WebSocket events and job integration
accounts, telegram, session Login, encrypted sessions, account ownership, gotd updates and media transport
engine Durable queue claims, ordering, cancellation, retry, account lifecycle and monitor coordination
download, filepublish Metadata dedup, verified byte reuse, streaming SHA-256, exclusive publication and recovery journals
store, dbread SQLite migrations, transactional writes and bounded read projections
auth Password hashes, web sessions and credential revocation
webassets/public Browser ES modules, prebuilt styles and static pages embedded in the binary
backup, cluster, rescue Backups and offline restore, peer pairing and catalog sync, rescue retention
thumbs, faststart, seekbar, jobs Thumbnails, MP4 faststart rewrites, seekbar sprites and tracked background jobs
nsfw Client for the tgdl-nsfw sidecar (the faces client lives in app)

The front, dbscan and seekbar packages started in tgdl-core, the 2.x Go helper, and are now part of the server. The only application build and release target is cmd/tgdl-server.

Durable download flow

Fresh Telegram metadata supplies lossless media/message identities before a transfer is accepted. Work is persisted and claimed exclusively, including message edit ordering. Existing catalog identities are checked against actual files; verified content may serve several message rows. Transfers hash bytes as they arrive and publish with an exclusive rename, so a concurrent destination cannot be overwritten. Journals allow a published file to be registered after a restart without downloading it again. Deleting one catalog owner preserves bytes still referenced by another owner.

This behavior is covered by native fixture and integration tests in internal/download, internal/engine and internal/app.

State and process boundaries

TGDL_DATA_DIR contains db.sqlite, encrypted account sessions, downloads, private keys, logs, generated previews and backups. Start exactly one server writer per library. Process and account locks prevent duplicate ownership. Configuration and web sessions are stored in SQLite; migrations run before health becomes ready. Native setup talks to the running server over loopback, rather than opening a second writer.

The media server confines file access to directory handles. Gallery paths honor stored nested paths and distinguish existing root files from the historical filename-only group layout. Permission errors never prove that a legacy file is missing. Read requests and file deletion enforce authentication and shared-file ownership independently of the browser.

On termination, HTTP requests drain, workers are canceled and joined, then the owned database closes. Compose provides 60 seconds before a forced stop.

Build and verification

Use make build, make test and make check. Go CI runs formatting, vet, race tests and native/cross builds. Docker CI checks an actual candidate container before publication. scripts/build-server-release.sh creates native archives and SHA-256 checksums; tagged app releases must match the source AppVersion.

The removed Node backend, its harness and the 2.x route snapshots are available in Git at aa83eed. New behavior and security regressions are tested in Go.

The faces-service and nsfw-service folders are separate sidecar projects with their own release workflows (images tgdl-faces and tgdl-nsfw). The server calls them over HTTP when their URL is configured. seekbar-service is no longer used: seekbar sprites are built in the server with ffmpeg. See AI.

Further details: deployment, configuration, and the engineering notes on HTTP policy, session lifetime, history, URL downloads and recovery.