# System overview

Drape is **four product surfaces plus this docs site**, running **two backend
generations**. One Expo mobile app and three Next.js web apps talk to FastAPI
backends that are [mid-migration from MongoDB to Postgres](./backend-evolution.md).
Read that page first — it is the context for everything below.

## Containers

```mermaid
graph TB
    subgraph "Client surfaces"
        App["Mobile app<br/>Expo — Drape-/frontend"]
        Mkt["Marketing<br/>Next.js — www.drape.to"]
        Brand["Brand portal<br/>Next.js — brand.drape.to"]
        Admin["Admin<br/>Next.js — admin.drape.to"]
    end

    subgraph "Backend (two generations)"
        Mono["MongoDB monolith<br/>server.py on Render"]
        PG["backend-postgres<br/>ECS Fargate - api.drape.to"]
    end

    subgraph "Data & infra"
        Mongo[("MongoDB")]
        PGDB[("PostgreSQL")]
        Redis[("Upstash Redis")]
        Supa[("Supabase Storage")]
    end

    subgraph "External"
        Fashn["Fashn.ai"]
        Fal["fal.ai — rembg · SAM · FLUX.2"]
        Stripe["Stripe Connect"]
        Mux["Mux — live"]
    end

    App --> Mono
    Mkt --> PG
    Brand --> PG
    Admin --> PG
    Mono --> Mongo
    Mono --> Redis
    Mono --> Supa
    Mono --> Fashn
    Mono --> Fal
    Mono --> Stripe
    PG --> PGDB
    PG --> Supa
    PG --> Stripe
    PG --> Mux
```

The try-on AI pipeline (rembg, garment masking, Fashn/FLUX.2) lives on the
**MongoDB** backend, which is what the shipped mobile app uses. The **Postgres**
backend serves the web tier and carries the newer marketplace capabilities.

## Surfaces and where they deploy

| Surface | Repo | Backend | Hosting |
|---|---|---|---|
| Mobile app | `Drape-/frontend` | MongoDB monolith (Render) | EAS → TestFlight / Play |
| Marketing | `Drape-Marketing` | Postgres (public reads) | AWS Amplify → www.drape.to |
| Brand portal | `Drape-brand` | Postgres | AWS Amplify → brand.drape.to + `{slug}.drape.to` |
| Admin | `Drape-admin-v1` | Postgres | AWS Amplify → admin.drape.to |
| Docs | `Drape-Docs` | — | AWS Amplify → **docs.drape.to** |

The brand portal is **multi-tenant by subdomain**: `brand.drape.to` is the
reserved apply/login host, and each approved store gets `{slug}.drape.to` (e.g.
`prk.drape.to`) with its own theming — see
[Web surfaces](./web-surfaces.md).

## Request lifecycle (mobile → Mongo backend)

Every authenticated request carries a JWT and resolves the user from the database
on each call (no session cache — deletions and flag changes take effect
immediately). The web apps follow the same shape against Postgres, holding the JWT
in `localStorage` with a client-side expiry pre-check.

```mermaid
sequenceDiagram
    autonumber
    participant App
    participant API as FastAPI
    participant Dep as get_current_user
    participant DB
    participant Handler

    App->>API: HTTPS + Bearer JWT
    API->>Dep: resolve identity
    Dep->>DB: look up user by sub claim
    DB-->>Dep: user record
    Dep-->>API: user (or 401 / 403)
    API->>Handler: dispatch
    Handler-->>App: JSON response
```

## Deployment topology

| Component | Where | Notes |
|---|---|---|
| MongoDB backend | Render (`uvicorn server:app`) | Mobile app only; non-AWS |
| Postgres backend | ECS Fargate on cluster **`drape`** | `api.drape.to` → service `drape-prod`; `dev-api.drape.to` → `drape-dev`. Code: `backend-postgres/`. `develop` auto-deploys dev; prod is `workflow_dispatch`. |
| Worker + cron agents | Render | Try-on queue, hourly testers, Mongo backup |
| MongoDB | Atlas | Generation-1 datastore |
| PostgreSQL | **RDS** in account `230790682930` | Prod instance `drape-postgres-prod-live` (docs-supported). See [AWS system map](./aws-system-map.md). |
| Redis | Upstash (REST) | Rate limits, try-on jobs |
| Storage | Supabase | Private body-photo buckets (shared). **No S3** in this AWS account. |
| DNS | Route 53 zone `drape.to` / `Z00780563EFBECXPWSBK4` | Not external-only |
| Web apps + docs | AWS Amplify (us-east-1) | Org git `drape-ai-llc/*`; docs custom domain is live |
| Mobile builds | EAS | development / preview / production |

:::warning[Superseded]
The Postgres API is **not** on Render. Render remains the Mongo mobile path.
:::

For the verified AWS footprint (Amplify app IDs, Route 53, ECS, RDS), see
[Infrastructure](./infrastructure.md) and the
[AWS system map](./aws-system-map.md).

## Where to go next

- [Backend evolution](./backend-evolution.md) — the two-generation migration.
- [Backend (MongoDB)](./backend.md) — the generation the mobile app runs on.
- [Web surfaces](./web-surfaces.md) — the three Next.js apps and the subdomain model.
- [Infrastructure](./infrastructure.md) — current hosting topology.
- [AWS system map](./aws-system-map.md) — live inventory + Stage 2A RDS classifications.
- [Mobile app](./frontend.md) — the Expo client.
- [Try-on pipeline](./try-on-pipeline.md) — the render path.
- [Data model](./data-model.md) · [Design system](./design-system.md) · [Security](./security.md)
