# Environment Configuration

This document provides a comprehensive reference for all environment variables used in the Building Management System.

## Configuration File Location

The primary configuration file is `.env` located in the project root. Never commit this file to version control.

## Core Application Settings

```env
# Application Identity
APP_NAME=Building
APP_ENV=local                    # Options: local, staging, production
APP_KEY=                         # Auto-generated, do not change
APP_DEBUG=true                   # Set to false in production
APP_TIMEZONE=UTC
APP_URL=http://127.0.0.1:8001

# Server Configuration
SERVER_PORT=8001
```

### Environment Modes

| APP_ENV | APP_DEBUG | Use Case |
|---------|-----------|----------|
| local | true | Local development |
| staging | true | Staging/QA testing |
| production | false | Production deployment |

## Database Configuration

### MySQL (Recommended)

```env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=building
DB_USERNAME=root
DB_PASSWORD=secret
```

### SQLite (Development Only)

```env
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
```

### Connection Pooling (Production)

```env
DB_POOL_MIN=2
DB_POOL_MAX=10
```

## Cache Configuration

```env
CACHE_DRIVER=redis              # Options: file, redis, memcached, database
CACHE_PREFIX=building_cache
```

### Redis Cache

```env
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=phpredis           # Options: phpredis, predis
```

## Session Configuration

```env
SESSION_DRIVER=database         # Options: file, cookie, database, redis
SESSION_LIFETIME=120            # Minutes
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
```

## Queue Configuration

```env
QUEUE_CONNECTION=database       # Options: sync, database, redis, sqs
```

### Redis Queue (Production Recommended)

```env
QUEUE_CONNECTION=redis
REDIS_QUEUE=default
```

## Mail Configuration

### Log Driver (Development)

```env
MAIL_MAILER=log
```

### SMTP Configuration

```env
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@example.com
MAIL_FROM_NAME="${APP_NAME}"
```

## Broadcasting (Real-time)

```env
BROADCAST_DRIVER=pusher

PUSHER_APP_ID=your_app_id
PUSHER_APP_KEY=your_app_key
PUSHER_APP_SECRET=your_app_secret
PUSHER_APP_CLUSTER=ap2
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
```

## File Storage

```env
FILESYSTEM_DISK=local           # Options: local, public, s3
```

### AWS S3 Configuration

```env
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your_bucket
AWS_USE_PATH_STYLE_ENDPOINT=false
```

## Authentication

### Sanctum (API Tokens)

```env
SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1
```

## Frontend URLs

```env
FRONTEND_URL=https://app.example.com
FRONTEND_DRIVER_MAGIC_LOGIN_URL=https://app.example.com/external/supplies/driver
FRONTEND_SUPPLIER_MAGIC_LOGIN_URL=https://app.example.com/external/supplies/supplier
```

## Third-Party Integrations

### ZATCA (Saudi Tax Authority)

```env
ZATCA_ENVIRONMENT=sandbox       # Options: sandbox, production
ZATCA_CERTIFICATE_PATH=
ZATCA_PRIVATE_KEY_PATH=
```

## Logging Configuration

```env
LOG_CHANNEL=stack               # Options: single, daily, slack, stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug                 # Options: debug, info, notice, warning, error
```

### Daily Log Files

```env
LOG_CHANNEL=daily
LOG_DAILY_DAYS=14
```

## Debugging Tools

### Telescope

```env
TELESCOPE_ENABLED=true
```

### Horizon

```env
HORIZON_PREFIX=building_horizon_
```

## Security Settings

```env
# CORS Settings
CORS_ALLOWED_ORIGINS=*

# Rate Limiting
RATE_LIMIT_PER_MINUTE=60
```

## Environment-Specific Files

| File | Purpose |
|------|---------|
| `.env` | Active configuration |
| `.env.example` | Template for new installations |
| `.env.testing` | PHPUnit test configuration |

## Configuration Caching

For production, cache configuration:

```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

Clear cached configuration:

```bash
php artisan config:clear
php artisan route:clear
php artisan view:clear
```

## Validation

Verify configuration:

```bash
php artisan config:show database
php artisan config:show mail
```
