# maazuddin1/tanishq_jewelry_recomm_system architecture

> Architecture diagram of the GitHub repository maazuddin1/tanishq_jewelry_recomm_system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maazuddin1/tanishq_jewelry_recomm_system
- Repository: https://github.com/maazuddin1/tanishq_jewelry_recomm_system

## Overview

##### Project type and purpose
- This is a machine-learning-powered recommendation system exposed via a Gradio-based web UI.
- Purpose: users upload a jewelry image, and the system returns top-N Tanishq jewelry recommendations.

##### File structure
- Top-level “app.py” is the Gradio entry point; “frontend/” holds UI code.
- “backend/” contains the service layer and supporting modules (model loader, image processor, recommender).
- “utils/formatter.py” handles response formatting.
- “models/” stores precomputed index and metadata files.
- “config.py” holds global constants (paths, device, default recommendation count).

##### README for additional insights
- The README defines the pipeline: User → app.py → frontend/gradio_app.py → input_handlers → backend service → supporting modules → config → models.
- No external database; model artifacts live on disk.

a. Main components:
- User & Browser (web client)
- Gradio Web Server (app.py + frontend/gradio_app.py)
- Input Handlers (frontend/input_handlers.py)
- Recommendation Service (backend/jewelry_recomm_service.py)
- Supporting Modules:
– Model Loader (backend/supportingfiles/model_loader.py)
– Image Processor (backend/supportingfiles/image_processor.py)
– Recommender Engine (backend/supportingfiles/recommender.py)
- Configuration Store (config.py)
- Model Artifacts (models/jewelry_index.idx, metadata.pkl)
- Formatter (utils/formatter.py)

b. Relationships & data flows:
1. User uploads image via Browser → Gradio UI
2. Gradio App invokes Input Handler → passes image and parameters
3. Input Handler calls Recommendation Service
4. Service loads model & metadata via Model Loader (uses paths from config)
5. Service preprocesses image via Image Processor (applies transforms from config)
6. Service queries Recommender Engine (uses index + metadata, DEFAULT_NUM_RECOMMENDATIONS)
7. Service returns raw recommendations → Input Handler
8. Input Handler invokes Formatter → produces API response
9. Gradio UI renders output to user

c. Architectural patterns/design principles:
- Layered architecture (Presentation → Application → Domain → Data)
- Single-process monolith, but clear separation of concerns
- Config-driven paths and parameters
- Model artifacts decoupled from code

d. Key technologies & libraries:
- Python 3.x
- Gradio (frontend)
- PyTorch or similar (device handling in config, image transforms)
- FAISS or another vector index (jewelry_index.idx)
- Pickle for metadata
- Standard Python modules for config management

##### Detailed capture of essential elements
- Do not omit: Input Handler, Formatter, Config, Model Loader, Image Processor, Recommender, Gradio App, Model files.
- Notebook (“nb/”) as a development artifact, separate from production.
- “requirements.txt” & Docker or deployment scripts (if any) as peripheral artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actor
    User["User / Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        App["Gradio Web Server\n(app.py)"]:::frontend
        GradioApp["Gradio Web App\n(gradio_app.py)"]:::frontend
        InputHandler["Input Handlers\n(input_handlers.py)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        Service["Recommendation Service\n(jewelry_recomm_service.py)"]:::backend
        subgraph "Supporting Modules"
            direction TB
            ModelLoader["Model Loader\n(model_loader.py)"]:::backend
            ImageProcessor["Image Processor\n(image_processor.py)"]:::backend
            Recommender["Recommender Engine\n(recommender.py)"]:::backend
        end
    end

    %% Config and Utils
    Config["Configuration Store\n(config.py)"]:::config
    Formatter["Formatter Utility\n(formatter.py)"]:::util

    %% Data Storage
    subgraph "Model Artifacts"
        direction TB
        Index["Index File\n(jewelry_index.idx)"]:::data
        Metadata["Metadata File\n(jewelry_metadata.pkl)"]:::data
    end

    %% Data Flows
    User -->|"upload image"| App
    App -->|"initialize UI"| GradioApp
    GradioApp -->|"user submits image"| InputHandler
    InputHandler -->|"call recommend()"| Service
    Service -->|"load model & metadata"| ModelLoader
    Service -->|"preprocess image"| ImageProcessor
    Service -->|"query recommendations"| Recommender
    Service -->|"reads paths from config"| Config
    ModelLoader -->|"reads index & metadata"| Index
    ModelLoader -->|"reads index & metadata"| Metadata
    Service -->|"raw results"| InputHandler
    InputHandler -->|"format response"| Formatter
    Formatter -->|"uses config"| Config
    Formatter -->|"formatted output"| GradioApp
    GradioApp -->|"render results"| User

    %% Click Events
    click App "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/app.py"
    click GradioApp "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/frontend/gradio_app.py"
    click InputHandler "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/frontend/input_handlers.py"
    click Service "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/backend/jewelry_recomm_service.py"
    click ModelLoader "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/backend/supportingfiles/model_loader.py"
    click ImageProcessor "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/backend/supportingfiles/image_processor.py"
    click Recommender "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/backend/supportingfiles/recommender.py"
    click Config "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/config.py"
    click Formatter "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/utils/formatter.py"
    click Index "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/models/jewelry_index.idx"
    click Metadata "https://github.com/maazuddin1/tanishq_jewelry_recomm_system/blob/main/models/jewelry_metadata.pkl"

    %% Styles
    classDef external fill:#D3EBCD,stroke:#2F855A,color:#22543D
    classDef frontend fill:#BEE3F8,stroke:#2B6CB0,color:#2C5282
    classDef backend fill:#FED7D7,stroke:#C53030,color:#742A2A
    classDef util fill:#F0FFF4,stroke:#38A169,color:#2F855A
    classDef config fill:#E9D8FD,stroke:#6B46C1,color:#422657
    classDef data fill:#FEFCBF,stroke:#D69E2E,color:#975A16
```
