How ayushdixit1-av/ar-product-viewer works
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: app.js UI controller · index.html Application shell · api.js ApiClient · generate-models.js Model generator
Components 13
Node service
- Express server · Serves the SPA, proxies API traffic, and falls back to the app shell.
server.js - External API · Optional cfcrack.co.in upstream for product and AR data.
Browser SPA
- Application shell · Single document containing the SPA sections and rendering component.
index.html - UI controller · Owns navigation, catalog interaction, selection, and AR controls.
js/app.js - ApiClient · Uses backend endpoints with an offline catalog fallback.
js/api.js - Responsive styles
css/style.css - Catalog and filters · Renders available products and the selected item.
3D and AR
- model-viewer · Displays GLB models and provides AR handoff.
- Native AR runtimes · WebXR/ARCore/ARKit with Scene Viewer and Quick Look fallbacks.
- Runtime GLB assets · Furniture, decor, and lighting geometry referenced by products.
assets/models/modern-chair.glb
Offline assets
- Model generator · Builds GLB assets from Three.js scenes through GLTF export.
generate-models.js - Coffee table GLB
assets/models/coffee-table.glb - Floor lamp GLB
assets/models/floor-lamp.glb
Connections 16
- 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