# Required Environment Variables

Create a `.env` file in the project root with these variables:

## Application Variables

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `APP_URL` | Base URL of your application (used for webhook URLs) | `http://127.0.0.1:8000` | No |
| `APP_TIMEZONE` | PHP timezone (e.g., `UTC`, `America/New_York`) | `UTC` | No |

## Database Variables

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `DB_HOST` | MySQL hostname | `127.0.0.1` | No |
| `DB_PORT` | MySQL port | `3306` | No |
| `DB_DATABASE` | Database name | `newsletter` | No |
| `DB_USERNAME` | Database username | `root` | No |
| `DB_PASSWORD` | Database password | (empty) | **Yes** (if password required) |


## Mailchimp Integration

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `MAILCHIMP_API_KEY` | Your Mailchimp API key | (empty) | **Yes** (for production) |
| `MAILCHIMP_DC` | Mailchimp data center (e.g., `us21`, `us6`) | `us21` | **Yes** (if using Mailchimp) |
| `MAILCHIMP_AUDIENCE_ID_DEFAULT` | Default Mailchimp audience/list ID | (empty) | No |

**Note:** If `MAILCHIMP_API_KEY` is empty, the app will use a **mock Mailchimp service** for testing.

---

## Example `.env` File

```env
# Application
APP_URL=http://127.0.0.1:8000
APP_TIMEZONE=UTC

# Database
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=newsletter
DB_USERNAME=root
DB_PASSWORD=your_db_password


# Mailchimp (leave empty to use mock service)
MAILCHIMP_API_KEY=your-mailchimp-api-key-here
MAILCHIMP_DC=us21
MAILCHIMP_AUDIENCE_ID_DEFAULT=your-audience-id-here
```

---

## Where Variables Are Used

### `app/bootstrap.php`
- `APP_TIMEZONE` - Sets PHP timezone
- `DB_*` - Database connection configuration

### `worker.php`
- `MAILCHIMP_API_KEY` - Determines if mock or real Mailchimp service is used
- `MAILCHIMP_AUDIENCE_ID_DEFAULT` - Default audience ID for list mappings

### `app/Services/Mailchimp/MailchimpService.php`
- `MAILCHIMP_API_KEY` - Authentication for Mailchimp API
- `MAILCHIMP_DC` - Data center for API endpoint URL


---

## Finding Your Mailchimp Variables

1. **API Key**: 
   - Go to Mailchimp Dashboard → Account → Extras → API keys
   - Create a new key or copy existing one
   - Format: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us21`

2. **Data Center (DC)**:
   - Extract from your API key (last 4-5 characters after the dash)
   - Example: If key ends with `-us21`, your DC is `us21`

3. **Audience ID**:
   - Go to Mailchimp → Audience → Settings → Audience name and defaults
   - Look for "Audience ID" (usually a long alphanumeric string)

---

## Quick Setup Checklist

- [ ] Create `.env` file in project root
- [ ] Set all database variables
- [ ] Set `ADMIN_AUTH_SECRET` (use a strong random string)
- [ ] Set Mailchimp variables (or leave empty to use mock service)
- [ ] Verify database connection works
- [ ] Run migrations: `SOURCE database/migrations/001_create_tables.sql`

