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

# Environment Variables

> Complete reference for all environment variables used by Stocks Signalist.

Create a `.env` file in the root directory. Use `.env.example` as a starting point.

## Required Variables

```bash theme={null}
# Application
NODE_ENV="development"
NEXT_PUBLIC_BASE_URL=http://localhost:3000
PORT=3000

# Database
MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net/SignalisticsDB?retryWrites=true&w=majority"

# Authentication
BETTER_AUTH_SECRET="generate_with_openssl_rand_base64_32"
BETTER_AUTH_URL=http://localhost:3000

# Email (Gmail SMTP)
NODEMAILER_EMAIL="your_email@gmail.com"
NODEMAILER_PASSWORD="your_gmail_app_password"

# Stock Market API
NEXT_PUBLIC_FINNHUB_API_KEY="your_finnhub_api_key"
```

## Optional Variables

```bash theme={null}
# AI Features
GEMINI_API_KEY="your_gemini_api_key"

# Event Processing
INNGEST_EVENT_KEY="your_inngest_key"
```

## Getting API Keys

<AccordionGroup>
  <Accordion title="Finnhub API">
    1. Sign up at [finnhub.io](https://finnhub.io/)
    2. Get your free API key from the dashboard
    3. Set it as `NEXT_PUBLIC_FINNHUB_API_KEY`
  </Accordion>

  <Accordion title="Gmail App Password">
    1. Enable 2-Factor Authentication on your Gmail account
    2. Go to [Google App Passwords](https://myaccount.google.com/apppasswords)
    3. Generate a new app password for "Mail"
    4. Use this password as `NODEMAILER_PASSWORD`
  </Accordion>

  <Accordion title="Better Auth Secret">
    Generate a secure secret:

    ```bash theme={null}
    openssl rand -base64 32
    ```

    Set the output as `BETTER_AUTH_SECRET`.
  </Accordion>
</AccordionGroup>

## Environment-Specific Behavior

<Tabs>
  <Tab title="Development">
    When `NODE_ENV=development`:

    * Email verification is **disabled** (auto sign-in after signup)
    * Verification and reset URLs are **logged to console**
    * Uses `NEXT_PUBLIC_BASE_URL` as the base URL
  </Tab>

  <Tab title="Production">
    When `NODE_ENV=production`:

    * Email verification is **required**
    * Emails are **sent via Nodemailer** (Gmail SMTP)
    * Uses `BETTER_AUTH_URL` as the base URL

    <Warning>
      Set `BETTER_AUTH_URL` to your actual production domain (e.g., `https://stocks-signalist.vercel.app`). Incorrect values will cause broken email links.
    </Warning>
  </Tab>
</Tabs>

## MongoDB URI

<Warning>
  The `MONGODB_URI` **must** include the database name in the connection string. Without it, data defaults to the `test` database.
</Warning>

```bash theme={null}
# Correct
mongodb+srv://user:pass@cluster.mongodb.net/SignalisticsDB?retryWrites=true&w=majority

# Wrong (defaults to 'test' database)
mongodb+srv://user:pass@cluster.mongodb.net/?retryWrites=true&w=majority
```
