# ramyyyy-00/tryon-widget architecture

> Architecture diagram of the GitHub repository ramyyyy-00/tryon-widget, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ramyyyy-00/tryon-widget
- Repository: https://github.com/ramyyyy-00/tryon-widget

## Overview

This MVP embeds a virtual try-on button in clothing product pages, obtains a short-lived Decart token through its backend, and streams camera video and a garment image into Decart’s realtime model. The widget also handles consent, localized UI, session timing, and cleanup; the server restricts brands and origins, enforces limits, and records monthly usage. The demo is an initiating storefront. Source excerpts show the runtime flow; README documents brand setup and deployment context, while no separate admin, billing, Shopify, or WordPress implementation exists.

Main entry points: [`public/tryon-widget.js`](https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js) (Realtime session and timer), [`server.js`](https://github.com/ramyyyy-00/tryon-widget/blob/main/server.js) (Token API and static hosting), [`demo/index.html`](https://github.com/ramyyyy-00/tryon-widget/blob/main/demo/index.html) (Demo storefront), [`brands.json`](https://github.com/ramyyyy-00/tryon-widget/blob/main/brands.json) (Brand origins and limits)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_widget["Storefront widget"]
  node_widget["Embed and product buttons<br/>[tryon-widget.js]"]
  node_consent["Consent and camera UI<br/>[tryon-widget.js]"]
  node_garment["Garment and prompt setup<br/>[tryon-widget.js]"]
  node_session["Realtime session and timer<br/>[tryon-widget.js]"]
end

subgraph group_backend["Token and usage backend"]
  node_backend["Token API and static hosting<br/>[server.js]"]
  node_brandconfig["Brand origins and limits<br/>[brands.json]"]
  node_usage[("Monthly usage counter<br/>[server.js]")]
end

subgraph group_provider["Try-on provider"]
  node_decart["Decart token and realtime service"]
end

node_shopper(("Store shopper"))
node_demo["Demo storefront<br/>[index.html]"]

node_shopper -->|"opens demo"| node_demo
node_shopper -->|"clicks try-on"| node_widget
node_demo -->|"loads widget"| node_widget
node_widget -->|"opens consent"| node_consent
node_consent -->|"starts session"| node_session
node_session -->|"requests token"| node_backend
node_backend -->|"checks brand"| node_brandconfig
node_backend -->|"checks and counts"| node_usage
node_backend -->|"creates token"| node_decart
node_session -->|"connects realtime"| node_decart
node_session -->|"loads garment"| node_garment
node_garment -->|"sets prompt and image"| node_session

click node_demo "https://github.com/ramyyyy-00/tryon-widget/blob/main/demo/index.html"
click node_widget "https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js"
click node_consent "https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js"
click node_garment "https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js"
click node_session "https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js"
click node_backend "https://github.com/ramyyyy-00/tryon-widget/blob/main/server.js"
click node_brandconfig "https://github.com/ramyyyy-00/tryon-widget/blob/main/brands.json"
click node_usage "https://github.com/ramyyyy-00/tryon-widget/blob/main/server.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_widget,node_consent,node_garment,node_session toneBlue
class node_backend,node_brandconfig,node_usage toneAmber
class node_decart toneMint
class node_shopper toneIndigo
class node_demo toneTeal
```

## Components

### Storefront widget

- [Embed and product buttons](https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js): `public/tryon-widget.js`
- [Consent and camera UI](https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js): `public/tryon-widget.js`
- [Garment and prompt setup](https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js): `public/tryon-widget.js`
- [Realtime session and timer](https://github.com/ramyyyy-00/tryon-widget/blob/main/public/tryon-widget.js): `public/tryon-widget.js`

### Token and usage backend

- [Token API and static hosting](https://github.com/ramyyyy-00/tryon-widget/blob/main/server.js): `server.js`
- [Brand origins and limits](https://github.com/ramyyyy-00/tryon-widget/blob/main/brands.json): `brands.json`
- [Monthly usage counter](https://github.com/ramyyyy-00/tryon-widget/blob/main/server.js): `server.js`

### Try-on provider

- **Decart token and realtime service**

### Other components

- **Store shopper**
- [Demo storefront](https://github.com/ramyyyy-00/tryon-widget/blob/main/demo/index.html): `demo/index.html`

## Connections

- Store shopper → Demo storefront: opens demo (evidence: `README.md`)
- Store shopper → Embed and product buttons: clicks try-on (evidence: `public/tryon-widget.js`)
- Demo storefront → Embed and product buttons: loads widget (evidence: `README.md`)
- Embed and product buttons → Consent and camera UI: opens consent (evidence: `public/tryon-widget.js`)
- Consent and camera UI → Realtime session and timer: starts session (evidence: `public/tryon-widget.js`)
- Realtime session and timer → Token API and static hosting: requests token (evidence: `public/tryon-widget.js`)
- Token API and static hosting → Brand origins and limits: checks brand (evidence: `server.js`)
- Token API and static hosting → Monthly usage counter: checks and counts (evidence: `server.js`)
- Token API and static hosting → Decart token and realtime service: creates token (evidence: `server.js`)
- Realtime session and timer → Decart token and realtime service: connects realtime (evidence: `public/tryon-widget.js`)
- Realtime session and timer → Garment and prompt setup: loads garment (evidence: `public/tryon-widget.js`)
- Garment and prompt setup → Realtime session and timer: sets prompt and image (evidence: `public/tryon-widget.js`)
