How harsh251singh/visual-product-manager works
Project Type and Purpose
• This is a full-stack web application for finding visually similar products.
• Frontend: React + Vite SPA
• Backend: Node.js + Express API
• Database: MongoDB
• Core functionality: image upload/URL input → image processing (Sharp + vector similarity) → search/filter/store results.
File Structure
• Top-level folders:
• frontend/: React app (components, routes, assets, CSS)
• backend/: Express server (config, models, controllers, routes)
• Backend follows an MVC‐style organization (model/, src/controllers/, src/routes/).
• Config/environment (backend/config/db.js, .env expected).
• Build & startup scripts: package.json, vite.config.js.
README for Architecture Insights
• Authentication (JWT).
• Image processing pipeline using Sharp.
• Cosine similarity computations against precomputed vectors (Kaggle dataset).
• Responsive, Bootstrap‐styled UI.
Main Components & Their Roles
A. Client (Browser)
• Hosts React SPA, issues HTTP requests to backend.
• UI Components: Auth, Upload, Processing, Result, Sidebar.
B. Frontend Application (React + Vite)
• Routes (SPA): defined in frontend/src/routes/index.jsx.
• API layer: fetch wrappers or direct fetch/axios calls to backend endpoints.
C. API Gateway / Backend Server (Node.js + Express)
• Entry point: backend/index.js
• Routes: src/routes/index.js maps URLs (e.g., /api/auth, /api/images) to controllers.
• Controllers:
• AuthController (login, register, JWT issuance).
• ImageController (searchAndStoreSimilarImages, getImageResults, getUserUploadedImages).
• Services/Utilities:
• Image processing (Sharp transforms).
• Similarity engine (cosine similarity against stored vectors).
• Database models: UserModel, ImageModel (via Mongoose).
D. Database (MongoDB)
• Collections: users, images (stores metadata, vectors, reference to file storage or URLs).
E. External Data / Storage
• Kaggle dataset of random images (preloaded or stored in a cloud bucket/local FS).
• (Optional) Cloud file storage or local disk for uploaded images.
Relationships & Data Flows
1. User uploads an image (or inputs URL) → Frontend POST /api/images/search.
2. Backend Controller receives request → passes image to Sharp for resizing/formatting.
3. Processed image → vectorized (embedding) → compared (cosine similarity) against vectors in MongoDB.
4. Top-N similar results fetched → stored in images collection if user “saves.”
5. Response JSON (image URLs, metadata, similarity scores) → returned to Frontend.
6. Frontend renders results in Result.jsx, allows filtering/saving.
Authentication flow: React login/register → POST /api/auth/login|register → JWT returned → stored in localStorage → attached to subsequent API requests (Authorization header).
Architectural Patterns & Principles
• Separation of Concerns: UI vs. API vs. Data layer.
• MVC (lightweight) on backend: routers → controllers → models.
• Stateless API with JWT auth.
• Modularization: distinct controllers for auth vs. image logic.
• Scalability: image processing and similarity computations can be extracted into microservices or serverless functions later.
Essential Elements
• Notation for asynchronous operations (e.g., vector computation).
• Callouts for third-party libraries (Sharp, Mongoose) if desired.