# MAYA OS ENTERPRISE — FRESH PRODUCTION INSTALLATION GUIDE

## 1. Prerequisites

- Linux server (Ubuntu 22.04/24.04 LTS or Debian 12+)
- **Containerized Mode (Recommended)**: Docker Engine + Docker Compose v2, `openssl`, `curl`
- **Bare-Metal Linux Mode**: Python 3.13+, Node.js 20 LTS + npm, MySQL 8.4 Server (`mysql`, `mysqldump`), Redis 7+, Nginx, WeasyPrint Pango/Cairo libraries

> Maya OS runs strictly on MySQL (`DB_ENGINE=mysql`). SQLite and PostgreSQL are unsupported in production.

## 2. Quick Install (Docker Compose — Zero Demo Data)

1. Unpack the release archive to `/srv/maya-os`:
   ```bash
   sudo mkdir -p /srv/maya-os && sudo unzip maya-os-enterprise-production.zip -d /srv/maya-os
   cd /srv/maya-os
   ```
2. Run the interactive fresh installer:
   ```bash
   ./install.sh --mode docker --domain erp.yourcompany.com.np
   ```
   What `./install.sh` does:
   - Generates a hardened `.env` from `.env.example` with cryptographic `DJANGO_SECRET_KEY`, `MAYA_FIELD_ENCRYPTION_KEY` (Fernet), `BOOTSTRAP_SETUP_TOKEN`, and MySQL passwords (`chmod 600`).
   - Boots `mysql:8.4` (`deployment/mysql/my.cnf`), `redis:7-alpine`, `backend` (Uvicorn ASGI + auto `manage.py migrate`), `asgi` (Daphne WebSocket worker), `celery_critical`, `celery_reports`, `celery_notifications`, `celery_beat`, `frontend` (production Nginx static dist), and TLS-ready `nginx`.
   - Prints your one-time `BOOTSTRAP_SETUP_TOKEN`.

## 3. First-Run Setup Wizard (`/`)

When opened on a fresh MySQL database (`GET /api/v1/bootstrap/status/` returns `bootstrap_allowed: true`), Maya OS automatically launches **FirstRunWizardPage**:

1. **System Preflight**: Verifies MySQL InnoDB engine, `utf8mb4` charset, strict SQL mode, storage writability, and zero pending migrations.
2. **Super Admin Bootstrap**: Requires `BOOTSTRAP_SETUP_TOKEN`. Default usernames (`admin`, `root`, `demo`, `test`) are rejected. Immediately locks unauthenticated bootstrap upon creation.
3. **Mandatory TOTP MFA**: Generates Base32 authenticator secret, `otpauth://` URI, and one-time recovery codes, confirmed via 6-digit TOTP verification.
4. **Dual Calendar Studio**: Sets global BS + AD behavior, Nepali/English numerals, and `Asia/Kathmandu`.
5. **Legal Entity & Nepal Fiscal Year**: Creates your first company, Head Office branch, Nepal Fiscal Year (`2083/84`), IRD tax codes (`VAT 13%`, `TDS`), and clean zero-balance NFRS Chart of Accounts.
6. **Backup Schedule & Installer Lock**: Configures nightly backup retention and permanently locks the installation wizard (`status = LOCKED`).

## 4. Headless CLI Super Admin Alternative

```bash
./create-superadmin.sh \
  --username erp_director \
  --email director@company.com.np \
  --full-name "Managing Director" \
  --password "<Strong-12+-Char-Password>"
```

