Skip to main content

Overview

TikTok Miner requires several environment variables for database connections, API integrations, and application configuration. This guide documents all available variables, their purposes, and whether they are required or optional.

Quick Setup

Copy the example environment file:
cp app/.env.example app/.env
Then configure the variables below based on your deployment needs.

Database Configuration

PostgreSQL Connection

DATABASE_URL
string
required
Connection string for the PostgreSQL database. Used for connection pooling.Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?pgbouncer=true&connection_limit=1&pool_timeout=0Example:
DATABASE_URL="postgresql://tiktok_miner_user:your-password@localhost:5432/tiktok_miner?pgbouncer=true&connection_limit=1"
For Supabase users, this should use the pooler URL with port 6543.
DIRECT_URL
string
required
Direct connection to PostgreSQL, used for running migrations.Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASEExample:
DIRECT_URL="postgresql://tiktok_miner_user:your-password@localhost:5432/tiktok_miner"
For Supabase, use port 5432 (not the pooler port) for migrations.
PASSWORD
string
required
Database password used in connection strings.Example:
PASSWORD=your-secure-database-password

Redis Configuration

REDIS_URL
string
required
Redis connection URL for job queues and caching.Format: redis://[username][:password]@host:port[/database]Example:
REDIS_URL="redis://:your-redis-password@localhost:6379"
The REDIS_URL is automatically configured in docker-compose.yml but needs to be set for local development.

Supabase Configuration

NEXT_PUBLIC_SUPABASE_URL
string
required
Your Supabase project URL.Example:
NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY
string
required
Supabase anonymous/public API key.Example:
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
This key is safe to use in client-side code as it has limited permissions.

AI & LLM Configuration

OpenAI

OPENAI_API_KEY
string
required
OpenAI API key for AI-powered features like creator analysis and content categorization.Example:
OPENAI_API_KEY=sk-proj-...
Never commit this key to version control. Keep it secret.
OPENAI_MODEL
string
default:"gpt-4o"
OpenAI model to use for text generation.Options: gpt-4o, gpt-4-turbo, gpt-4, gpt-3.5-turboExample:
OPENAI_MODEL=gpt-4o
OPENAI_TEMPERATURE
number
default:"0.7"
Controls randomness in AI responses. Range: 0.0 to 2.0
  • Lower values (0.0-0.3): More focused and deterministic
  • Medium values (0.4-0.7): Balanced creativity
  • Higher values (0.8-2.0): More creative and varied
Example:
OPENAI_TEMPERATURE=0.7
OPENAI_MIN_CONFIDENCE
number
default:"0.5"
Minimum confidence threshold for AI predictions. Range: 0.0 to 1.0Example:
OPENAI_MIN_CONFIDENCE=0.5

Perplexity AI

PERPLEXITY_API_KEY
string
Perplexity API key for enhanced research and discovery features.Example:
PERPLEXITY_API_KEY=pplx-...

GitHub Integration

GITHUB_TOKEN
string
required
GitHub personal access token for API access and rate limit management.Permissions needed: public_repo, read:userExample:
GITHUB_TOKEN=ghp_...
GITHUB_TOKENS
string
Multiple GitHub tokens for load balancing (comma-separated).Example:
GITHUB_TOKENS=ghp_token1,ghp_token2,ghp_token3
Using multiple tokens helps avoid rate limits on high-traffic deployments.
GITHUB_TOKEN_LB_STRATEGY
string
default:"ROUND_ROBIN"
Load balancing strategy for multiple GitHub tokens.Options: ROUND_ROBINExample:
GITHUB_TOKEN_LB_STRATEGY=ROUND_ROBIN

Social Media API Keys

TikTok

TIKTOK_CLIENT_KEY
string
required
TikTok API client key for accessing TikTok data.Example:
TIKTOK_CLIENT_KEY=your-client-key
Register your app at: https://developers.tiktok.com/
TIKTOK_CLIENT_SECRET
string
required
TikTok API client secret.Example:
TIKTOK_CLIENT_SECRET=your-client-secret

Instagram

INSTAGRAM_CLIENT_ID
string
Instagram/Facebook Graph API client ID.Example:
INSTAGRAM_CLIENT_ID=your-instagram-client-id
INSTAGRAM_CLIENT_SECRET
string
Instagram/Facebook Graph API client secret.Example:
INSTAGRAM_CLIENT_SECRET=your-instagram-secret

Twitter/X

TWITTER_BEARER_TOKEN
string
Twitter API v2 bearer token for read-only access.Example:
TWITTER_BEARER_TOKEN=AAAAAAAAAAAAAAAAAAAAAMLheAAAAAAA...
Get your bearer token from: https://developer.twitter.com/

YouTube

YOUTUBE_API_KEY
string
YouTube Data API v3 key.Example:
YOUTUBE_API_KEY=AIzaSy...
Create API credentials at: https://console.cloud.google.com/

Email Configuration

Azure Email Service

AZURE_EMAIL_CONNECTION_STRING
string
Azure Communication Services connection string for sending emails.Format: endpoint=https://...;accesskey=...Example:
AZURE_EMAIL_CONNECTION_STRING="endpoint=https://your-communication.communication.azure.com/;accesskey=your-key"

SMTP Configuration

SMTP_HOST
string
SMTP server hostname.Example:
SMTP_HOST=smtp.gmail.com
SMTP_PORT
number
SMTP server port.Common values:
  • 465: SSL/TLS
  • 587: STARTTLS
  • 25: Unencrypted (not recommended)
Example:
SMTP_PORT=465
SMTP_USER
string
SMTP authentication username (usually your email address).Example:
SMTP_PASSWORD
string
SMTP authentication password or app-specific password.Example:
SMTP_PASSWORD=your-app-password
For Gmail, use an app-specific password, not your account password.
SMTP_SECURE
boolean
default:"true"
Use SSL/TLS for SMTP connection.
  • true: Port 465 (SSL)
  • false: Port 587 (STARTTLS)
Example:
SMTP_SECURE=true
SMTP_AUTH_METHOD
string
default:"login"
SMTP authentication method.Options: login, plain, cram-md5Example:
SMTP_AUTH_METHOD=login

Application Configuration

NODE_ENV
string
default:"development"
Node.js environment mode.Options: development, production, testExample:
NODE_ENV=production
PORT
number
default:"3000"
Port number for the application server.Example:
PORT=3000
NEXT_PUBLIC_APP_URL
string
required
Public URL where the application is hosted. Used for OAuth redirects and email links.Example:
# Development
NEXT_PUBLIC_APP_URL=http://localhost:3000

# Production
NEXT_PUBLIC_APP_URL=https://your-domain.com
LOG_LEVEL
string
default:"info"
Logging verbosity level.Options: debug, info, warn, errorExample:
LOG_LEVEL=debug
Use debug for development and info or warn for production.

pgAdmin Configuration (Development)

PGADMIN_EMAIL
string
Email for pgAdmin login (development only).Example:
PGADMIN_EMAIL=admin@localhost
PGADMIN_PASSWORD
string
default:"admin"
Password for pgAdmin login (development only).Example:
PGADMIN_PASSWORD=secure-password

Environment-Specific Examples

Development Environment

# Database
PASSWORD=dev_password
DATABASE_URL="postgresql://tiktok_miner_user:dev_password@localhost:5432/tiktok_miner"
DIRECT_URL="postgresql://tiktok_miner_user:dev_password@localhost:5432/tiktok_miner"
REDIS_URL="redis://localhost:6379"

# Supabase (if using)
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-local-anon-key

# OpenAI
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o

# GitHub
GITHUB_TOKEN=ghp_...

# Application
NODE_ENV=development
PORT=3000
NEXT_PUBLIC_APP_URL=http://localhost:3000
LOG_LEVEL=debug

Production Environment

# Database - Use strong passwords!
PASSWORD=<generate-strong-password>
DATABASE_URL="postgresql://tiktok_miner_user:<password>@db.example.com:5432/tiktok_miner?pgbouncer=true&connection_limit=1"
DIRECT_URL="postgresql://tiktok_miner_user:<password>@db.example.com:5432/tiktok_miner"
REDIS_URL="redis://:<redis-password>@redis.example.com:6379"

# Supabase
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...

# OpenAI
OPENAI_API_KEY=sk-proj-...
OPENAI_MODEL=gpt-4o
OPENAI_TEMPERATURE=0.7

# GitHub - Use multiple tokens for load balancing
GITHUB_TOKEN=ghp_...
GITHUB_TOKENS=ghp_token1,ghp_token2,ghp_token3
GITHUB_TOKEN_LB_STRATEGY=ROUND_ROBIN

# Social Media APIs
TIKTOK_CLIENT_KEY=...
TIKTOK_CLIENT_SECRET=...
INSTAGRAM_CLIENT_ID=...
INSTAGRAM_CLIENT_SECRET=...
TWITTER_BEARER_TOKEN=...
YOUTUBE_API_KEY=...

# Email
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=[email protected]
SMTP_PASSWORD=<app-specific-password>
SMTP_SECURE=true

# Application
NODE_ENV=production
PORT=3000
NEXT_PUBLIC_APP_URL=https://yourdomain.com
LOG_LEVEL=warn

Security Best Practices

Never commit .env files to version control!Always add .env to your .gitignore:
echo ".env" >> .gitignore
  1. Use strong passwords: Generate secure random passwords for databases and Redis
  2. Rotate API keys: Regularly rotate sensitive API keys and tokens
  3. Limit permissions: Use API keys with minimum required permissions
  4. Environment isolation: Use different keys for development and production
  5. Secret management: Consider using secret management services like:
    • AWS Secrets Manager
    • HashiCorp Vault
    • Azure Key Vault
    • Google Secret Manager

Validation

Validate your environment configuration:
cd app
bun run validate-apis
This script checks:
  • Database connectivity
  • Redis connection
  • API key validity
  • Required vs optional variables

Troubleshooting

Database Connection Errors

  • Verify PostgreSQL is running: docker-compose ps postgres
  • Check DATABASE_URL format and credentials
  • Ensure database port (5432) is accessible
Add ?sslmode=require to your DATABASE_URL:
DATABASE_URL="postgresql://user:pass@host:5432/db?sslmode=require"
Use DIRECT_URL for migrations, not the pooler URL:
  • Supabase: Port 5432 (not 6543)
  • No pgbouncer parameters

API Key Issues

  • Use multiple tokens with GITHUB_TOKENS
  • Enable GITHUB_TOKEN_LB_STRATEGY=ROUND_ROBIN
  • Check rate limit status in application logs

Next Steps

Docker Deployment

Deploy with Docker Compose

Database Setup

Configure Prisma and run migrations

Build docs developers (and LLMs) love