Development Guide
Prerequisites
Section titled “Prerequisites”SyncTV is a Rust workspace. Local development usually needs:
- Rust stable toolchain.
- PostgreSQL.
- Redis.
- Node.js and npm for the
docs/site. - Docker and Docker Compose for quickly starting dependencies.
- Protobuf/gRPC build dependencies depending on platform and crate build requirements.
Check versions:
rustc --versioncargo --versiondocker --versiondocker compose versionnode --versionnpm --versionRepository Layout
Section titled “Repository Layout”- synctv application binary and CLI
- synctv-core business logic, configuration, services, repositories
- synctv-api HTTP/gRPC API
- synctv-livestream RTMP/HLS/HTTP-FLV
- synctv-cluster cluster coordination
- synctv-proxy media proxy and slice cache
- synctv-proto protobuf definitions
Directoryhelm
- synctv Helm chart
- docs Astro Starlight documentation site
Start Development Dependencies
Section titled “Start Development Dependencies”Start PostgreSQL and Redis:
docker compose -f docker-compose.dev.yml up -d postgres redisStart the whole development stack:
docker compose -f docker-compose.dev.yml up -dDevelopment Compose builds from the local Dockerfile and includes development secrets. It is not for production.
Run Locally
Section titled “Run Locally”-
Start dependencies:
Terminal window docker compose -f docker-compose.dev.yml up -d postgres redis -
Validate configuration:
Terminal window cargo run -p synctv --bin synctv -- config validate -
Start the service:
Terminal window cargo run -p synctv --bin synctv -- serve
With a config file:
cargo run -p synctv --bin synctv -- serve --config synctv.yamlDry-run startup:
cargo run -p synctv --bin synctv -- serve --config synctv.yaml --dry-runConfiguration Validation
Section titled “Configuration Validation”After changing configuration structures:
cargo run -p synctv --bin synctv -- config --config synctv.yaml validateInspect effective config with secrets redacted:
cargo run -p synctv --bin synctv -- config --config synctv.yaml showcargo run -p synctv --bin synctv -- config --config synctv.yaml show --output jsonSee How Configuration Works for precedence and environment variable naming.
Database Migrations
Section titled “Database Migrations”Service startup runs embedded SQLx migrations automatically. To preflight database state without starting the service, run:
cargo run -p synctv --bin synctv -- db migrateCheck database and migration state:
cargo run -p synctv --bin synctv -- db statusIf database state looks wrong, check:
SYNCTV_DATABASE_URLordatabase.url.- PostgreSQL container health.
- Migration files.
- Whether the current branch changed schema or SQL queries.
Tests and Checks
Section titled “Tests and Checks”Whole workspace:
cargo test --workspace --all-targetsOne crate:
cargo test -p synctv-apiOne test:
cargo test -p synctv-api test_nameFormat:
cargo fmt --all --checkClippy:
cargo clippy --workspace --all-targets --all-features -- -D warningsRun focused tests first for the area you changed, then broader checks.
SQLx Offline Metadata
Section titled “SQLx Offline Metadata”SQLx macros validate SQL at compile time and use .sqlx/ metadata for offline builds. Refresh metadata after changing SQL, migrations, or query return types.
Refresh flow:
docker compose -f docker-compose.dev.yml down -vdocker compose -f docker-compose.dev.yml up -d postgres redis
SYNCTV_DATABASE_URL=postgresql://synctv:synctv@localhost:5432/synctv \SYNCTV_JWT_SECRET=dev-jwt-secret-please-change-in-production-1234567890 \SYNCTV_SERVER_CLUSTER_SECRET=dev-cluster-secret-please-change-in-production-1234567890 \SYNCTV_SECURITY_CREDENTIAL_ENCRYPTION_KEY=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f \SYNCTV_SECURITY_OPAQUE_SERVER_SETUP_SECRET=dev-opaque-server-setup-secret-please-change-1234567890 \cargo run -p synctv --bin synctv -- db migrate
DATABASE_URL=postgresql://synctv:synctv@localhost:5432/synctv \cargo sqlx prepare --workspace
SQLX_OFFLINE=true cargo check --workspace --all-targetsOpenAPI Feature
Section titled “OpenAPI Feature”Built-in OpenAPI docs require the openapi feature.
Check:
cargo check --workspace --all-targets --features openapiRun with Swagger UI:
cargo run -p synctv --features openapi --bin synctv -- serveSee OpenAPI Access for URLs.
Documentation Site
Section titled “Documentation Site”The docs site is an Astro Starlight project under docs/.
Install dependencies:
cd docsnpm installLocal preview:
cd docsnpm run devBuild:
cd docsnpm run buildValidate:
cd docsnpm run validateIf deploying under a subpath, set SYNCTV_DOCS_BASE. Set SYNCTV_DOCS_SITE for canonical URLs and sitemap output.
cd docsSYNCTV_DOCS_SITE=https://example.com SYNCTV_DOCS_BASE=/synctv npm run buildSYNCTV_DOCS_BASE is only the path prefix, such as /synctv or /docs. Build output is docs/dist and should not be committed.
When Changing CLI
Section titled “When Changing CLI”CLI definitions live in synctv/src/cli.rs. After changing commands or arguments, check:
cargo run -p synctv --bin synctv -- --helpcargo run -p synctv --bin synctv -- user --helpcargo run -p synctv --bin synctv -- provider --helpUpdate CLI Reference for new commands.
When Changing Helm or Compose
Section titled “When Changing Helm or Compose”Helm:
helm lint ./helm/synctvhelm template synctv ./helm/synctvhelm template synctv ./helm/synctv --set ingress.grpc.enabled=trueCompose:
docker compose -f docker-compose.dev.yml configdocker compose configRendering only proves syntax and templates are valid. Still run SyncTV config validation or an actual startup check.