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

# Installation

> Complete guide to installing, configuring, and running Instance locally with PostgreSQL, Redis, NextAuth, Cloudflare R2 storage, and background workers.

## Prerequisites

Before starting, verify that your machine has the following tools installed:

| Tool | Minimum Version | Installation Check | Download Link |
| :- | :- | :- | :- |
| **Node.js** | 20.x LTS or higher | `node -v` | [nodejs.org](https://nodejs.org/) |
| **pnpm** | 10.28.2+ | `pnpm -v` | `npm install -g pnpm` |
| **Git** | Any modern version | `git --version` | [git-scm.com](https://git-scm.com/) |
| **PostgreSQL** | PostgreSQL 16+ | Local or Cloud | [Neon (Free Cloud Postgres)](https://neon.tech) |
| **Redis** | Redis 7+ | Local or Cloud | [Upstash (Free Cloud Redis)](https://upstash.com) |

***

## Step 1: Clone the Repository

Open your terminal (PowerShell on Windows, or Terminal on macOS/Linux) and clone the repository:

```bash theme={null}
git clone https://github.com/sumamakhan761/tryinstance.git
cd instance
```

***

## Step 2: Install Monorepo Dependencies

Instance uses pnpm workspaces to coordinate dependencies across apps and shared packages. Run:

```bash theme={null}
pnpm install
```

This installs all packages for the Web dashboard, API server, background workers, AI and email connectors, and shared database packages.

***

## Step 3: Prepare Environment Configuration

Create your local `.env` configuration file from the template:

```bash theme={null}
cp .env.example .env
```

*(On Windows PowerShell, run `Copy-Item .env.example .env`)*

***

## Step 4: Rapid Bootstrapping Setup (2 Minutes to Run)

To get the application running locally and sign into the dashboard immediately, configure these core connections in your `.env` file:

### 1. PostgreSQL Database

* **Cloud Option (Recommended and Fastest)**: Sign up at [neon.tech](https://neon.tech), create a new project named `instance`, and copy the pooled and direct connection strings into your `.env`:
  ```env theme={null}
  DATABASE_URL="postgresql://user:password@ep-pooler.region.neon.tech/neondb?sslmode=require"
  DIRECT_URL="postgresql://user:password@ep-direct.region.neon.tech/neondb?sslmode=require"
  ```
* **Local Option**: If you have PostgreSQL running locally:
  ```env theme={null}
  DATABASE_URL="postgresql://postgres:postgres@localhost:5432/instance?sslmode=disable"
  DIRECT_URL="postgresql://postgres:postgres@localhost:5432/instance?sslmode=disable"
  ```

### 2. Redis Cache and Queue

* **Cloud Option (Fastest)**: Create a free Redis instance on [upstash.com](https://upstash.com) and copy your connection URL:
  ```env theme={null}
  REDIS_URL="rediss://default:token@region.upstash.io:6379"
  ```
* **Local Option**: If you have local Redis running (`redis-server`):
  ```env theme={null}
  REDIS_URL="redis://localhost:6379"
  ```

### 3. Application URLs and NextAuth Secret

Set your local URLs so the web dashboard and API server can communicate:

```env theme={null}
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NEXT_PUBLIC_APP_URL="http://localhost:3000"
NEXT_PUBLIC_API_URL="http://localhost:4000"
API_URL="http://localhost:4000"
```

Instance uses NextAuth to secure user sessions and encrypt JWT tokens. You need a random 32-character secret, which you can generate in either of two ways:

* **Terminal**: Run `openssl rand -hex 32` in your command line.
* **Online Generator**: Visit [generate-secret.vercel.app/32](https://generate-secret.vercel.app/32) to generate a random 32-character hex secret instantly.

Paste the generated string into your `.env`:

```env theme={null}
NEXTAUTH_SECRET="your-generated-32-character-secret"
NEXTAUTH_URL="http://localhost:3000"
```

### 4. Configure Google OAuth Login (Optional)

If you want team members to sign in with Google in addition to email and password:

1. Open [Google Cloud Console](https://console.cloud.google.com).
2. Create a project and navigate to **APIs & Services -> Credentials**.
3. Click **Create Credentials -> OAuth client ID** (Application type: **Web application**).
4. Set Authorized JavaScript origins: `http://localhost:3000`.
5. Set Authorized redirect URIs: `http://localhost:3000/api/auth/callback/google`.
6. Copy the credentials into your `.env`:
   ```env theme={null}
   GOOGLE_CLIENT_ID="your-google-client-id"
   GOOGLE_CLIENT_SECRET="your-google-client-secret"
   ```

***

## Step 5: Initialize the Database Schema

Generate the Prisma Client types and synchronize all tables with your PostgreSQL database:

```bash theme={null}
pnpm db:generate
pnpm db:push
```

***

## Step 6: Start the Development Stack

Launch all services concurrently (Web Dashboard, API Server, and Background Workers):

```bash theme={null}
pnpm dev
```

Or run each service in its own terminal window:

* **Web Dashboard** (port `3000`): `pnpm dev:web`
* **API Server** (port `4000`): `pnpm dev:api`
* **Background Workers**: `pnpm dev:workers`

Open `http://localhost:3000` in your browser to create your workspace and enter the setup wizard.

***

## Step 7: Core Feature Integrations

Add these variables to `.env` when you are ready to connect Instagram, upload media, or send transactional emails:

* **Instagram and Meta Graph API**: Required to connect Instagram accounts and receive webhooks. See [Instagram Setup](/docs/instagram-setup.md) for step-by-step instructions.
  ```env theme={null}
  INSTAGRAM_APP_ID="your-instagram-app-id"
  INSTAGRAM_APP_SECRET="your-instagram-app-secret"
  INSTAGRAM_REDIRECT_URI="http://localhost:3000/api/instagram/callback"
  META_WEBHOOK_VERIFY_TOKEN="instance_verify_token"
  ```
* **Cloudflare R2 Storage**: Required for uploading images, voice notes, PDFs, Bio Link avatars, and scheduled posts.
  ```env theme={null}
  R2_ACCOUNT_ID="your-r2-account-id"
  R2_ACCESS_KEY_ID="your-r2-access-key"
  R2_SECRET_ACCESS_KEY="your-r2-secret-key"
  R2_BUCKET_NAME="instance-media"
  R2_PUBLIC_URL="https://media.yourdomain.com"
  ```
* **Default Groq AI Key (Optional)**: Useful as a fallback if you have not configured AI providers inside **Dashboard -> Settings -> AI Connectors**.
  ```env theme={null}
  GROQ_API_KEY="your-groq-api-key"
  ```
* **Transactional Email (SMTP)**: Used for sending team member invitations and password reset emails.
  ```env theme={null}
  EMAIL_SERVER_HOST="smtp.resend.com"
  EMAIL_SERVER_PORT="587"
  EMAIL_SERVER_USER="resend"
  EMAIL_SERVER_PASSWORD="your-smtp-password"
  EMAIL_FROM="noreply@yourdomain.com"
  ```
* **Cron Protection**: Secures internal scheduled maintenance routes.
  ```env theme={null}
  CRON_SECRET="your-cron-secret"
  ```
* **Meta Instagram Rate Limits and Pacing Controls (Pre-tuned in `.env.example`)**: Built-in token-bucket limits and thread pacing matching official Meta Graph API rules. Leave the defaults as-is unless your Meta app tier increases (see [Safety & Anti-Ban](/docs/safety.md)):
  ```env theme={null}
  META_SEND_RATE_LIMIT_PER_SEC=100
  META_MEDIA_RATE_LIMIT_PER_SEC=10
  META_PRIVATE_REPLY_RATE_LIMIT_PER_HOUR=750
  META_LIVE_COMMENT_RATE_LIMIT_PER_SEC=100
  META_THREAD_PACING_MIN_INTERVAL_SEC=1.0
  META_COMMENT_REPLY_RATE_LIMIT_PER_HOUR=60
  META_CONVERSATION_RATE_LIMIT_PER_SEC=2
  ```

***

## Common Troubleshooting

* **Prisma connection error on `db:push`**: Make sure PostgreSQL is running and `DIRECT_URL` points directly to port `5432` without connection pooler parameters.
* **Background workers not sending DMs**: Verify `REDIS_URL` is reachable and `pnpm dev:workers` is running alongside `pnpm dev:api`.
* **Instagram OAuth redirect mismatch**: Make sure `INSTAGRAM_REDIRECT_URI` in `.env` matches the exact Redirect URI saved in your Meta Developer App settings.


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