# Sites Container Removal - Quick Reference

**Version:** 1.0  
**Date:** November 29, 2025

> **Full Guide:** See [SITES_REMOVAL_GUIDE.md](./SITES_REMOVAL_GUIDE.md) for complete step-by-step instructions

---

## TL;DR - What Changes

### Current Architecture (3 Containers)
```
┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐
│ Frontend        │   │ Sites           │   │ Backend         │
│ Port: 8021      │   │ Port: 8024      │   │ Port: 8011      │
│                 │   │ - Site Builder  │   │                 │
│                 │   │ - Renderer      │   │                 │
└─────────────────┘   └─────────────────┘   └─────────────────┘
```

### Target Architecture (2 Containers)
```
┌─────────────────┐   ┌─────────────────┐
│ Frontend        │   │ Backend         │
│ Port: 8021      │   │ Port: 8011      │
│ - Main App      │   │                 │
│ - Site Builder  │   │                 │
│ - Renderer      │   │                 │
└─────────────────┘   └─────────────────┘
```

---

## What Gets Removed

❌ **Deleted:**
- `/sites/` folder (after copying to frontend)
- `/site-builder/` folder (empty, deprecated)
- `/frontend/src/modules/siteBuilder/` (empty)
- `igny8_sites` Docker container
- Port 8024

✅ **Kept:**
- Backend `/api/v1/site-builder/` endpoints
- Backend `/api/v1/publisher/` endpoints
- Backend modules: `site_builder/`, `publisher/`
- Backend business logic: `site_building/`, `publishing/`
- Database tables (no changes)
- `/data/app/sites-data/` directory

---

## What Gets Moved

### File Movements

| From (Sites Container) | To (Frontend) |
|------------------------|---------------|
| `sites/src/builder/pages/wizard/` | `frontend/src/pages/Sites/Builder/Wizard.tsx` |
| `sites/src/builder/pages/preview/` | `frontend/src/pages/Sites/Builder/Preview.tsx` |
| `sites/src/builder/pages/dashboard/` | `frontend/src/pages/Sites/Builder/Dashboard.tsx` |
| `sites/src/builder/components/layout/` | `frontend/src/components/sites/BuilderLayout.tsx` |
| `sites/src/pages/SiteRenderer.tsx` | `frontend/src/pages/Sites/PublicSiteRenderer.tsx` |
| `sites/src/loaders/loadSiteDefinition.ts` | `frontend/src/services/siteRenderer.api.ts` |
| `sites/src/utils/layoutRenderer.tsx` | `frontend/src/utils/siteRenderer/layoutRenderer.tsx` |
| `sites/src/utils/pageTypeRenderer.tsx` | `frontend/src/utils/siteRenderer/pageTypeRenderer.tsx` |
| `sites/src/utils/templateEngine.tsx` | `frontend/src/utils/siteRenderer/templateEngine.tsx` |

---

## Route Changes

### Site Builder Routes

| Old Route (Port 8024) | New Route (Port 8021) | Auth |
|----------------------|----------------------|------|
| `/builder` | `/sites/builder` | Required ✅ |
| `/builder/preview` | `/sites/builder/preview` | Required ✅ |
| `/builder/dashboard` | `/sites/builder/dashboard` | Required ✅ |

### Sites Renderer Routes

| Old Route (Port 8024) | New Route (Port 8021) | Auth |
|----------------------|----------------------|------|
| `/:siteSlug` | `/sites/view/:siteSlug` | None ❌ |
| `/:siteSlug/:pageSlug` | `/sites/view/:siteSlug/:pageSlug` | None ❌ |

**⚠️ Important:** Public site URLs will change! Update any hardcoded links.

---

## Files to Update

### Critical Files (Must Update)

1. **`/frontend/src/App.tsx`**
   - Add site builder routes
   - Add public renderer routes
   - Add lazy imports

2. **`/docker-compose.app.yml`**
   - Remove `igny8_sites` service
   - Add `/sites-data` volume mount to `igny8_frontend`
   - Add `SITES_DATA_PATH` env var to `igny8_frontend`

3. **`/frontend/vite.config.ts`**
   - Add `SITES_DATA_PATH` environment variable

### Optional Files (Verify/Update)

4. **`/backend/igny8_core/settings.py`**
   - Verify CORS settings (remove port 8024)

5. **`/frontend/src/components/sidebar/AppSidebar.tsx`**
   - Add site builder menu items

---

## Critical Commands

### 1. Backup First
```bash
cd /data/app/igny8
tar -czf backup-sites-$(date +%Y%m%d-%H%M%S).tar.gz sites/ site-builder/
cp docker-compose.app.yml docker-compose.app.yml.backup
```

### 2. Copy Files
```bash
# Create directories
mkdir -p frontend/src/pages/Sites/Builder
mkdir -p frontend/src/components/sites/builder
mkdir -p frontend/src/utils/siteRenderer

# Copy builder pages
cp sites/src/builder/pages/wizard/WizardPage.tsx frontend/src/pages/Sites/Builder/Wizard.tsx
cp sites/src/builder/pages/preview/PreviewCanvas.tsx frontend/src/pages/Sites/Builder/Preview.tsx
cp sites/src/builder/pages/dashboard/SiteDashboard.tsx frontend/src/pages/Sites/Builder/Dashboard.tsx

# Copy renderer
cp sites/src/pages/SiteRenderer.tsx frontend/src/pages/Sites/PublicSiteRenderer.tsx
cp sites/src/loaders/loadSiteDefinition.ts frontend/src/services/siteRenderer.api.ts

# Copy utilities
cp -r sites/src/utils/* frontend/src/utils/siteRenderer/
```

### 3. Rebuild & Restart
```bash
# Rebuild frontend
cd /data/app/igny8/frontend
docker build -t igny8-frontend-dev:latest -f Dockerfile.dev .

# Stop sites container
docker stop igny8_sites
docker rm igny8_sites

# Start updated frontend
cd /data/app/igny8
docker compose -f docker-compose.app.yml up -d igny8_frontend
```

### 4. Test
```bash
# Test site builder (requires auth)
curl -I http://localhost:8021/sites/builder

# Test public renderer
curl -I http://localhost:8021/sites/view/test-site

# Check logs
docker logs -f igny8_frontend
```

### 5. Cleanup (After Verification)
```bash
cd /data/app/igny8
rm -rf sites/
rm -rf site-builder/
rm -rf frontend/src/modules/siteBuilder/
docker rmi igny8-sites-dev:latest
```

---

## Impact on Other Features

### ✅ No Impact (These Still Work)

| Feature | Why No Impact |
|---------|---------------|
| Planner module | Uses only backend API |
| Writer module | Uses only backend API |
| Linker module | Uses only backend API |
| Optimizer module | Uses only backend API |
| WordPress Publishing | Talks to backend, not affected |
| Authentication | Frontend change only |
| Billing/Credits | Backend only |
| AI Content Generation | Backend/Celery only |

### ⚠️ Needs Update (After Migration)

| Feature | What to Update | Impact |
|---------|----------------|--------|
| Site Builder UI | Routes change to `/sites/builder/*` | Low - Internal only |
| Public Site Links | URLs change to `/sites/view/{slug}` | Medium - External links |
| Navigation Menu | Add site builder menu items | Low - UI only |
| Tests | Update route tests if any | Low - Dev only |

---

## Docker Compose Changes

### Before (3 Services)
```yaml
services:
  igny8_frontend:    # Port 8021
  igny8_sites:       # Port 8024 ❌ REMOVE THIS
  igny8_backend:     # Port 8011
  igny8_celery_worker:
  igny8_celery_beat:
```

### After (2 Services)
```yaml
services:
  igny8_frontend:    # Port 8021 (updated)
  # igny8_sites removed
  igny8_backend:     # Port 8011
  igny8_celery_worker:
  igny8_celery_beat:
```

### Frontend Service Update
```yaml
igny8_frontend:
  image: igny8-frontend-dev:latest
  container_name: igny8_frontend
  ports:
    - "0.0.0.0:8021:5173"
  environment:
    VITE_BACKEND_URL: "https://api.igny8.com/api"
    SITES_DATA_PATH: "/sites"  # ← ADD THIS
  volumes:      
    - /data/app/igny8/frontend:/app:rw
    - /data/app/sites-data:/sites:ro  # ← ADD THIS
```

---

## Testing Checklist

**Before Migration:**
- [ ] Site builder wizard works at `http://localhost:8024/builder`
- [ ] Site preview works at `http://localhost:8024/builder/preview`
- [ ] Public site loads at `http://localhost:8024/{siteSlug}`

**After Migration:**
- [ ] Site builder wizard works at `http://localhost:8021/sites/builder`
- [ ] Site preview works at `http://localhost:8021/sites/builder/preview`
- [ ] Blueprint dashboard works at `http://localhost:8021/sites/builder/dashboard`
- [ ] Public site loads at `http://localhost:8021/sites/view/{siteSlug}`
- [ ] Auth required for builder routes
- [ ] No auth required for public renderer
- [ ] API calls succeed from frontend
- [ ] No console errors in browser
- [ ] Sites data loads from `/data/app/sites-data/`

---

## Rollback (If Needed)

```bash
# Quick rollback
cp docker-compose.app.yml.backup docker-compose.app.yml
docker compose -f docker-compose.app.yml up -d igny8_sites

# Full rollback
cd /data/app/igny8
tar -xzf backup-sites-YYYYMMDD-HHMMSS.tar.gz
cd sites
docker build -t igny8-sites-dev:latest -f Dockerfile.dev .
docker compose -f docker-compose.app.yml up -d igny8_sites
```

---

## Estimation

| Task | Time |
|------|------|
| Backup & Prep | 30 min |
| Copy Files & Update Routes | 2 hours |
| Docker Config Updates | 30 min |
| Rebuild & Deploy | 30 min |
| Testing | 1-2 hours |
| Cleanup & Docs | 1 hour |
| **Total** | **5-6 hours** |

---

## Decision Matrix

### Keep Separate Sites Container If:
- ❌ You need different deployment schedules for sites vs main app
- ❌ You want sites on different infrastructure
- ❌ You have high traffic public sites (performance isolation)
- ❌ You want to scale sites independently

### Merge Into Frontend If:
- ✅ You want simpler deployment (fewer containers)
- ✅ You want unified routing and authentication
- ✅ Sites are internal/low traffic
- ✅ You want easier development (single app)
- ✅ You want to reduce port complexity

---

## Support

**Full Documentation:** [SITES_REMOVAL_GUIDE.md](./SITES_REMOVAL_GUIDE.md)  
**Architecture Reference:** [MASTER_REFERENCE.md](./MASTER_REFERENCE.md)  
**API Reference:** [API-COMPLETE-REFERENCE.md](./API-COMPLETE-REFERENCE.md)

---

**Last Updated:** November 29, 2025  
**Status:** Ready for implementation
