This app is designed as two deployable services:
- Web/API: Next.js on Vercel.
- Worker: a persistent Railway service running
npm run worker.
Postgres and Redis should be provisioned on Railway or another managed provider and shared by both services.
Copy .env.example and set every value in Vercel and Railway:
DATABASE_URLREDIS_URLNEXTAUTH_URLNEXTAUTH_SECRETCRON_SECRETENCRYPTION_KEYRESEND_API_KEYEMAIL_FROMSTRIPE_SECRET_KEYSTRIPE_WEBHOOK_SECRETSTRIPE_PRICE_PROSTRIPE_PRICE_AGENCYMETA_GRAPH_API_VERSIONINSTAGRAM_APP_IDINSTAGRAM_APP_SECRETFACEBOOK_APP_SECRETWEBHOOK_VERIFY_TOKEN
ENCRYPTION_KEY must be 64 hex characters. Generate one with:
openssl rand -hex 32Run migrations before starting production traffic:
npm ci
npm run db:generate
npm run db:migrate- Create a Vercel project from this repository.
- Add all environment variables.
- Set the production domain as
NEXTAUTH_URL. - Deploy.
- Vercel Cron will call
/api/cron/refresh-tokensdaily usingvercel.json.
Create a second Railway service from the same repository.
Start command:
npm run workerUse the same DATABASE_URL, REDIS_URL, Meta, Stripe, and encryption environment variables as the Vercel app.
- Create monthly subscription prices for Pro and Agency.
- Put the price IDs into
STRIPE_PRICE_PROandSTRIPE_PRICE_AGENCY. - Add a webhook endpoint pointing to:
https://your-domain.com/api/stripe/webhook
Subscribe to:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deleted
Configure the webhook callback URL:
https://your-domain.com/api/webhook
Use WEBHOOK_VERIFY_TOKEN as the verify token. Public customer launch requires Meta App Review for Instagram messaging/comment permissions.