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

# SPN - Deployment

> Deploy SPN to production

# Deployment

SPN uses Docker Compose with Caddy for production deployment.

## Architecture

```
┌────────────────────────────────────────┐
│              Caddy (Reverse Proxy)     │
│         Routes /api/* → Backend         │
│         Routes /*  → Frontend           │
└───────────────┬────────────────────────┘
                │
       ┌────────┴────────┐
       ▼                 ▼
┌─────────────┐   ┌─────────────┐
│   Backend   │   │  Frontend   │
│  (FastAPI)  │   │  (Static)   │
└─────────────┘   └─────────────┘
       │
       ▼
┌─────────────┐
│ PostgreSQL  │
└─────────────┘
```

## Prerequisites

* Docker & Docker Compose
* Domain name (for SSL)
* Server with 2GB+ RAM

## Quick Deploy

```bash theme={null}
cd ~/spn
git pull
bash deploy.sh
```

## Manual Deployment

### 1. Build and Start

```bash theme={null}
docker-compose up -d --build
```

### 2. Run Migrations

```bash theme={null}
docker-compose exec api alembic upgrade head
```

### 3. Verify

```bash theme={null}
curl https://your-domain.com/api/v1/system/health
```

## Environment Variables

Configure in `.env`:

```env theme={null}
# Production values
POSTGRES_SERVER=db
POSTGRES_PASSWORD=secure-password
SESSION_SECRET=production-secret

# Production URLs
FRONTEND_URL=https://your-domain.com
CORS_ORIGINS=https://your-domain.com
```

## Services

| Service    | Port | Description     |
| ---------- | ---- | --------------- |
| API        | 8000 | FastAPI backend |
| PostgreSQL | 5432 | Database        |

## SSL

Caddy automatically provisions Let's Encrypt SSL.

## Troubleshooting

### View logs

```bash theme={null}
docker-compose logs -f api
docker-compose logs -f frontend
```

### Restart services

```bash theme={null}
docker-compose restart api
```

### Database issues

```bash theme={null}
docker-compose exec db psql -U postgres -d spn_db
```
