Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
}
},
"python.terminal.activateEnvironment": false,
"python.terminal.activateEnvInCurrentTerminal": false
"python.terminal.activateEnvInCurrentTerminal": false,
"workbench.editorAssociations": {
"*.copilotmd": "vscode.markdown.preview.editor",
"*.docx": "default",
"file:/**/*.csv": "jupyter-data-wrangler"
}
}
150 changes: 128 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ A complete machine learning operations (ML Ops) system demonstrating the full li
┌──────────────────────────────────────────┐
GATEWAY SERVICE (:8000)
│ GATEWAY SERVICE (:8080 → :8000)
│ ┌────────────────────────────────────┐ │
│ │ 1. Whitelist Check (15 domains) │ │
│ │ ├─ google.com, github.com │ │
Expand Down Expand Up @@ -87,7 +87,7 @@ A complete machine learning operations (ML Ops) system demonstrating the full li
┌──────────────────────────────────────────┐
│ MODEL SERVICE (:9000) │
│ MODEL SERVICE (:8002) │
│ ┌────────────────────────────────────┐ │
│ │ • Feature Extraction (8 features) │ │
│ │ • XGBoost Inference │ │
Expand Down Expand Up @@ -714,6 +714,74 @@ Final decision: ALLOW
- **LEAN_PHISH:** Likely phishing → Final decision: BLOCK
- **UNCERTAIN:** Unclear → Final decision: REVIEW (manual review queue)


### How to use the optional LLM (Ollama)

#### STEP 1: Verify Ollama is Running
```
# Check if Ollama service is running
ollama list
# Should show: llama3.2:1b

# Test Ollama directly
ollama run llama3.2:1b
# Try: "Is google.com a phishing URL?"
# If it responds, Ollama is working!
# Type /bye to exit

# Check Ollama API endpoint
curl http://localhost:11434/api/tags
# Should return JSON with model list
```
- If Ollama isn't running:

```
# Start Ollama service
ollama serve
# Keep this running in a terminal
```

#### STEP 2: Configure PhishGuardAI to Use Ollama


##### Option A: Environment Variables

```
# .env file

# Enable LLM judge (instead of stub)
JUDGE_BACKEND=llm

# Ollama API endpoint (default is localhost:11434)
OLLAMA_BASE_URL=http://localhost:11434

# Model name (must match your installed model)
OLLAMA_MODEL=llama3.2:1b

# Judge timeout (seconds)
JUDGE_TIMEOUT=10

# Verbose logging (to see judge calls)
LOG_LEVEL=DEBUG
```

##### Option B: Set Environment Variables Directly
- **Windows:**
```
set JUDGE_BACKEND=llm
set OLLAMA_BASE_URL=http://localhost:11434
set OLLAMA_MODEL=llama3.2:1b
set LOG_LEVEL=DEBUG
```

- **Linux/Mac:**
```
export JUDGE_BACKEND=llm
export OLLAMA_BASE_URL=http://localhost:11434
export OLLAMA_MODEL=llama3.2:1b
export LOG_LEVEL=DEBUG
```

### SHAP Explainability Integration

**Purpose:** Provide feature-level explanations for model predictions to support:
Expand Down Expand Up @@ -854,7 +922,7 @@ suite.expect_column_to_exist("CharContinuationRate")

**Multi-Stage Build:**
```dockerfile
# gateway.Dockerfile (BRANCH: feature/docker-slim-gateway)
# gateway.Dockerfile

# ---- build stage: install runtime deps into a venv ----
FROM python:3.11-slim AS builder
Expand Down Expand Up @@ -1067,71 +1135,109 @@ pip install -e ".[dev]"

### Running the Services

**Option 1: Using Docker Compose (Recommended)**
```bash
# Start all services
docker compose up -d

# Check service health
docker ps

# View logs
docker compose logs -f gateway
docker compose logs -f model-svc
```

**Option 2: Running Locally (Development)**

**Terminal 1: Model Service**
```bash
python -m model_svc.main
python -m src.model_svc.main
# Wait for: ✓ Model Service Ready
# Listening on http://localhost:9000
# Listening on http://localhost:8002
```

**Terminal 2: Gateway Service**
```bash
# Windows
set MODEL_SVC_URL=http://localhost:9000
set MODEL_SVC_URL=http://localhost:8002

# Linux/Mac
export MODEL_SVC_URL=http://localhost:9000
export MODEL_SVC_URL=http://localhost:8002

python -m gateway.main
python -m src.gateway.main
# Listening on http://localhost:8000
```

### Testing the System

**When using Docker (recommended):**

**1. Whitelist Test**
```bash
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"url":"https://github.com"}'
curl -X POST http://localhost:8080/predict ^
-H "Content-Type: application/json" ^
-d "{\"url\":\"https://github.com\"}"
# → {"decision":"ALLOW","reason":"domain-whitelist","source":"whitelist"}
```

**2. Phishing Detection**
```bash
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"url":"https://phishing.top"}'
curl -X POST http://localhost:8080/predict ^
-H "Content-Type: application/json" ^
-d "{\"url\":\"https://phishing.top\"}"
# → {"p_malicious":1.0,"decision":"BLOCK","reason":"policy-band"}
```

**3. Short Domain Routing**
```bash
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"url":"https://npm.org"}'
curl -X POST http://localhost:8080/predict ^
-H "Content-Type: application/json" ^
-d "{\"url\":\"https://npm.org\"}"
# → {"decision":"ALLOW","reason":"judge-short-domain-lean-legit"}
```

**4. SHAP Dashboard**
Open browser: `http://localhost:8000/explain`
Open browser: `http://localhost:8080/explain`

**5. Stats Monitoring**
```bash
curl http://localhost:8000/stats
curl http://localhost:8080/stats
# → {"policy_decisions":{...},"final_decisions":{...},"judge_verdicts":{...}}
```

### Docker Deployment

#### Using standalone Docker

```bash
# Build gateway image
docker build -f docker/gateway.Dockerfile -t phishguard-gateway:latest .

# Run container
docker run --rm -p 8000:8000 \
-e MODEL_SVC_URL=http://host.docker.internal:9000 \
# Build model service image
docker build -f docker/model.Dockerfile -t phishguard-model:latest .

# Run model service first
docker run -d --name phishguard-model -p 8002:8002 phishguard-model:latest

# Run gateway service
docker run --rm -p 8080:8000 \
-e MODEL_SVC_URL=http://host.docker.internal:8002 \
-e THRESHOLDS_JSON=configs/dev/thresholds.json \
-e JUDGE_BACKEND=stub \
phishguard-gateway:latest
```

#### Using Docker Compose

```bash
# Build and run all services
docker compose up -d

# Or build and run specific service
docker compose up gateway -d
```

---

## 🗂️ Repository Structure
Expand Down
Loading