# WebSocket Without Port - How It Works

## Your Question
You asked: "How does `devapp.syntheon.in` work without a port number? Can the same be done for FastAPI and WebSocket?"

## Answer: YES! It's Already Configured! ✅

The configuration I created **already does this** - you can access your FastAPI service and WebSocket **without specifying a port**!

## How devapp.syntheon.in Works (Laravel/PHP)

### Laravel/PHP Setup:
```
devapp.syntheon.in (port 80/443)
    ↓
Apache receives request
    ↓
DocumentRoot: /var/www/html/voicebot-web/
    ↓
PHP-FPM processes PHP files via Unix socket
    ↓
Response sent back
```

**Key Point**: PHP runs through **PHP-FPM** (FastCGI Process Manager) which Apache communicates with via a **Unix socket** (`/usr/local/php83/var/run/php-fpm.sock`), not a TCP port. That's why no port is needed in the URL.

## How catalyst.syntheon.in Will Work (FastAPI/Python)

### FastAPI/Python Setup:
```
catalyst.syntheon.in (port 80/443)
    ↓
Apache receives request
    ↓
Reverse Proxy (ProxyPass)
    ↓
Forwards to: http://127.0.0.1:7900/
    ↓
FastAPI/Uvicorn processes request
    ↓
Response sent back through proxy
```

**Key Point**: FastAPI runs as a **standalone server** on port 7900, but Apache **proxies** all requests to it. Users never see the port number!

## Comparison

| Aspect | Laravel (devapp) | FastAPI (catalyst) |
|--------|------------------|-------------------|
| **Access URL** | `http://devapp.syntheon.in` | `http://catalyst.syntheon.in` |
| **Port in URL?** | ❌ No | ❌ No (proxied) |
| **Backend Port** | N/A (Unix socket) | 7900 (internal only) |
| **How It Works** | PHP-FPM via socket | Reverse proxy to port 7900 |
| **WebSocket Support** | Limited (PHP) | ✅ Full support |

## WebSocket Without Port - How It Works

### Before (With Port):
```
❌ ws://catalyst.syntheon.in:7900/ws/session123
   - Port must be specified
   - May be blocked by firewalls
   - Not standard for production
```

### After (Without Port - What We Configured):
```
✅ ws://catalyst.syntheon.in/ws/session123
   - No port needed!
   - Works on standard ports (80/443)
   - Standard WebSocket URL
   - Works through proxy
```

## How the Proxy Works

### HTTP Requests:
```apache
# User accesses: http://catalyst.syntheon.in/
# Apache proxies to: http://127.0.0.1:7900/
ProxyPass / http://127.0.0.1:7900/
ProxyPassReverse / http://127.0.0.1:7900/
```

### WebSocket Requests:
```apache
# User accesses: ws://catalyst.syntheon.in/ws/session123
# Apache detects WebSocket upgrade header
# Proxies to: ws://127.0.0.1:7900/ws/session123

RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/ws/(.*)$ ws://127.0.0.1:7900/ws/$1 [P,L]

# Also direct proxy pass
ProxyPass /ws/ ws://127.0.0.1:7900/ws/
ProxyPassReverse /ws/ ws://127.0.0.1:7900/ws/
```

## Real-World Example

### Current Setup (Before):
```javascript
// ❌ Must specify port
const ws = new WebSocket('ws://catalyst.syntheon.in:7900/ws/session123');
```

### After Configuration:
```javascript
// ✅ No port needed!
const ws = new WebSocket('ws://catalyst.syntheon.in/ws/session123');
// or with SSL:
const ws = new WebSocket('wss://catalyst.syntheon.in/ws/session123');
```

## Port Visibility

| What | Port Visible? | Why |
|------|---------------|-----|
| **User URL** | ❌ No | Apache handles it |
| **Internal** | ✅ Yes (7900) | FastAPI runs on 7900 |
| **WebSocket URL** | ❌ No | Proxied through Apache |

## The Magic: Reverse Proxy

Apache acts as a **reverse proxy**:
- **Frontend**: Users connect to `catalyst.syntheon.in` (port 80/443)
- **Backend**: Apache forwards to `127.0.0.1:7900` (internal)
- **Users never see port 7900** - it's completely hidden!

## Benefits

1. ✅ **No Port in URL**: Clean, professional URLs
2. ✅ **Standard Ports**: Uses 80 (HTTP) and 443 (HTTPS)
3. ✅ **Firewall Friendly**: Standard ports are usually open
4. ✅ **SSL Support**: Easy to add HTTPS/WSS
5. ✅ **Load Balancing**: Can add multiple backend servers later
6. ✅ **Security**: Backend port (7900) not exposed to internet

## Configuration Summary

The configuration I created does exactly this:

```apache
# HTTP requests → FastAPI
ProxyPass / http://127.0.0.1:7900/

# WebSocket requests → FastAPI WebSocket
ProxyPass /ws/ ws://127.0.0.1:7900/ws/
```

**Result**: 
- `http://catalyst.syntheon.in/` → Works (no port!)
- `ws://catalyst.syntheon.in/ws/session123` → Works (no port!)

## Testing

After setup, test it:

```bash
# Test HTTP (no port)
curl http://catalyst.syntheon.in/
# Should return: {"message": "Mcube Call Service Server is running!"}

# Test WebSocket (no port)
wscat -c ws://catalyst.syntheon.in/ws/testsession_123
```

## Conclusion

**YES, it works exactly like `devapp.syntheon.in`!**

- ✅ No port in the URL
- ✅ Direct domain access
- ✅ WebSocket works without port
- ✅ Standard HTTP/HTTPS ports (80/443)
- ✅ Backend port (7900) is internal only

The only difference is:
- **Laravel**: Uses PHP-FPM (Unix socket)
- **FastAPI**: Uses reverse proxy (TCP port 7900 internally)

But from the user's perspective, **both work the same way** - no port needed! 🎉

