# ayushdixit1-av/ar-product-viewer architecture

> Architecture diagram of the GitHub repository ayushdixit1-av/ar-product-viewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayushdixit1-av/ar-product-viewer
- Repository: https://github.com/ayushdixit1-av/ar-product-viewer

## Overview

#### Purpose and Runtime

AR Product Viewer is a Node-served, vanilla-JavaScript single-page product catalog for viewing furniture GLB assets in 3D and launching device-native/WebXR AR placement. It runs as an Express service on port 3000 and serves static frontend and model assets.

Core entry points:
- `server.js`
- `index.html`
- `js/app.js`

#### HTTP Server and API Boundary

`server.js` is the deployment boundary. It serves project-root static content, proxies browser `/api/*` traffic to `https://cfcrack.co.in`, adds CORS behavior, and returns `index.html` for unmatched routes so client-side navigation remains functional.

The external API is optional at runtime: frontend behavior must remain usable when proxy/upstream calls fail.
- `server.js`
- `js/api.js`

#### SPA Views and Navigation Control

The UI is implemented as sections within one document rather than separate pages. `js/app.js` owns client-side view changes, catalog interaction, product selection, model-viewer configuration, and AR-related controls across landing, catalog, detail, and full-screen AR views.

`index.html` defines the application shell and embeds/loads the rendering component; `css/style.css` provides responsive presentation but is not a routing or application boundary.
- `index.html`
- `js/app.js`
- `css/style.css`

#### Catalog and Resilient Product Data

`ApiClient` mediates all product, AR-session, and capture requests. It first targets backend API endpoints, while retaining a hardcoded catalog fallback for offline or unavailable upstream conditions. The UI consumes this abstraction rather than directly coupling to remote API URLs.

Primary flow: app initialization → product retrieval through `ApiClient` → catalog/filter rendering → selected product passed to detail/AR viewer.
- `js/api.js`
- `js/app.js`
- `server.js`

#### 3D and AR Delivery Pipeline

Google `model-viewer` is the client rendering boundary for GLB display: interactive orbit controls, lighting/shadows, auto-rotation, and AR handoff. Supported mobile environments use WebXR/ARCore/ARKit, with Scene Viewer or Quick Look as platform fallbacks; unsupported desktop environments retain standard 3D preview.

Models are static binary assets loaded by product references, keeping renderable geometry separate from catalog/UI logic.
- `index.html`
- `js/app.js`
- `assets/models/modern-chair.glb`

#### Asset Generation and Model Contract

`generate-models.js` is an offline build-stage generator, not part of browser execution. It uses Three.js geometry/material scene graphs and GLTF export to create the GLB files consumed at runtime. This establishes model dimensions/materials in code and produces a stable asset contract for the catalog.

Generated asset set includes furniture, decor, and lighting models.
- `generate-models.js`
- `assets/models/coffee-table.glb`
- `assets/models/floor-lamp.glb`

#### End-to-End Control Flow

1. Node starts `server.js`, exposing SPA/assets and API proxy routes.
2. Browser loads `index.html`; `js/app.js` initializes UI state and navigation.
3. `js/api.js` obtains remote data or supplies fallback catalog data.
4. Selecting an item binds its `.glb` asset to the model viewer.
5. AR-capable devices launch AR through model-viewer/WebXR; session/capture events can POST through the proxy to the external API.

Main entry points: [`js/app.js`](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/app.js) (UI controller), [`index.html`](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/index.html) (Application shell), [`js/api.js`](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/api.js) (ApiClient), [`generate-models.js`](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/generate-models.js) (Model generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Node service"]
  node_express["Express server<br/>deployment boundary<br/>[server.js]"]
  node_upstream{{"External API<br/>remote service"}}
end

subgraph group_spa["Browser SPA"]
  node_shell["Application shell<br/>HTML document<br/>[index.html]"]
  node_app["UI controller<br/>vanilla JS<br/>[app.js]"]
  node_api["ApiClient<br/>data adapter<br/>[api.js]"]
  node_styles["Responsive styles<br/>CSS<br/>[style.css]"]
  node_catalog["Catalog and filters<br/>UI state"]
end

subgraph group_ar["3D and AR"]
  node_viewer["model-viewer<br/>rendering boundary"]
  node_platform_ar{{"Native AR runtimes<br/>platform services"}}
  node_runtime_models["Runtime GLB assets<br/>static models<br/>[modern-chair.glb]"]
end

subgraph group_build["Offline assets"]
  node_generator["Model generator<br/>offline Node script<br/>[generate-models.js]"]
  node_coffee_table["Coffee table GLB<br/>generated asset<br/>[coffee-table.glb]"]
  node_floor_lamp["Floor lamp GLB<br/>generated asset<br/>[floor-lamp.glb]"]
end

node_express -->|"serves SPA"| node_shell
node_express -->|"proxies /api/*"| node_upstream
node_shell -->|"loads"| node_app
node_shell -->|"loads"| node_styles
node_shell -->|"embeds"| node_viewer
node_app -->|"retrieves products"| node_api
node_api -->|"calls /api endpoints"| node_express
node_api -->|"remote or fallback data"| node_catalog
node_catalog -->|"selection"| node_app
node_app -->|"binds selected GLB"| node_viewer
node_runtime_models -->|"loads geometry"| node_viewer
node_viewer -->|"AR handoff"| node_platform_ar
node_app -.->|"session and capture events"| node_api
node_generator -->|"generates"| node_coffee_table
node_generator -->|"generates"| node_floor_lamp
node_generator -.->|"establishes asset contract"| node_runtime_models

click node_express "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/server.js"
click node_shell "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/index.html"
click node_app "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/app.js"
click node_api "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/api.js"
click node_styles "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/css/style.css"
click node_runtime_models "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/modern-chair.glb"
click node_generator "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/generate-models.js"
click node_coffee_table "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/coffee-table.glb"
click node_floor_lamp "https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/floor-lamp.glb"

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_express,node_upstream toneBlue
class node_shell,node_app,node_api,node_styles,node_catalog toneAmber
class node_viewer,node_platform_ar,node_runtime_models toneMint
class node_generator,node_coffee_table,node_floor_lamp toneRose
```

## Components

### Node service

- [Express server](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/server.js): deployment boundary · Serves the SPA, proxies API traffic, and falls back to the app shell. · `server.js`
- **External API**: remote service · Optional cfcrack.co.in upstream for product and AR data.

### Browser SPA

- [Application shell](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/index.html): HTML document · Single document containing the SPA sections and rendering component. · `index.html`
- [UI controller](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/app.js): vanilla JS · Owns navigation, catalog interaction, selection, and AR controls. · `js/app.js`
- [ApiClient](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/js/api.js): data adapter · Uses backend endpoints with an offline catalog fallback. · `js/api.js`
- [Responsive styles](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/css/style.css): CSS · `css/style.css`
- **Catalog and filters**: UI state · Renders available products and the selected item.

### 3D and AR

- **model-viewer**: rendering boundary · Displays GLB models and provides AR handoff.
- **Native AR runtimes**: platform services · WebXR/ARCore/ARKit with Scene Viewer and Quick Look fallbacks.
- [Runtime GLB assets](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/modern-chair.glb): static models · Furniture, decor, and lighting geometry referenced by products. · `assets/models/modern-chair.glb`

### Offline assets

- [Model generator](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/generate-models.js): offline Node script · Builds GLB assets from Three.js scenes through GLTF export. · `generate-models.js`
- [Coffee table GLB](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/coffee-table.glb): generated asset · `assets/models/coffee-table.glb`
- [Floor lamp GLB](https://github.com/ayushdixit1-av/ar-product-viewer/blob/master/assets/models/floor-lamp.glb): generated asset · `assets/models/floor-lamp.glb`

## Connections

- Express server → Application shell: serves SPA
- Express server → External API: proxies /api/*
- Application shell → UI controller: loads
- Application shell → Responsive styles: loads
- Application shell → model-viewer: embeds
- UI controller → ApiClient: retrieves products
- ApiClient → Express server: calls /api endpoints
- ApiClient → Catalog and filters: remote or fallback data
- Catalog and filters → UI controller: selection
- UI controller → model-viewer: binds selected GLB
- Runtime GLB assets → model-viewer: loads geometry
- model-viewer → Native AR runtimes: AR handoff
- UI controller → ApiClient: session and capture events
- Model generator → Coffee table GLB: generates
- Model generator → Floor lamp GLB: generates
- Model generator → Runtime GLB assets: establishes asset contract
