# MAYA OS ENTERPRISE — DEPLOYMENT ARCHITECTURE & RUNBOOK

## 1. Service Topology

| Service | Runtime | Port / Queue | Purpose |
| :--- | :--- | :--- | :--- |
| `nginx` | Nginx 1.27 Alpine | `80` / `443` | TLS termination, `/static/`, SPA frontend, `/api/` & `/ws/` proxy |
| `frontend` | Nginx + Vite dist | `80` (internal) | Compiled React + TypeScript bundle (`frontend/Dockerfile`) |
| `backend` | Uvicorn ASGI (`config.asgi:application`) | `8000` | HTTP API workers (`--workers 4 --proxy-headers`) |
| `asgi` | Daphne (`config.asgi:application`) | `8001` | Django Channels WebSocket live notifications & chat |
| `celery_critical` | Celery worker | `critical_finance,default` | Accounting vouchers, clearing, high-priority jobs |
| `celery_reports` | Celery worker | `reports_exports,backup_recovery` | WeasyPrint PDF, Excel exports, MySQL backup snapshots |
| `celery_notifications` | Celery worker | `chat_notifications,maintenance_scheduled` | Chat push alerts & scheduled tasks |
| `celery_beat` | Celery Beat | Scheduler | Periodic backups, NRB FX sync, loan/cheque SLAs |
| `mysql` | MySQL 8.4 LTS | `3306` | Authoritative ACID transactional database (`InnoDB`) |
| `redis` | Redis 7 Alpine | `6379` | Cache, Channels pub/sub, Celery broker/results |

## 2. Docker Deployment

```bash
./deploy.sh --mode docker
```

Verify health:
```bash
./health-check.sh
```

## 3. Bare-Metal Linux Deployment (Systemd + Nginx TLS)

1. Provision OS directories `/srv/maya-os/{backend,frontend,backups}` owned by `mayaos:mayaos`.
2. Copy systemd unit templates from `deployment/systemd/maya-os-*.service` to `/etc/systemd/system/`.
3. Copy `deployment/nginx/maya-os.tls.conf` to `/etc/nginx/sites-available/maya-os.conf`, replace `__APP_DOMAIN__`, configure TLS via Let's Encrypt (`certbot`), and enable the site.
4. Enable and start services:
   ```bash
   sudo systemctl daemon-reload
   sudo systemctl enable --now maya-os-asgi maya-os-celery-critical maya-os-celery-reports maya-os-celery-chat maya-os-celery-beat
   ```
5. Future code deployments:
   ```bash
   ./deploy.sh --mode bare-metal
   ```

