# Deployment Checklist

After pulling from Git, configure the following server-specific settings:

## 1. Environment Files (gitignored - safe to modify)

### Root `.env`
```bash
# Database connections
DATABASE_URL=postgresql+psycopg2://user:password@10.0.10.181:5432/punimtag
DATABASE_URL_AUTH=postgresql+psycopg2://user:password@10.0.10.181:5432/punimtag_auth

# JWT Secrets
SECRET_KEY=your-secret-key-here
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin

# Photo storage
PHOTO_STORAGE_DIR=/opt/punimtag/data/uploads
```

### `admin-frontend/.env`
```bash
VITE_API_URL=http://10.0.10.121:8000
```

### `viewer-frontend/.env`
```bash
DATABASE_URL=postgresql://user:password@10.0.10.181:5432/punimtag
DATABASE_URL_AUTH=postgresql://user:password@10.0.10.181:5432/punimtag_auth
NEXTAUTH_URL=http://10.0.10.121:3001
NEXTAUTH_SECRET=your-secret-key-here
AUTH_URL=http://10.0.10.121:3001
```

## 2. PM2 Configuration

Copy the template and customize for your server:

```bash
cp ecosystem.config.js.example ecosystem.config.js
```

Edit `ecosystem.config.js` and update:
- All `cwd` paths to your deployment directory
- All `error_file` and `out_file` paths to your user's home directory
- `PYTHONPATH` and `PATH` environment variables

## 3. System Configuration (One-time setup)

### Firewall Rules
```bash
sudo ufw allow 3000/tcp  # Admin frontend
sudo ufw allow 3001/tcp  # Viewer frontend  
sudo ufw allow 8000/tcp  # Backend API
```

### Database Setup
Create admin user in auth database:
```bash
cd viewer-frontend
npx tsx scripts/fix-admin-user.ts
```

## 4. Build Frontends

```bash
# Admin frontend
cd admin-frontend
npm install
npm run build

# Viewer frontend
cd viewer-frontend
npm install
npm run prisma:generate:all
npm run build
```

## 5. Start Services

```bash
pm2 start ecosystem.config.js
pm2 save
```

## Notes

- `.env` files are gitignored and safe to modify
- `ecosystem.config.js` is gitignored and server-specific
- Database changes (admin user) persist across pulls
- Firewall rules are system-level and persist

