Project Build Process
Relevant source files
The following files were used as context for generating this wiki page:
The build and deployment process for the Discord Live Translator is a multi-stage system involving a TypeScript-based Discord bot, a Rust-based Speech-to-Text (STT) service, and other supporting services. The primary and recommended method for hosting is using Docker, which orchestrates all the necessary components.
The process can be broken down into three main parts: building the TypeScript application, running the containerized services via Docker Compose, and deploying the Discord slash commands required for bot interaction. While the Docker images are pre-built, understanding the underlying build scripts is useful for development.
TypeScript Bot Build
The core bot logic is written in TypeScript and must be compiled into JavaScript before execution. The build process is defined in package.json and executed by a shell script.
Sources: package.json:11, build.sh
Build Script (build.sh)
The build command in package.json executes the build.sh script. This script prepares the output directory and runs the TypeScript compiler (tsc).
# build.sh
mkdir -p ./dist
rm -rf ./dist/*
cp -r ./src/lib ./dist
tsc
Sources: build.sh:1-4, package.json:11
The following diagram illustrates the steps executed by the build script.
Sources: build.sh:1-4
TypeScript Configuration (tsconfig.json)
The TypeScript compiler (tsc) is configured via tsconfig.json. This file specifies that the project extends the base configuration for Node.js 20 and defines the output directory and source map generation.
| Option | Value | Description |
|---|---|---|
extends | @tsconfig/node20/tsconfig.json | Inherits a base set of modern Node.js compiler options. |
outDir | ./dist | Specifies the output directory for compiled JavaScript files. |
sourceMap | true | Generates corresponding .map files for debugging. |
Sources: tsconfig.json:1-5
Rust STT Service
The Speech-to-Text (STT) functionality is provided by a separate microservice written in Rust. This service is defined in the stt/ directory.
Dependencies (stt/Cargo.toml)
The Cargo.toml file lists the dependencies for the STT service, which include the actix-web framework for creating the web server and whisper-rs for the speech recognition model.
# stt/Cargo.toml
[dependencies]
actix-web = "4"
num_cpus = "1.16.0"
hound = "3.5.1"
whisper-rs = "0.10.0"
futures = "0.3.29"
lazy_static = "1.4.0"
simple_logger = "4.3.0"
log = "0.4.20"
Sources: stt/Cargo.toml:6-15
The service exposes a single POST endpoint at / that accepts .wav audio files and returns the transcribed text.
Sources: stt/src/main.rs:49-51
Production Deployment with Docker
The recommended deployment method uses Docker and Docker Compose to run the entire application stack. The configuration is defined in docker-compose.prod.yml.
Sources: docker-compose.prod.yml, README.md:22-24
Service Orchestration
The docker-compose.prod.yml file defines four main services: the bot itself, the STT service, a translation service, and a Redis database. The bot and stt services use pre-built images from the GitHub Container Registry (ghcr.io).
This diagram shows the components and their connections as defined in the Docker Compose file.
Sources: docker-compose.prod.yml:3-32
Service Details
| Service | Image | Description |
|---|---|---|
bot | ghcr.io/wotschofsky/discord-live-translator | The main Discord bot application. It depends on all other services. |
stt | ghcr.io/wotschofsky/discord-live-translator/stt | The Rust-based Speech-to-Text service. |
libretranslate | libretranslate/libretranslate:v1.3.11 | Provides translation capabilities. Limited to specific languages (de,en,es,fr,it). |
redis | redis:alpine | A Redis instance used for storing user settings, with data persisted in a volume. |
Sources: docker-compose.prod.yml:5-32
Slash Command Deployment
For the bot to be interactive, its slash commands must be registered with Discord's API. This is a separate step performed after the bot is running.
Manual Deployment
The package.json file includes a deploy script that executes src/deploy.ts using ts-node. This script registers the commands globally. The README.md instructs users to run this script inside the running bot container.
// package.json
"scripts": {
"deploy": "ts-node src/deploy.ts",
...
}
Sources: package.json:12, README.md:28-30
The deployment process is illustrated below.
Automatic Guild-Specific Deployment
Alternatively, if the GUILD_ID and CLIENT_ID environment variables are set, the bot will automatically register/update the slash commands for that specific guild upon startup. This is useful for development and testing.
Sources: src/app.ts:46-52, README.md:34-36
Conclusion
The project's build and deployment architecture is robust, leveraging TypeScript for the main application, Rust for a performance-critical STT microservice, and Docker for orchestrating the entire stack. The use of pre-built container images simplifies production deployment to a single docker compose up command, with a subsequent manual step to register Discord commands. This modular, containerized approach ensures consistency and scalability.