How qasimhassan65/vetra works
Project Type & Purpose
• This is a browser-extension project (“Vetra”) for Chrome that adds a minimalistic virtual try-on experience on e-commerce sites.
• Core features: product detection (content script), UI popup for photo upload & history, background script for messaging & state, AI integration with Google Gemini.
a. Manifest & Assets (static)
b. Content Script (content.js)
• Injects into e-commerce pages
• Detects products & attaches click handlers
c. Background Script (background.js)
• Acts as a service worker / message broker
• Manages extension-wide state (Chrome storage)
• Opens/closes side panel
d. Popup UI (popup.html, popup.css, popup.js)
• Photo upload widget
• “Try On” button & 3D carousel history
• Reads/writes state via messages to background
e. Configuration (config.js / config.example.js)
• Holds API URL & key templates
f. External Service (Google Gemini API)
• Image upload endpoint
• Generation endpoint
g. Chrome Storage (local & sync)
• Persists uploaded photos & generated results across navigations
Relationships & Data Flows
• Popup UI ↔ Background Script
• Message channel for user actions (upload, “Try On”, history requests)
• Content Script ↔ Background Script
• Messaged events when user clicks a product on page
• Payload: product image URL, metadata
• Background Script → Gemini API (HTTPS)
• Sends image & product context to AI
• Receives generated try-on image
• Background Script ↔ Chrome Storage
• Saves user sessions, history entries, last result
• Popup UI ← reads history from Chrome Storage via background messaging
• Content Script injects UI panel on page when instructed by background
Architectural Patterns & Principles
• Event-driven messaging (Chrome runtime.sendMessage/onMessage)
• Separation of concerns:
• UI layer (popup)
• DOM Integration layer (content script)
• Orchestration & state layer (background)
• External API isolation: config files drive endpoint & key
• Progressive enhancement: minimal UI, no data collection, secure HTTPS