Skip to Content
agentic-yt

Self-hosting and deployment

The services that make up agentic-yt, the environment each one needs, and notes for running your own.

agentic-yt is a Bun workspace with four apps and three shared packages. Nothing is compiled ahead of time except the web app; the packages are consumed as TypeScript source.

The pieces

ServiceWhat it doesNeeds
api (apps/api)The HTTP API, /openapi.json, and the Scalar reference at /docs. Validates every request against the route table, answers from cache, enqueues jobs.Postgres, Redis
worker (apps/worker)Runs download, clip and frames jobs: fetches from YouTube, transcodes, uploads to storage. This is the only place yt-dlp and ffmpeg are needed.Postgres, Redis, storage
web (apps/web)This site: landing page, docs, dashboard. Reads and writes Postgres directly.Postgres, Clerk
cli (apps/cli)The agentic-yt / ayt program. Not deployed; published to npm and as standalone binaries.—

Plus Postgres (accounts, tokens, jobs, the cache index), Redis (job queue, rate limits) and object storage for the files.

Environment

Shared by the server-side apps:

VariableUsed byNotes
DATABASE_URLapi, worker, webPostgres connection string.
DB_POOL_MAXapi, worker, webPool size per process. Default 10.
REDIS_URLapi, workerJob queue and rate limits.
ENCRYPTION_KEYapi, worker, web32 bytes as 64 hex characters or base64. Encrypts YouTube cookies at rest. Must be identical everywhere, or cookies saved in the dashboard cannot be read by the worker.
STORAGE_DRIVERapi, worker, webuploadx or local. Defaults to uploadx when UPLOADX_TOKEN is set, else local.
UPLOADX_TOKEN, UPLOADX_URLapi, worker, webFor the uploadx driver.
LOCAL_STORAGE_DIRapi, workerFor the local driver. Default .data/storage.
LOCAL_STORAGE_URLapi, workerPublic URL prefix for local files; the API serves the directory there. Unset means file:// URLs, which only work on the same machine.
API_URLapi, webPublic origin of the API.
WEB_URLapi, webPublic origin of this site. The API builds the CLI login verification_url from it.
PORTapi, webListen port.

Generate a key with openssl rand -hex 32. Losing it means every stored cookie is unreadable and every connected account must be reconnected.

Web app

VariableWhenNotes
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYbuild + runClerk publishable key. Inlined into the client bundle, so it must be present at build time.
CLERK_SECRET_KEYrunClerk secret key.
NEXT_PUBLIC_API_URLbuildPublic API origin used in links, examples and the reference link. Default https://api.agentic-yt.crafter.run.
NEXT_PUBLIC_WEB_URLbuildThis site's origin, used for absolute links in llms.txt. Falls back to WEB_URL.
API_INTERNAL_URLrunWhere the server reaches the API (playground, admin health). Falls back to API_URL, then the public URL. Point it at the private network address.
DATABASE_URL, ENCRYPTION_KEYrunAs above. Not needed at build time.
ALLOWED_EMAILSrunComma-separated allowlist. An entry starting with @ matches a whole domain: ada@example.com,@crafter.run. Unset means anyone who can sign in gets a dashboard.
ADMIN_EMAILSrunComma-separated, same syntax. These accounts get the admin role, and always pass the allowlist.
ACCESS_REQUEST_EMAILrunWhere the request-access button sends mail. Optional.
UPLOADX_TOKEN, UPLOADX_URLrunOptional. Lets the dashboard re-sign download links that have expired.

CLI and SDK

AGENTIC_YT_TOKEN and AGENTIC_YT_URL — point AGENTIC_YT_URL at your own API.

Database

bun install
bun run db:migrate        # applies packages/db/drizzle/*.sql

Migrations are plain SQL files generated from packages/db/src/schema.ts with bun run db:generate. Run db:migrate on every deploy before starting the new api and worker.

Running it

bun run --cwd apps/api start        # the API
bun run --cwd apps/worker start     # the worker (needs yt-dlp and ffmpeg on PATH)
bun run --cwd apps/web build && bun run --cwd apps/web start

The web app builds with output: "standalone", so a container only needs apps/web/.next/standalone, .next/static and public. apps/web/Dockerfile does this; build it from the repository root so the workspace packages are in the build context:

docker build -f apps/web/Dockerfile \
  --build-arg NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_… \
  --build-arg NEXT_PUBLIC_API_URL=https://api.example.com \
  --build-arg NEXT_PUBLIC_WEB_URL=https://example.com \
  -t agentic-yt-web .

No database is contacted during the build: docs and the landing page are static, and every dashboard route is rendered per request.

Things that bite

  • Clerk. Add your site's origin to the Clerk application, and keep sign-in at /sign-in and sign-up at /sign-up — the app's proxy redirects there.
  • First admin. Put your own email in ADMIN_EMAILS before you first sign in. Roles are never removed automatically; demote in the database.
  • System YouTube accounts. Without at least one (Admin → System YouTube accounts), videos that YouTube blocks for anonymous clients fail with youtube_blocked for users who have not connected their own. Use throwaway accounts.
  • Egress. YouTube blocks datacenter addresses aggressively. Where the worker's traffic comes from matters more than anything else in this list.
  • Storage growth. Files are evicted least-recently-used first; watch the cache size on the admin page.
  • CORS and the reference. The Scalar reference is served by the API at /docs; the web app only links to it.

On this page