Index your code with Devin

[DeepWiki](https://deepwiki.com/)

[DeepWiki](https://deepwiki.com/)

[YouROK/TorrServer](https://github.com/YouROK/TorrServer "Open repository")

Index your code with

Devin
Edit WikiShare

Last indexed: 28 February 2026 ( [d26699](https://github.com/YouROK/TorrServer/commits/d266990f))

- [Overview](https://deepwiki.com/YouROK/TorrServer/1-overview)
- [System Architecture](https://deepwiki.com/YouROK/TorrServer/2-system-architecture)
- [Backend System](https://deepwiki.com/YouROK/TorrServer/3-backend-system)
- [Server Initialization and Lifecycle](https://deepwiki.com/YouROK/TorrServer/3.1-server-initialization-and-lifecycle)
- [BitTorrent Engine (BTServer)](https://deepwiki.com/YouROK/TorrServer/3.2-bittorrent-engine-(btserver))
- [Cache and Storage System](https://deepwiki.com/YouROK/TorrServer/3.3-cache-and-storage-system)
- [Reader and Priority Management](https://deepwiki.com/YouROK/TorrServer/3.4-reader-and-priority-management)
- [Torrent Management API](https://deepwiki.com/YouROK/TorrServer/3.5-torrent-management-api)
- [Web Server and Middleware](https://deepwiki.com/YouROK/TorrServer/3.6-web-server-and-middleware)
- [Static Asset Serving](https://deepwiki.com/YouROK/TorrServer/3.7-static-asset-serving)
- [Streaming and Playback](https://deepwiki.com/YouROK/TorrServer/3.8-streaming-and-playback)
- [REST API Reference](https://deepwiki.com/YouROK/TorrServer/3.9-rest-api-reference)
- [Optional Services](https://deepwiki.com/YouROK/TorrServer/3.10-optional-services)
- [Database and Persistence](https://deepwiki.com/YouROK/TorrServer/3.11-database-and-persistence)
- [Frontend System](https://deepwiki.com/YouROK/TorrServer/4-frontend-system)
- [Application Bootstrap and PWA](https://deepwiki.com/YouROK/TorrServer/4.1-application-bootstrap-and-pwa)
- [Build System and Asset Pipeline](https://deepwiki.com/YouROK/TorrServer/4.2-build-system-and-asset-pipeline)
- [Component Architecture](https://deepwiki.com/YouROK/TorrServer/4.3-component-architecture)
- [Torrent Management UI](https://deepwiki.com/YouROK/TorrServer/4.4-torrent-management-ui)
- [Torrent Details and Cache Visualization](https://deepwiki.com/YouROK/TorrServer/4.5-torrent-details-and-cache-visualization)
- [Settings and Configuration UI](https://deepwiki.com/YouROK/TorrServer/4.6-settings-and-configuration-ui)
- [Internationalization and Localization](https://deepwiki.com/YouROK/TorrServer/4.7-internationalization-and-localization)
- [Search Integration](https://deepwiki.com/YouROK/TorrServer/4.8-search-integration)
- [Configuration and Settings](https://deepwiki.com/YouROK/TorrServer/5-configuration-and-settings)
- [Command-Line Arguments](https://deepwiki.com/YouROK/TorrServer/5.1-command-line-arguments)
- [BitTorrent Configuration](https://deepwiki.com/YouROK/TorrServer/5.2-bittorrent-configuration)
- [Network and Proxy Settings](https://deepwiki.com/YouROK/TorrServer/5.3-network-and-proxy-settings)
- [Security and Authentication](https://deepwiki.com/YouROK/TorrServer/5.4-security-and-authentication)
- [Cache and Storage Configuration](https://deepwiki.com/YouROK/TorrServer/5.5-cache-and-storage-configuration)
- [External Service Configuration](https://deepwiki.com/YouROK/TorrServer/5.6-external-service-configuration)
- [Deployment and Installation](https://deepwiki.com/YouROK/TorrServer/6-deployment-and-installation)
- [Linux Installation](https://deepwiki.com/YouROK/TorrServer/6.1-linux-installation)
- [macOS Installation](https://deepwiki.com/YouROK/TorrServer/6.2-macos-installation)
- [Docker Deployment](https://deepwiki.com/YouROK/TorrServer/6.3-docker-deployment)
- [Platform-Specific Considerations](https://deepwiki.com/YouROK/TorrServer/6.4-platform-specific-considerations)
- [Development Guide](https://deepwiki.com/YouROK/TorrServer/7-development-guide)
- [Building from Source](https://deepwiki.com/YouROK/TorrServer/7.1-building-from-source)
- [Project Structure](https://deepwiki.com/YouROK/TorrServer/7.2-project-structure)
- [Backend Development](https://deepwiki.com/YouROK/TorrServer/7.3-backend-development)
- [Frontend Development](https://deepwiki.com/YouROK/TorrServer/7.4-frontend-development)
- [Testing and CI/CD](https://deepwiki.com/YouROK/TorrServer/7.5-testing-and-cicd)
- [Contributing Guidelines](https://deepwiki.com/YouROK/TorrServer/7.6-contributing-guidelines)

Menu

# Build System and Asset Pipeline

Relevant source files

- [.gitignore](https://github.com/YouROK/TorrServer/blob/d266990f/.gitignore)
- [build-all.sh](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh)
- [gen\_web.go](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go)
- [web/package.json](https://github.com/YouROK/TorrServer/blob/d266990f/web/package.json)
- [web/src/components/Add/AddDialog.jsx](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/AddDialog.jsx)
- [web/src/components/Add/LeftSideComponent.jsx](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/LeftSideComponent.jsx)
- [web/src/components/Add/RightSideComponent.jsx](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/RightSideComponent.jsx)
- [web/src/components/Add/TorznabSearch.jsx](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/TorznabSearch.jsx)
- [web/src/components/Add/helpers.js](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/helpers.js)
- [web/src/components/Add/style.js](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Add/style.js)
- [web/src/components/Search/SearchDialog.jsx](https://github.com/YouROK/TorrServer/blob/d266990f/web/src/components/Search/SearchDialog.jsx)
- [web/yarn.lock](https://github.com/YouROK/TorrServer/blob/d266990f/web/yarn.lock)

This page documents the process by which the React frontend is compiled into static assets and embedded into the Go binary. It covers the `yarn`-based frontend build, the `gen_web.go` code generator, and the generated Go source files that wire assets into the HTTP server.

For how the resulting embedded assets are served at runtime, see [Static Asset Serving](https://deepwiki.com/YouROK/TorrServer/3.7-static-asset-serving). For how to run these steps as a developer, see [Building from Source](https://deepwiki.com/YouROK/TorrServer/7.1-building-from-source).

* * *

## Overview

TorrServer ships a single self-contained binary that includes the entire web UI. This is achieved through a two-phase pipeline:

1. **Frontend build**: Yarn and `react-scripts` compile the React source in `web/` into static HTML, JS, and CSS in `web/build/`.
2. **Code generation**: `gen_web.go` copies that build output into the Go source tree and generates Go source files that embed every file and register them as Gin HTTP routes.

The resulting generated source files are compiled into the Go binary via the standard `go build` step.

**Pipeline overview diagram:**

```
yarn run build

gen_web.go copies

gen_web.go generates

gen_web.go generates

go:embed directives

RouteWebPages() registers routes

web/src/ (React source)

web/build/ (static assets)

server/web/pages/template/pages/

server/web/pages/template/html.go

server/web/pages/template/route.go

Go binary
```

Sources: [gen\_web.go1-97](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L1-L97) [build-all.sh53-56](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh#L53-L56)

* * *

## Frontend Build (`web/`)

The frontend is a React 17 application managed by Yarn.

### Package Configuration

[web/package.json1-70](https://github.com/YouROK/TorrServer/blob/d266990f/web/package.json#L1-L70) defines the project metadata and scripts.

| Script | Command | Purpose |
| --- | --- | --- |
| `start` | `react-scripts start` | Dev server with hot reload |
| `build` | `react-scripts build` | Production build to `web/build/` |
| `test` | `react-scripts test` | Jest test runner |
| `lint` | `eslint --ext .js,.jsx src` | ESLint check |
| `fix` | `yarn lint --fix` | Auto-fix lint errors |

The `"homepage": "./"` field in `package.json` [web/package.json69](https://github.com/YouROK/TorrServer/blob/d266990f/web/package.json#L69-L69) instructs Create React App to generate relative asset paths, which is necessary since the app is served from a Go binary at any path prefix.

### Key Production Dependencies

| Package | Version | Role |
| --- | --- | --- |
| `react` | `^17.0.2` | UI framework |
| `react-dom` | `^17.0.2` | DOM renderer |
| `react-scripts` | `4.0.3` | CRA build toolchain (webpack, Babel) |
| `@material-ui/core` | `^4.11.4` | Component library |
| `styled-components` | `^5.3.11` | CSS-in-JS |
| `i18next` | `^20.3.1` | Internationalization |
| `axios` | `^1.13.5` | HTTP client |
| `react-query` | `^3.39.3` | Server state management |
| `parse-torrent` | `^9.1.3` | Torrent metadata parsing |

Sources: [web/package.json5-29](https://github.com/YouROK/TorrServer/blob/d266990f/web/package.json#L5-L29)

### Build Output Structure

After `yarn run build`, the `web/build/` directory contains:

```
web/build/
├── index.html              # Main HTML entry point
├── manifest.webmanifest    # PWA manifest
├── favicon.ico
├── logo*.png               # PWA icons
└── static/
    ├── css/
    │   └── main.*.chunk.css
    ├── js/
    │   ├── main.*.chunk.js
    │   └── runtime-main.*.js
    └── media/
        └── (fonts, images, etc.)
```

All JS and CSS filenames include a content hash, so `Cache-Control: immutable` semantics apply automatically once served.

### OpenSSL Compatibility

`build-all.sh` [build-all.sh55](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh#L55-L55) sets `NODE_OPTIONS=--openssl-legacy-provider` before invoking `gen_web.go`. This is required because `react-scripts` 4.0.3 uses a webpack version that is incompatible with the OpenSSL 3.x API available in Node.js 17+.

Sources: [build-all.sh54-56](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh#L54-L56) [web/package.json25](https://github.com/YouROK/TorrServer/blob/d266990f/web/package.json#L25-L25)

* * *

## Code Generator (`gen_web.go`)

`gen_web.go` is a standalone Go program at the repository root. It is invoked with `go run gen_web.go` and performs three tasks: triggering the frontend build if needed, copying the build output into the Go source tree, and generating the embed and routing source files.

### Execution Flow

**`gen_web.go` execution diagram:**

```

yes

no

no

yes

go run gen_web.go

--clean flag?

rm -rf web/build

web/build/static exists?

run('yarn')

run('yarn','run','build')

rm -rf server/web/pages/template/pages/
cp -r web/build/ server/web/pages/template/pages/

filepath.WalkDir(srcGo+template/pages/)

writeEmbed() → html.go

writeRoute() → route.go
```

Sources: [gen\_web.go17-97](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L17-L97)

### Path Constants

The two key path strings are defined as local variables in `main()`:

| Variable | Value | Purpose |
| --- | --- | --- |
| `compileHtml` | `"web/build/"` | React build output |
| `srcGo` | `"server/web/pages/"` | Destination in Go source tree |

The build output is copied to `server/web/pages/template/pages/`, which is listed in `.gitignore` [.gitignore36](https://github.com/YouROK/TorrServer/blob/d266990f/.gitignore#L36-L36) and is regenerated on every build.

Sources: [gen\_web.go53-54](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L53-L54)

### `writeEmbed()` — Generating `html.go`

[gen\_web.go99-122](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L99-L122) generates `server/web/pages/template/html.go`. For each file found in the copied directory tree, it emits a `//go:embed` directive and a `[]byte` variable declaration.

The variable name for each file is produced by `cleanName()` [gen\_web.go184-191](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L184-L191) which strips all non-alphanumeric characters from the file path and title-cases the result. For example:

| File path | Variable name |
| --- | --- |
| `/index.html` | `Indexhtml` |
| `/static/css/main.abc123.chunk.css` | `StaticCssMainAbc123Chunkcss` |
| `/favicon.ico` | `Faviconico` |

The generated file begins with:

```
package template

import (
    _ "embed"
)

//go:embed pages/index.html
var Indexhtml []byte

//go:embed pages/static/css/main.abc123.chunk.css
var StaticCssMainAbc123Chunkcss []byte
// ...
```

Sources: [gen\_web.go99-122](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L99-L122) [gen\_web.go184-191](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L184-L191)

### `writeRoute()` — Generating `route.go`

[gen\_web.go124-175](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L124-L175) generates `server/web/pages/template/route.go`. This file contains the `RouteWebPages` function that registers a Gin GET handler for every embedded file.

**Generated route structure diagram:**

```
RouteWebPages(route)

gin.IRouter

GET /
serves Indexhtml

GET /static/js/.js
GET /static/css/.css
GET /favicon.ico
...

Cache-Control: public max-age=31536000
ETag: md5(Indexhtml)

Cache-Control: public max-age=31536000
ETag: md5(fileBytes)
```

Each handler:

1. Computes `etag` as `fmt.Sprintf("%x", md5.Sum(varName))`
2. Sets `Cache-Control: public, max-age=31536000`
3. Sets the `ETag` header
4. Calls `c.Data(200, mimeType, varBytes)`

MIME types are resolved from file extensions using `mime.TypeByExtension`. Two special cases are registered [gen\_web.go147-148](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L147-L148):

| Extension | MIME type |
| --- | --- |
| `.map` | `application/json` |
| `.webmanifest` | `application/manifest+json` |

Additionally, `image/x-icon` is remapped to `image/vnd.microsoft.icon` [gen\_web.go157-159](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L157-L159) for cross-browser compatibility, and XML/JS types get `; charset=utf-8` appended.

Sources: [gen\_web.go124-175](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L124-L175)

* * *

## Integration with the Build Script

`build-all.sh` runs the full pipeline in sequence:

```
"go build ./cmd""swag init""yarn run build""go run gen_web.go""build-all.sh""go build ./cmd""swag init""yarn run build""go run gen_web.go""build-all.sh""go run gen_web.go""if web/build/static missing""web/build/ populated""copy assets, generate html.go + route.go""done""swag init -g web/server.go""docs/ generated""for each GOOS/GOARCH""dist/TorrServer-* binaries"
```

Sources: [build-all.sh53-89](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh#L53-L89)

The `go build` step at [build-all.sh83](https://github.com/YouROK/TorrServer/blob/d266990f/build-all.sh#L83-L83) uses `-tags=nosqlite -trimpath` and `ldflags='-s -w -checklinkname=0'`. The `nosqlite` tag is described in [Platform-Specific Considerations](https://deepwiki.com/YouROK/TorrServer/6.4-platform-specific-considerations).

* * *

## Generated File Locations

| Generated file | Contents | Regenerated by |
| --- | --- | --- |
| `server/web/pages/template/pages/` | Copy of `web/build/` | `gen_web.go` main |
| `server/web/pages/template/html.go` | `//go:embed` \+ `[]byte` vars | `writeEmbed()` |
| `server/web/pages/template/route.go` | `RouteWebPages()` Gin handler | `writeRoute()` |

The `server/web/pages/template/pages/` directory is excluded from version control via `.gitignore` [.gitignore36](https://github.com/YouROK/TorrServer/blob/d266990f/.gitignore#L36-L36) because it is derived output. The generated `.go` files (`html.go`, `route.go`) are also regenerated and should not be edited manually.

Sources: [gen\_web.go53-96](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L53-L96) [.gitignore36](https://github.com/YouROK/TorrServer/blob/d266990f/.gitignore#L36-L36)

* * *

## Caching Strategy

Every file served by `RouteWebPages` gets identical cache headers:

- `Cache-Control: public, max-age=31536000` — one year, publicly cacheable
- `ETag: <md5hex>` — content-addressed, computed at startup from the embedded bytes

Because Create React App generates content-hashed filenames for JS and CSS bundles (e.g., `main.a1b2c3d4.chunk.js`), the filenames themselves change when content changes. The root `index.html` is the only file that is not content-hashed by filename, but it still receives an MD5 ETag so browsers can detect changes on next request.

This means:

- Static assets (`/static/**`) are effectively immutable for the lifetime of a binary version.
- The root `/` handler returns the correct `index.html` for the current binary, with an ETag for conditional GETs.

Sources: [gen\_web.go139-145](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L139-L145) [gen\_web.go163-169](https://github.com/YouROK/TorrServer/blob/d266990f/gen_web.go#L163-L169)

This wiki is featured in the [repository](https://github.com/YouROK/TorrServer/blob/master/README.md)

Dismiss

Refresh this wiki

Enter email to refresh

### On this page

- [Build System and Asset Pipeline](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#build-system-and-asset-pipeline)
- [Overview](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#overview)
- [Frontend Build (\`web/\`)](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#frontend-build-web)
- [Package Configuration](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#package-configuration)
- [Key Production Dependencies](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#key-production-dependencies)
- [Build Output Structure](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#build-output-structure)
- [OpenSSL Compatibility](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#openssl-compatibility)
- [Code Generator (\`gen\_web.go\`)](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#code-generator-gen_webgo)
- [Execution Flow](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#execution-flow)
- [Path Constants](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#path-constants)
- [\`writeEmbed()\` — Generating \`html.go\`](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#writeembed-generating-htmlgo)
- [\`writeRoute()\` — Generating \`route.go\`](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#writeroute-generating-routego)
- [Integration with the Build Script](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#integration-with-the-build-script)
- [Generated File Locations](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#generated-file-locations)
- [Caching Strategy](https://deepwiki.com/YouROK/TorrServer/4.2-rest-api-endpoints#caching-strategy)

Ask Devin about YouROK/TorrServer

Fast