# tentsundue/fashion-finder architecture

> Architecture diagram of the GitHub repository tentsundue/fashion-finder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tentsundue/fashion-finder
- Repository: https://github.com/tentsundue/fashion-finder
- Video tour (about a minute): https://gitdiagram.com/tentsundue/fashion-finder/video

## Overview

Purpose and principal workflow

Fashion Finder is a visual clothing-discovery product: an API consumer submits an image path and optional brand/category filters, the server embeds the image and searches catalog image embeddings for similar products, returning paginated product details, variants, and sizes. The implemented web client provides browsing/upload/result presentation pieces, but the sampled code does not establish a browser-to-API search call.

Components

Client experience
- Browser User — repository path: null. Loads and interacts with the single-page fashion-discovery UI.
- React Mount — `client/src/main.tsx`. Creates the React root, applies Chakra’s provider/theme context, and renders the application shell.
- SPA Shell — `client/src/App.tsx`. Owns BrowserRouter setup and currently mounts the navigation plus the root Home route.
- Home Discovery Screen — `client/src/pages/Home/Home.tsx`. The routed discovery-screen boundary exists, though its implementation was not sampled.
- Global Navigation — `client/src/components/Navbar/Navbar.tsx`. Provides home, brand, category, and color-mode navigation controls.
- Image Upload Control — `client/src/components/Dropzone/Dropzone.tsx`. Accepts up to five PNG/JPEG files and emits accepted files to its parent callback.
- Product Result Card — `client/src/components/ProductBox/ProductBox.tsx`. Displays product price, ratings, brand treatment, image variants, and opens a product-details dialog from a ProductInfo value.
- Variant Image Carousel — `client/src/components/ImageCarousel/ImageCarousel.tsx`. Maintains selected-slide state and renders product color-to-image mappings in horizontal or vertical modes.
- Product Detail Dialog — `client/src/components/ProductInfoModal/ProductInfoModal.tsx`. Is instantiated by each product card; dialog internals were not sampled.

API and retrieval
- API Consumer — repository path: null. Initiates the demonstrated principal workflow by calling the HTTP search endpoint.
- FastAPI API Host — `server/main.py`. Creates the FastAPI application and registers separately prefixed products and search routers.
- Similarity Search API — `server/api/routes/search.py`. Accepts image-path similarity searches and listing/filter requests; its main search embeds the query, then uses SQL CTEs to rank products by nearest related image while aggregating color/image variants and sizes.
- Search API Contracts — `server/schemas/search.py`. Defines the request and response models imported by the similarity endpoints.
- Product Catalog API — `server/api/routes/products.py`. Is a separately registered products-routing boundary, but its handlers were not sampled.
- Database Session Provider — `server/db/session.py`. Constructs a SQLAlchemy engine/session factory and yields a request-scoped session that is closed afterward.
- CLIP Embedding Adapter — `server/services/clip_model.py`. Supplies `embed_image`, directly invoked by the search route; README documents OpenCLIP/PyTorch as the intended ML implementation, but the adapter body was not sampled.
- PostgreSQL/pgvector Catalog Database — repository path: null. Stores products, product images and embeddings, colors, and sizes; the query uses pgvector cosine-distance operations and returns stored S3 image URLs.

Offline ingestion and alternate retrieval
- Clothing Website Scraper — repository path: null. A separately maintained scraper documented in the README produces vendor metadata and downloaded images for manual transfer into this project.
- Local Scraped-Image Staging — repository path: null. Runtime image files matching the uploader’s recursive JPEG glob and naming convention.
- S3 Image Publisher — `scripts/upload/upload_images.py`. Parses four-part image filenames and uploads each image to a deterministic `products/{brand}/{product}/{color}.jpg` object key.
- Amazon S3 Product Image Storage — repository path: null. Receives uploaded product images and is the documented source for catalog image URLs.
- Development FAISS Retrieval — `server/services/search_engine.py`. A standalone/testing alternative to pgvector that optionally predicts a category, embeds a local query image, queries category FAISS indexes, and resolves result positions through CSV metadata.
- Local Metadata Dataset — `data/metadata.csv`. Is loaded by the FAISS retrieval module to translate nearest-neighbor indices into product records.
- Local FAISS Index Artifacts — repository path: null. Runtime category index files read by the development retrieval path; their generated files are not present in the supplied tree.

Relationships

- Browser User -> React Mount: loads the client application; evidence: the mount creates a React root from the browser DOM.
- React Mount -> SPA Shell: renders the application inside Chakra provider/theme context; evidence: it renders `App`.
- SPA Shell -> Global Navigation: mounts the navigation for all routed views; evidence: it renders `Navbar` inside BrowserRouter.
- SPA Shell -> Home Discovery Screen: routes `/` to the Home element; evidence: the declared root route renders `Home`.
- Global Navigation -> SPA Shell: requests client-side home, category, and brand navigation; evidence: it uses router links and `useNavigate`.
- Product Result Card -> Variant Image Carousel: renders its product’s color-to-image mapping; evidence: it passes `color_to_s3_url` and product name.
- Product Result Card -> Product Detail Dialog: instantiates the dialog when the card is used as its trigger; evidence: it renders the modal inside `Dialog.Root`.
- API Consumer -> FastAPI API Host: sends an HTTP request initiating product similarity search; evidence: the host registers the search router under `/search`.
- FastAPI API Host -> Similarity Search API: dispatches `/search` requests to the search router; evidence: router inclusion with the search prefix.
- FastAPI API Host -> Product Catalog API: dispatches `/products` requests to the products router; evidence: router inclusion with the products prefix.
- Similarity Search API -> Search API Contracts: declares typed similarity/filter inputs and response models; evidence: endpoint annotations import these models.
- Similarity Search API -> CLIP Embedding Adapter: computes the query image embedding; evidence: it calls `embed_image(request.image_path)`.
- Similarity Search API -> Database Session Provider: requests a database dependency; evidence: endpoints declare `Depends(get_db)`.
- Database Session Provider -> PostgreSQL/pgvector Catalog Database: opens and yields SQLAlchemy sessions against the configured database URL; evidence: engine and sessionmaker construction.
- Similarity Search API -> PostgreSQL/pgvector Catalog Database: executes parameterized vector-ranking and product-aggregation SQL through its injected session; evidence: `db.execute(...).mappings().all()`.
- Similarity Search API -> FastAPI API Host: returns products plus pagination metadata or an HTTP error; evidence: endpoint return dictionaries and exception handling.
- FastAPI API Host -> API Consumer: serializes and sends the endpoint response; evidence: FastAPI response-model registration.
- Clothing Website Scraper -> Local Scraped-Image Staging: produces downloaded vendor images for manual transfer; evidence: README’s documented scraper workflow.
- S3 Image Publisher -> Local Scraped-Image Staging: scans staged JPEG paths and parses their filenames; evidence: recursive globbing and four-part filename validation.
- S3 Image Publisher -> Amazon S3 Product Image Storage: uploads each accepted image to a product/brand/color object key; evidence: Boto3 `upload_file`.
- Development FAISS Retrieval -> CLIP Embedding Adapter: embeds each local query image; evidence: it invokes `embed_image`.
- Development FAISS Retrieval -> Local FAISS Index Artifacts: reads one index per selected or predicted category and performs nearest-neighbor search; evidence: FAISS index loading and `search`.
- Development FAISS Retrieval -> Local Metadata Dataset: resolves returned FAISS indices into metadata rows; evidence: CSV loading and positional selection.

Coverage limits

The sampled client code shows no fetch/upload bridge from the Home or Dropzone UI to the API, and the Results page was not sampled. Product-route handlers, CLIP initialization/model lifecycle, catalog-loading logic, and embedding/index build scripts were also unavailable. The image uploader imports a `backend.config` module not present in the tree, so its executable configuration wiring cannot be confirmed.

Main entry points: [`server/api/routes/search.py`](https://github.com/tentsundue/fashion-finder/blob/main/server/api/routes/search.py) (Similarity Search API), [`server/main.py`](https://github.com/tentsundue/fashion-finder/blob/main/server/main.py) (FastAPI API Host), [`client/src/App.tsx`](https://github.com/tentsundue/fashion-finder/blob/main/client/src/App.tsx) (SPA Shell), [`server/services/search_engine.py`](https://github.com/tentsundue/fashion-finder/blob/main/server/services/search_engine.py) (Development FAISS Retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client Experience"]
  node_browser_user(("Browser User<br/>external actor"))
  node_react_mount["React Mount<br/>frontend entrypoint"]
  node_spa_shell["SPA Shell<br/>frontend shell"]
  node_home_screen["Home Discovery Screen<br/>frontend page"]
  node_global_navigation["Global Navigation<br/>frontend component"]
  node_product_card["Product Result Card<br/>frontend component"]
  node_variant_carousel["Variant Image Carousel<br/>frontend component"]
  node_product_dialog["Product Detail Dialog<br/>frontend component"]
end

subgraph group_api["API and Retrieval"]
  node_api_consumer(("API Consumer<br/>external client"))
  node_fastapi_host["FastAPI API Host<br/>[main.py]"]
  node_search_api["Similarity Search API<br/>api route"]
  node_search_contracts["Search API Contracts<br/>schema models"]
  node_products_api["Product Catalog API<br/>api route"]
  node_clip_adapter["CLIP Embedding Adapter<br/>ML adapter"]
end

subgraph group_catalog["Catalog Persistence"]
  node_db_session["Database Session Provider<br/>database access"]
  node_catalog_db[("PostgreSQL/pgvector Catalog Database")]
  node_s3_storage[("Amazon S3 Product Image Storage<br/>object storage")]
end

subgraph group_ingestion["Offline Ingestion"]
  node_scraper["Clothing Website Scraper<br/>external ingestion"]
  node_image_staging["Local Scraped-Image Staging<br/>local file staging"]
  node_s3_publisher["S3 Image Publisher<br/>ingestion script"]
end

subgraph group_faiss["Development Retrieval"]
  node_faiss_retrieval["Development FAISS Retrieval<br/>alternate retrieval"]
  node_metadata_dataset["Local Metadata Dataset<br/>metadata file"]
  node_faiss_artifacts[("Local FAISS Index Artifacts<br/>index files")]
end

node_browser_user -->|"loads app"| node_react_mount
node_react_mount -->|"renders"| node_spa_shell
node_spa_shell -->|"mounts navigation"| node_global_navigation
node_spa_shell -->|"routes /"| node_home_screen
node_global_navigation -->|"navigates"| node_spa_shell
node_product_card -->|"renders variants"| node_variant_carousel
node_product_card -->|"opens details"| node_product_dialog
node_api_consumer -->|"searches"| node_fastapi_host
node_fastapi_host -->|"dispatches /search"| node_search_api
node_fastapi_host -->|"dispatches /products"| node_products_api
node_search_api -->|"uses contracts"| node_search_contracts
node_search_api -->|"embeds query"| node_clip_adapter
node_search_api -->|"requests session"| node_db_session
node_db_session -->|"opens session"| node_catalog_db
node_search_api -->|"ranks products"| node_catalog_db
node_search_api -->|"returns results"| node_fastapi_host
node_fastapi_host -->|"sends response"| node_api_consumer
node_scraper -->|"produces images"| node_image_staging
node_s3_publisher -->|"scans images"| node_image_staging
node_s3_publisher -->|"uploads images"| node_s3_storage
node_faiss_retrieval -.->|"embeds query"| node_clip_adapter
node_faiss_retrieval -.->|"searches indexes"| node_faiss_artifacts
node_faiss_retrieval -.->|"resolves metadata"| node_metadata_dataset

click node_react_mount "https://github.com/tentsundue/fashion-finder/blob/main/client/src/main.tsx"
click node_spa_shell "https://github.com/tentsundue/fashion-finder/blob/main/client/src/App.tsx"
click node_home_screen "https://github.com/tentsundue/fashion-finder/blob/main/client/src/pages/Home/Home.tsx"
click node_global_navigation "https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/Navbar/Navbar.tsx"
click node_product_card "https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ProductBox/ProductBox.tsx"
click node_variant_carousel "https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ImageCarousel/ImageCarousel.tsx"
click node_product_dialog "https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ProductInfoModal/ProductInfoModal.tsx"
click node_fastapi_host "https://github.com/tentsundue/fashion-finder/blob/main/server/main.py"
click node_search_api "https://github.com/tentsundue/fashion-finder/blob/main/server/api/routes/search.py"
click node_search_contracts "https://github.com/tentsundue/fashion-finder/blob/main/server/schemas/search.py"
click node_products_api "https://github.com/tentsundue/fashion-finder/blob/main/server/api/routes/products.py"
click node_db_session "https://github.com/tentsundue/fashion-finder/blob/main/server/db/session.py"
click node_clip_adapter "https://github.com/tentsundue/fashion-finder/blob/main/server/services/clip_model.py"
click node_s3_publisher "https://github.com/tentsundue/fashion-finder/blob/main/scripts/upload/upload_images.py"
click node_faiss_retrieval "https://github.com/tentsundue/fashion-finder/blob/main/server/services/search_engine.py"
click node_metadata_dataset "https://github.com/tentsundue/fashion-finder/blob/main/data/metadata.csv"

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_browser_user,node_react_mount,node_spa_shell,node_home_screen,node_global_navigation,node_product_card,node_variant_carousel,node_product_dialog toneBlue
class node_api_consumer,node_fastapi_host,node_search_api,node_search_contracts,node_products_api,node_clip_adapter toneAmber
class node_db_session,node_catalog_db,node_s3_storage toneMint
class node_scraper,node_image_staging,node_s3_publisher toneRose
class node_faiss_retrieval,node_metadata_dataset,node_faiss_artifacts toneIndigo
```

## Components

### Client Experience

Browser-based fashion discovery interface.

- **Browser User**: external actor · Loads and interacts with the fashion-discovery UI.
- [React Mount](https://github.com/tentsundue/fashion-finder/blob/main/client/src/main.tsx): frontend entrypoint · `client/src/main.tsx`
- [SPA Shell](https://github.com/tentsundue/fashion-finder/blob/main/client/src/App.tsx): frontend shell · `client/src/App.tsx`
- [Home Discovery Screen](https://github.com/tentsundue/fashion-finder/blob/main/client/src/pages/Home/Home.tsx): frontend page · Routed discovery-screen boundary. · `client/src/pages/Home/Home.tsx`
- [Global Navigation](https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/Navbar/Navbar.tsx): frontend component · `client/src/components/Navbar/Navbar.tsx`
- [Product Result Card](https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ProductBox/ProductBox.tsx): frontend component · `client/src/components/ProductBox/ProductBox.tsx`
- [Variant Image Carousel](https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ImageCarousel/ImageCarousel.tsx): frontend component · `client/src/components/ImageCarousel/ImageCarousel.tsx`
- [Product Detail Dialog](https://github.com/tentsundue/fashion-finder/blob/main/client/src/components/ProductInfoModal/ProductInfoModal.tsx): frontend component · Dialog internals were not sampled. · `client/src/components/ProductInfoModal/ProductInfoModal.tsx`

### API and Retrieval

HTTP API, embedding, and catalog search services.

- **API Consumer**: external client · Initiates HTTP similarity searches.
- [FastAPI API Host](https://github.com/tentsundue/fashion-finder/blob/main/server/main.py): api host · `server/main.py`
- [Similarity Search API](https://github.com/tentsundue/fashion-finder/blob/main/server/api/routes/search.py): api route · Embeds queries and ranks catalog products. · `server/api/routes/search.py`
- [Search API Contracts](https://github.com/tentsundue/fashion-finder/blob/main/server/schemas/search.py): schema models · `server/schemas/search.py`
- [Product Catalog API](https://github.com/tentsundue/fashion-finder/blob/main/server/api/routes/products.py): api route · Products-routing boundary; handlers were not sampled. · `server/api/routes/products.py`
- [CLIP Embedding Adapter](https://github.com/tentsundue/fashion-finder/blob/main/server/services/clip_model.py): ML adapter · Provides image embeddings. · `server/services/clip_model.py`

### Catalog Persistence

Database-backed product catalog and image storage.

- [Database Session Provider](https://github.com/tentsundue/fashion-finder/blob/main/server/db/session.py): database access · Creates request-scoped SQLAlchemy sessions. · `server/db/session.py`
- **PostgreSQL/pgvector Catalog Database**: catalog database · Stores products, images, embeddings, colors, and sizes.
- **Amazon S3 Product Image Storage**: object storage · Stores catalog product images and supplies image URLs.

### Offline Ingestion

Scraped image staging and S3 publishing.

- **Clothing Website Scraper**: external ingestion · Produces vendor metadata and downloaded images.
- **Local Scraped-Image Staging**: local file staging · Staged runtime JPEG image files.
- [S3 Image Publisher](https://github.com/tentsundue/fashion-finder/blob/main/scripts/upload/upload_images.py): ingestion script · Uploads accepted images using deterministic object keys. · `scripts/upload/upload_images.py`

### Development Retrieval

Local FAISS-based testing retrieval path.

- [Development FAISS Retrieval](https://github.com/tentsundue/fashion-finder/blob/main/server/services/search_engine.py): alternate retrieval · Testing retrieval over local category indexes. · `server/services/search_engine.py`
- [Local Metadata Dataset](https://github.com/tentsundue/fashion-finder/blob/main/data/metadata.csv): metadata file · Maps FAISS positions to product records. · `data/metadata.csv`
- **Local FAISS Index Artifacts**: index files · Runtime category index files.

## Connections

- Browser User → React Mount: loads app
- React Mount → SPA Shell: renders · Renders the application inside the Chakra provider and theme context.
- SPA Shell → Global Navigation: mounts navigation
- SPA Shell → Home Discovery Screen: routes /
- Global Navigation → SPA Shell: navigates · Requests client-side home, category, and brand navigation.
- Product Result Card → Variant Image Carousel: renders variants
- Product Result Card → Product Detail Dialog: opens details
- API Consumer → FastAPI API Host: searches · Sends an HTTP request initiating product similarity search.
- FastAPI API Host → Similarity Search API: dispatches /search
- FastAPI API Host → Product Catalog API: dispatches /products
- Similarity Search API → Search API Contracts: uses contracts
- Similarity Search API → CLIP Embedding Adapter: embeds query
- Similarity Search API → Database Session Provider: requests session
- Database Session Provider → PostgreSQL/pgvector Catalog Database: opens session
- Similarity Search API → PostgreSQL/pgvector Catalog Database: ranks products · Executes vector-ranking and product-aggregation SQL.
- Similarity Search API → FastAPI API Host: returns results · Returns products, pagination metadata, or an HTTP error.
- FastAPI API Host → API Consumer: sends response
- Clothing Website Scraper → Local Scraped-Image Staging: produces images · Produces downloaded vendor images for manual transfer.
- S3 Image Publisher → Local Scraped-Image Staging: scans images · Scans staged JPEG paths and parses filenames.
- S3 Image Publisher → Amazon S3 Product Image Storage: uploads images
- Development FAISS Retrieval → CLIP Embedding Adapter: embeds query
- Development FAISS Retrieval → Local FAISS Index Artifacts: searches indexes
- Development FAISS Retrieval → Local Metadata Dataset: resolves metadata
