> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Production Deployment

> Deploy Instance to production with managed PostgreSQL, Redis, HTTPS Meta webhooks, and Railway or Docker.

Deploying Instance to production requires HTTPS domains for both your Web Dashboard and API Server so Meta OAuth callbacks and real-time Instagram webhooks work reliably.

***

## 1. Production Environment Variables

Configure these variables in your hosting provider (or `.env` on your server):

```env theme={null}
NODE_ENV="production"

# Public HTTPS URLs
NEXT_PUBLIC_BASE_URL="https://app.yourdomain.com"
NEXT_PUBLIC_APP_URL="https://app.yourdomain.com"
NEXT_PUBLIC_API_URL="https://api.yourdomain.com"
API_URL="https://api.yourdomain.com"

# PostgreSQL (Pooled for runtime, Direct for migrations)
DATABASE_URL="postgresql://user:pass@pooled-host:5432/instance?pgbouncer=true"
DIRECT_URL="postgresql://user:pass@direct-host:5432/instance"

# Redis
REDIS_URL="rediss://default:pass@your-redis-host:6379"

# Auth
NEXTAUTH_URL="https://app.yourdomain.com"
NEXTAUTH_SECRET="your-production-32-byte-secret"

# Instagram / Meta
INSTAGRAM_APP_ID="your-instagram-app-id"
INSTAGRAM_APP_SECRET="your-instagram-app-secret"
INSTAGRAM_REDIRECT_URI="https://app.yourdomain.com/api/instagram/callback"
META_WEBHOOK_VERIFY_TOKEN="your-secure-webhook-verify-token"
```

Make sure you also configure `R2_*` variables if you use media uploads (Bio Link avatars, Sales Chat assets, Automation voice/PDF/images, and Scheduled Posts).

***

## 2. Database Migrations

Instance uses Prisma ORM. Always run migrations using `DIRECT_URL` before starting new API and worker builds:

```bash theme={null}
pnpm run db:deploy
```

* **Why both `DATABASE_URL` and `DIRECT_URL`?** Serverless and managed Postgres providers (like Neon or Supabase) use a connection pooler (`DATABASE_URL`) for high-concurrency runtime queries, while Prisma schema migrations require a direct, unpooled connection (`DIRECT_URL`).
* If deploying with `docker-compose.yml`, the `db-migrate` service runs migrations automatically before `api` and `workers` start.

***

## 3. Configure Meta Webhooks for Production

1. Open your app in the [Meta Developer Dashboard](https://developers.facebook.com/).
2. Navigate to **Instagram -> API setup with Instagram Business login -> Configure Webhook**.
3. Set **Callback URL** to:
   ```text theme={null}
   https://api.yourdomain.com/api/webhook/instagram
   ```
   *(Always include the `/api/` prefix, because NestJS mounts all routes under `/api`.)*
4. Set **Verify Token** to match your `META_WEBHOOK_VERIFY_TOKEN`.
5. Click **Verify and Save**, then subscribe to `messages`, `messaging_postbacks`, `comments`, `message_reactions`, and `live_comments`.

***

## 4. Health Checks and Cron Jobs

* **API Health Check**: `GET https://api.yourdomain.com/api/health` returns `200 OK` when the API, PostgreSQL, and Redis are healthy.
* **Background Workers (`apps/workers`)**: Must run continuously alongside `apps/api` to process outbound DMs, comment replies, profile enrichment, and scheduled posts.
* **Scheduled Cron Maintenance**: Configure your cron runner (or Railway/GitHub Actions) to call the `/api/cron/*` maintenance endpoints with `Authorization: Bearer <CRON_SECRET>` so hourly rate-limit counters reset and paused accounts auto-resume on schedule.

***

## 5. Moving to Live Mode

In Development Mode, Instagram automations only fire for accounts listed as Instagram Testers. To enable automations for all public followers worldwide, complete [Meta App Review](/docs/meta-app-review.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.