# Dual Stack Architecture Flow Diagram

This server runs two completely separate application stacks, using Apache2 as the primary front-facing proxy (The "Main Door").

## Stack 1: Native Local Stack (spysms.edistry.com)
Runs natively on the host machine from `/var/www/html`.

```text
User Request (spysms.edistry.com)
      │
      ▼
[ Host Machine: Apache2 (Ports 443 / 3000) ] 
      │
      ├─ If PHP / Static File ────────> [ Served from /var/www/html ]
      ├─ If API Request (:3000) ──────> [ Proxy to Local PM2 (127.0.0.1:3001) ]
      └─ If WebSockets (/ws) ─────────> [ Proxy to Local PM2 (ws://127.0.0.1:5000) ]
```

## Stack 2: Dockerized Stack (app.edistry.com)
Runs fully containerized from `/var/www/html` with Caddy handling internal routing.

```text
User Request (app.edistry.com)
      │
      ▼
[ Host Machine: Apache2 (Ports 443 / 3000) ] 
      │
      └─ Forwards 100% of traffic to ─> [ Docker: Caddy Container (https://127.0.0.1:8443) ]
                                              │
      ┌───────────────────────────────────────┘ (Caddyfile internal routing)
      │
      ├─ If PHP Request (*.php) ────────> [ Docker: PHP-FPM (app:9000) ]
      ├─ If Legacy API (/api/quiz) ─────> [ Docker: Node Legacy (node-api:3000) ]
      ├─ If New API (/api*) ────────────> [ Docker: Node Express (node-api:4000) ]
      ├─ If WebSockets (/ws) ───────────> [ Docker: Node WS (node-websocket:5000) ]
      └─ If Static File (/assets) ──────> [ Served directly by Caddy ]
```

---

# 🤖 Live Server Deployment Prompt
*Copy and paste the prompt below to your AI assistant when you are ready to configure your LIVE Server.*

**Prompt to copy:**
```text
I have a Dual-Stack web architecture running on this Live server, with Apache2 acting as the main front-facing proxy. I need you to configure my Apache files in `/etc/apache2/sites-available` to support this setup perfectly.

**Stack 1 (Local Native Stack):** 
The domain `app.stoxbaba.com` runs locally from `/var/www/html`. It uses PM2 and native PHP.
Please configure the Apache VirtualHost for `app.stoxbaba.com` to:
1. Serve PHP and static files from `DocumentRoot /var/www/html`.
2. Proxy API requests on port 3000 directly to my local PM2 service at `http://127.0.0.1:3001/`.
3. Proxy WebSocket connections (`/ws/` and `/socket.io/`) on both port 443 and 3000 to `ws://localhost:5000/`.

**Stack 2 (Dockerized Stack):**
The domain `spysms.edistry.com` runs in Docker from `/var/www/html`. It uses Caddy inside Docker as its master router.
Please configure the Apache VirtualHost for `spysms.edistry.com` to:
1. Act as a completely "blind" proxy. It should do no intelligent routing.
2. Proxy 100% of all traffic on port 443 AND port 3000 to `https://127.0.0.1:8443/` (which is where Caddy is listening on the host).
3. Remove any old RewriteRules for WebSockets or APIs for this domain, as Caddy will handle all of that internally.

Ensure the filenames in `sites-available` match their respective domains (e.g., `app_stoxbaba_com.conf` and `spysms_edistry_com.conf`), and make sure SSL configurations using Let's Encrypt are intact for both.
```
