> ## Documentation Index
> Fetch the complete documentation index at: https://acm-aa28ebf6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend Deployment

> Deploy the SuperBox backend API and Cloudflare Worker

## Overview

SuperBox deployment has two independent steps:

1. **Cloudflare Worker** - deployed with `wrangler deploy` (edge, globally distributed)
2. **Go API** - deployed as a Docker container (self-hosted or any container platform)

## Deploy the Cloudflare Worker

<Steps>
  <Step title="Install dependencies">
    ```bash theme={null}
    cd cloudflare
    npm install
    ```
  </Step>

  <Step title="Authenticate">
    ```bash theme={null}
    wrangler login
    ```
  </Step>

  <Step title="Deploy">
    ```bash theme={null}
    npx wrangler deploy
    ```

    Expected output:

    ```
    Deployed superbox-executor (X.XX sec)
    https://superbox-executor.<your-subdomain>.workers.dev
    ```
  </Step>
</Steps>

<Tip>
  The Worker is deployed globally - no region selection needed. Durable Objects
  are created on-demand at the edge.
</Tip>

## Deploy the Go API

### Docker build

```dockerfile theme={null}
# Multi-stage build (already in backend/Dockerfile)
FROM golang:1.26-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o server ./cmd/server

FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /app/server .
COPY src/ ./src/
RUN pip install -e ".[server]"
CMD ["./server"]
```

Build and run:

```bash theme={null}
cd backend
docker build -t superbox-api .
docker run -d \
  -p 8000:8000 \
  --env-file .env \
  superbox-api
```

### Environment variables

```env theme={null}
CLOUDFLARE_ACCOUNT_ID=...
CLOUDFLARE_R2_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
CLOUDFLARE_R2_ACCESS_KEY_ID=...
CLOUDFLARE_R2_SECRET_ACCESS_KEY=...
CLOUDFLARE_R2_BUCKET_NAME=superbox-mcp-registry
CLOUDFLARE_WORKER_URL=https://superbox-executor.<your-subdomain>.workers.dev
FIREBASE_PROJECT_ID=...
FIREBASE_PRIVATE_KEY=...
FIREBASE_CLIENT_EMAIL=...
SONAR_TOKEN=...
SONAR_ORGANIZATION=...
GITGUARDIAN_API_KEY=...
SNYK_API_TOKEN=...
RAZORPAY_KEY_ID=...
RAZORPAY_KEY_SECRET=...
```

## CI/CD (GitHub Actions)

Example workflow:

```yaml theme={null}
name: Deploy

on:
  push:
 branches: [main]

jobs:
  deploy-worker:
 runs-on: ubuntu-latest
 steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
  with:
 node-version: 20
- run: npm ci
  working-directory: cloudflare
- run: npx wrangler deploy
  working-directory: cloudflare
  env:
 CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

  deploy-api:
 runs-on: ubuntu-latest
 steps:
- uses: actions/checkout@v4
- name: Build and push Docker image
  run: |
 docker build -t superbox-api ./backend
 # push to your container registry
```

## Verify deployment

```bash theme={null}
# Worker health check
curl https://superbox-executor.<your-subdomain>.workers.dev/health

# API health check
curl https://your-api-domain/health

# List servers
curl https://your-api-domain/api/v1/servers
```

## Rollback

```bash theme={null}
# List Worker deployments
wrangler deployments list superbox-executor

# Rollback to a previous deployment
wrangler deployments rollback superbox-executor --deployment-id <id>
```

For the Go API, re-run `docker run` with the previous image tag.
