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

# 環境變數

> Panguard 各服務環境變數完整參考。

環境變數在服務啟動時生效。可以設在 shell profile、`.env` 檔或容器編排系統裡。

## Panguard Guard

| 變數                   | 預設                       | 說明                                    |
| -------------------- | ------------------------ | ------------------------------------- |
| `PANGUARD_DATA_DIR`  | `~/.panguard-guard`      | Guard 資料、規則、log 的根目錄                  |
| `PANGUARD_MODE`      | `protect`                | 運作模式：`learning`、`detect`、`protect`    |
| `OLLAMA_ENDPOINT`    | `http://localhost:11434` | Ollama API endpoint，本機 AI 分析用         |
| `ANTHROPIC_API_KEY`  | --                       | Anthropic API key，Claude 分析用（第 2/3 層） |
| `OPENAI_API_KEY`     | --                       | OpenAI API key，GPT 分析用（第 2/3 層）       |
| `ABUSEIPDB_KEY`      | --                       | AbuseIPDB API key，IP 聲譽查詢用            |
| `PANGUARD_LOG_LEVEL` | `info`                   | log 等級：`debug`、`info`、`warn`、`error`  |
| `PANGUARD_LANG`      | `en`                     | CLI 輸出跟通知語言：`en`、`zh-TW`、`ja`         |

<CodeGroup>
  ```bash Linux / macOS theme={null}
  export PANGUARD_DATA_DIR=~/.panguard-guard
  export PANGUARD_MODE=protect
  export PANGUARD_LOG_LEVEL=info
  export PANGUARD_LANG=en

  # AI provider（建議至少設一個）
  export OLLAMA_ENDPOINT=http://localhost:11434
  export ANTHROPIC_API_KEY=sk-ant-...
  export OPENAI_API_KEY=sk-...

  # 選配
  export ABUSEIPDB_KEY=your-key-here
  ```

  ```powershell Windows theme={null}
  $env:PANGUARD_DATA_DIR = "$HOME\.panguard-guard"
  $env:PANGUARD_MODE = "protect"
  $env:PANGUARD_LOG_LEVEL = "info"
  $env:PANGUARD_LANG = "en"

  # AI provider
  $env:OLLAMA_ENDPOINT = "http://localhost:11434"
  $env:ANTHROPIC_API_KEY = "sk-ant-..."
  ```
</CodeGroup>

<Info>
  Guard 用三層 AI 系統。最低限度要設 `OLLAMA_ENDPOINT` 給本機分析（第一層）。加上 `ANTHROPIC_API_KEY` 或 `OPENAI_API_KEY` 就能用雲端分析（第 2/3 層）。
</Info>

***

## Panguard Threat Cloud

| 變數                       | 預設                       | 說明                           |
| ------------------------ | ------------------------ | ---------------------------- |
| `TC_API_KEYS`            | --                       | 逗號分隔的合法 API key 清單           |
| `TC_PORT`                | `4000`                   | Threat Cloud API 的 HTTP port |
| `TC_DB_PATH`             | `./data/threat-cloud.db` | SQLite 資料庫路徑                 |
| `ALLOW_ANONYMOUS_UPLOAD` | `false`                  | 允許未認證的威脅提交                   |

<CodeGroup>
  ```bash Linux / macOS theme={null}
  export TC_API_KEYS=key1,key2,key3
  export TC_PORT=4000
  export TC_DB_PATH=/var/lib/panguard/threat-cloud.db
  export ALLOW_ANONYMOUS_UPLOAD=false
  ```
</CodeGroup>

<Info>
  `ALLOW_ANONYMOUS_UPLOAD=true` 讓人不用 API key 就能提交威脅資料。提交的資料還是會經過驗證跟聲譽評分。
</Info>

***

## Docker / Production

| 變數         | 預設            | 說明                           |
| ---------- | ------------- | ---------------------------- |
| `NODE_ENV` | `development` | production 部署設成 `production` |

設 `NODE_ENV=production` 的效果：

* 關掉 debug log 跟錯誤回應裡的 stack trace
* 啟用 response 壓縮
* 啟用更嚴格的安全 header
* 關掉開發用的 route

<CodeGroup>
  ```yaml docker-compose.yml theme={null}
  services:
    threat-cloud:
      image: panguard/threat-cloud
      environment:
        - NODE_ENV=production
        - TC_PORT=4000
        - TC_API_KEYS=${TC_API_KEYS}
        - TC_DB_PATH=/data/threat-cloud.db
      volumes:
        - tc-data:/data
  ```
</CodeGroup>

## 優先順序

環境變數優先於 config 檔。解析順序：

1. 環境變數（最高）
2. Config 檔值（`config.json`）
3. 內建預設值（最低）

<Tip>
  本機開發的話，在服務目錄建一個 `.env` 檔用 `dotenv` 載入就好。`.env` 檔永遠不要 commit 進 version control。
</Tip>
