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

# Configuration

> Server configuration and environment variables

## Overview

Zeus server configuration is managed through environment variables. This allows flexible deployment across different environments.

## Environment Variables

### Required

| Variable       | Description                  | Example                     |
| -------------- | ---------------------------- | --------------------------- |
| `DATABASE_URL` | PostgreSQL connection string | `postgres://localhost/zeus` |

### Optional

| Variable     | Description     | Default          |
| ------------ | --------------- | ---------------- |
| `PORT`       | Server port     | `3000`           |
| `RUST_LOG`   | Log level       | `info`           |
| `JWT_SECRET` | JWT signing key | Random generated |

## Configuration File

Create `.env` in the server directory:

```bash theme={null}
# Database
DATABASE_URL=postgres://localhost/zeus

# Server
PORT=3000

# Logging
RUST_LOG=info

# Security (generate a strong secret)
JWT_SECRET=your-super-secret-key-min-32-chars
```

## Docker Compose

Full configuration in `docker-compose.yml`:

```yaml theme={null}
version: '3.8'

services:
  postgres:
    image: postgres:14
    environment:
      POSTGRES_USER: zeus
      POSTGRES_PASSWORD: zeus_password
      POSTGRES_DB: zeus
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  server:
    build: ./server
    environment:
      DATABASE_URL: postgres://zeus:zeus_password@postgres/zeus
      PORT: 3000
      RUST_LOG: info
    ports:
      - "3000:3000"
    depends_on:
      - postgres

volumes:
  postgres_data:
```

## Environments

### Development

```bash theme={null}
# .env.development
DATABASE_URL=postgres://localhost/zeus_dev
RUST_LOG=debug
PORT=3000
```

### Staging

```bash theme={null}
# .env.staging
DATABASE_URL=postgres://staging-db/zeus
RUST_LOG=info
PORT=3000
```

### Production

```bash theme={null}
# .env.production
DATABASE_URL=postgres://prod-db/zeus
RUST_LOG=warn
PORT=3000
JWT_SECRET=<strong-secret-key>
```

## Logging Levels

| Level   | Use Case                      |
| ------- | ----------------------------- |
| `error` | Errors only                   |
| `warn`  | Warnings and errors           |
| `info`  | General information (default) |
| `debug` | Detailed debugging            |
| `trace` | Very verbose                  |

## Security Considerations

1. **Never commit `.env` files** - Add to `.gitignore`
2. **Use strong JWT secrets** - At least 32 characters
3. **Rotate secrets regularly** - Especially in production
4. **Use TLS** - Always in production
5. **Limit database permissions** - Use dedicated user

## Configuration in Code

Access configuration in Rust:

```rust theme={null}
use std::env;

pub struct Config {
    pub database_url: String,
    pub port: u16,
    pub jwt_secret: String,
}

impl Config {
    pub fn from_env() -> Self {
        Self {
            database_url: env::var("DATABASE_URL")
                .expect("DATABASE_URL must be set"),
            port: env::var("PORT")
                .unwrap_or_else(|_| "3000".to_string())
                .parse()
                .expect("PORT must be a number"),
            jwt_secret: env::var("JWT_SECRET")
                .unwrap_or_else(|_| generate_secret()),
        }
    }
}
```
