Sofa

Configuration

Environment variables and server settings.

Required Variables

These three environment variables must be set for Sofa to start:

VariableDescriptionExample
TMDB_API_READ_ACCESS_TOKENTMDB API authentication tokenGet one here
BETTER_AUTH_SECRETSession encryption secret (min 32 chars)openssl rand -base64 32
BETTER_AUTH_URLPublic URL of your instancehttps://sofa.example.com

BETTER_AUTH_URL is critical when using a reverse proxy or OIDC — it must match the URL users access in their browser.

Data & Storage

VariableDefaultDescription
DATA_DIR/data (Docker) or ./data (dev)Root directory for all persistent data
DATABASE_URL${DATA_DIR}/sqlite.dbSQLite database file path
CACHE_DIR${DATA_DIR}/imagesImage cache directory

DATABASE_URL and CACHE_DIR are derived from DATA_DIR by default but can be overridden independently.

The database uses SQLite with WAL (Write-Ahead Logging) mode for concurrent read access. Migrations run automatically on every startup.

Image Caching

VariableDefaultDescription
IMAGE_CACHE_ENABLEDtrueCache TMDB images locally

When enabled, Sofa downloads poster, backdrop, and other images from TMDB and serves them from disk. This improves load times and reduces external requests but uses disk space.

Cached images are stored in subdirectories under CACHE_DIR:

images/
├── posters/       # 500px wide
├── backdrops/     # 1280px wide
├── stills/        # 1280px wide (episode stills)
├── logos/         # 92px wide (provider logos)
└── profiles/      # 185px wide (cast photos)

Set IMAGE_CACHE_ENABLED=false to serve images directly from TMDB's CDN instead.

Logging

VariableDefaultOptions
LOG_LEVELinfoerror, warn, info, debug, trace

Sofa uses structured JSON logging via Pino. Set to debug for troubleshooting.

OIDC / SSO

Sofa supports any OpenID Connect provider (Authentik, Keycloak, Authelia, Google Workspace, etc.). OIDC is enabled when all three of OIDC_CLIENT_ID, OIDC_CLIENT_SECRET, and OIDC_ISSUER_URL are set.

VariableDefaultDescription
OIDC_CLIENT_IDClient ID from your identity provider
OIDC_CLIENT_SECRETClient secret from your identity provider
OIDC_ISSUER_URLIssuer discovery URL
OIDC_PROVIDER_NAMESSOLabel shown on the login button
OIDC_AUTO_REGISTERtrueAuto-create accounts on first OIDC login
DISABLE_PASSWORD_LOGINfalseHide the email/password form (requires OIDC)

Callback URL

Configure this redirect URI in your identity provider:

https://your-sofa-url.com/api/auth/oauth2/callback/oidc

Replace https://your-sofa-url.com with your BETTER_AUTH_URL value.

Example: Authentik

  1. In Authentik, create a new OAuth2/OpenID Provider
  2. Set the redirect URI to https://sofa.example.com/api/auth/oauth2/callback/oidc
  3. Note the Client ID and Client Secret
  4. Add to your .env:
OIDC_CLIENT_ID=your_client_id
OIDC_CLIENT_SECRET=your_client_secret
OIDC_ISSUER_URL=https://authentik.example.com/application/o/sofa
OIDC_PROVIDER_NAME=Authentik

Example: Keycloak

  1. In Keycloak, create a new OpenID Connect client in your realm
  2. Set the Valid Redirect URI to https://sofa.example.com/api/auth/oauth2/callback/oidc
  3. Add to your .env:
OIDC_CLIENT_ID=sofa
OIDC_CLIENT_SECRET=your_client_secret
OIDC_ISSUER_URL=https://keycloak.example.com/realms/your-realm
OIDC_PROVIDER_NAME=Keycloak

Disabling Password Login

To enforce SSO-only login, set DISABLE_PASSWORD_LOGIN=true. This only takes effect when OIDC is configured. The admin account created during setup will still work via OIDC.

Account Linking

When OIDC is enabled, account linking is active by default. If a user logs in via OIDC with an email address that matches an existing Sofa account, the accounts are automatically linked — no manual confirmation is required. This means existing users can start using SSO without losing their library or watch history.

Auto-Registration and Password Login

OIDC_AUTO_REGISTER and DISABLE_PASSWORD_LOGIN interact to control how users can access your instance:

OIDC_AUTO_REGISTERDISABLE_PASSWORD_LOGINBehavior
true (default)false (default)Both login methods available. New OIDC users get accounts created automatically.
truetrueOIDC only. Accounts are auto-created on first login. Password form is hidden.
falsefalseBoth login methods available. OIDC users must have a pre-existing account with a matching email.
falsetrueOIDC only, no auto-registration. Admin must create accounts first via the registration toggle.

TMDB Overrides

VariableDefaultDescription
TMDB_API_BASE_URLhttps://api.themoviedb.org/3Override TMDB API endpoint
TMDB_IMAGE_BASE_URLhttps://image.tmdb.org/t/pOverride TMDB image CDN

These are only needed if you're proxying TMDB requests or using an alternative endpoint.

Network

VariableDefaultDescription
CORS_ORIGINhttp://localhost:3000Allowed CORS origin
PORT3000Server listening port

Set CORS_ORIGIN to your public URL when using a reverse proxy.

Update Checks

Sofa checks for new versions every 6 hours by contacting the public API.

VariableDefaultDescription
PUBLIC_API_URLhttps://public-api.sofa.watchEndpoint for version checks

Update checks can be disabled in Settings → Admin → Update Checks. When a new version is available, a notification appears in the admin settings.

Telemetry

Sofa includes opt-in anonymous telemetry. It is disabled by default. See the Telemetry page for full details on what is and isn't collected.

Scheduled Backups

Automatic backups can be enabled in Settings → Admin → Backups. Configuration options:

SettingDefaultOptions
FrequencyEvery day6h, 12h, 1d, 7d
Time02:00Any HH:MM
Day of weekSunday(for weekly backups)
Retention7Number of scheduled backups to keep

Backups are SQLite database dumps stored in the backups/ directory inside DATA_DIR. Old backups beyond the retention count are automatically deleted.

Background Jobs

Sofa runs several background jobs automatically:

JobScheduleDescription
Library refreshDaily at 3:00 AMRefreshes metadata for tracked titles
Streaming availabilityEvery 6 hoursUpdates where titles are available to stream
RecommendationsEvery 12 hoursRefreshes personalized recommendations
New episodesEvery 12 hoursChecks for new episodes of tracked TV shows
Image cachingTwice dailyCaches images for tracked titles
Credits refreshDaily at 2:00 AMUpdates cast and crew information
Update checkEvery 6 hoursChecks for new Sofa versions
TelemetryDaily at 12:30 AMSends anonymized usage data (if enabled)

All schedules are in UTC. TMDB API calls are rate-limited with a 300ms delay between requests per title to stay within API limits.

On this page