# ritesh2006m/jewellery-sketch-to-realistic-design-transformation- architecture

> Architecture diagram of the GitHub repository ritesh2006m/jewellery-sketch-to-realistic-design-transformation-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-
- Repository: https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-

## Overview

##### Project type and purpose
- This is a full-stack web application whose goal is to transform user-provided jewelry sketches or text prompts into realistic gold-jewelry images and let users organize those outputs into personalized collections.
- Key technologies: React (client), Node.js/Express (backend API), Python/Flask (AI model inference), TensorFlow-Keras model (.h5), and a persistent store for user data.

##### File structure
- Top level:
- api/ → Node.js + Express backend, contains server.js, userModel.js, model/ with Python scripts and the `.h5` model file
- client/ → React single-page application with components, CSS, public assets, and Firebase config
- api/.env : environment variables (e.g., database URI, Firebase secrets)
- client/src/firebase/firebase-config.js : front-end’s Firebase initialization (auth, possibly Firestore)
- package.json in root, api/, client/ indicating separate npm projects and scripts

##### README
- Describes two “services”:
a. Sketch-to-Jewelry (upload sketch → realistic image)
b. Text-to-Image (text prompt → jewelry design)
- Notes Python dependencies (Flask, TensorFlow, Torch, diffusers), Node dependencies, and instructions to start both backend and frontend with npm scripts.

##### Main components and interactions
a. Components:
1. User’s Web Browser (UI)
2. React Frontend (client/src)
3. Firebase Auth Service (external)
4. Node.js/Express Backend (api/server.js + user/userModel.js)
5. Python/Flask ML Microservice (api/model/app.py)
6. AI Model File (generator.h5)
7. Datastore (e.g., MongoDB or Firebase Firestore)
8. Object Storage (optional – storing generated images)
b. Data Flow / Interactions:
1. User logs in or signs up via React → Firebase Auth → returns JWT
2. React issues REST calls to Express, attaching JWT
3. Express middleware validates JWT (or uses its own DB via Mongoose) → handles user profile & collection CRUD
4. For generation requests, Express forwards payload (sketch image or text prompt) to Flask ML service
5. Flask loads `.h5` model and runs inference → returns generated image
6. Express stores image metadata (and maybe the image itself in object storage) and updates user’s collection in the database
7. React polls or fetches updated collection for display
c. Architectural patterns & principles:
– Clear separation of concerns: UI, API gateway, ML inference service, and persistence
– Microservice style for heavy AI tasks to isolate Python dependencies
– Stateless frontend + stateful backend (JWT-based auth)
– Use of environment variables for secrets/config
d. Key technologies / frameworks:
– React + React Router + CSS modules
– Firebase Auth (and possibly Firestore)
– Express.js + Mongoose (MongoDB) or alternative DB
– Flask + Flask-CORS for Python service
– TensorFlow/Keras, Torch, diffusers for AI inference

##### Elements
- UI (blue)
- API gateway (green)
- ML microservice (orange)
- External services (gray)
– Notation for environment variables (.env) feeding into Express and Flask

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        Browser["User Browser"]:::ui
        ReactSPA["React SPA"]:::ui
        ReactComps["React Components"]:::ui
        FirebaseAuth["Firebase Auth Service"]:::external
    end

    subgraph "Backend API Gateway"
        ExpressAPI["Express API Gateway"]:::api
        UserRoutes["User Management Module"]:::api
        UserModel["User Model"]:::api
        EnvConfig["Environment Config (.env)"]:::api
    end

    subgraph "ML Microservice"
        FlaskAPI["Flask ML Service"]:::ml
        ImageProc["Sketch-to-Jewelry Service"]:::ml
        TextProc["Text-to-Image Service"]:::ml
        ModelFile["AI Model File (.h5)"]:::ml
    end

    subgraph "Data Layer"
        Datastore["MongoDB / Firestore"]:::db
        ObjectStorage["Object Storage"]:::db
    end

    subgraph "Project Manifests"
        RootPkg["root package.json"]
        ApiPkg["api/package.json"]
        ClientPkg["client/package.json"]
    end

    Browser -->|"loads SPA"| ReactSPA
    ReactSPA -->|"uses components"| ReactComps
    ReactSPA -->|"login/signup"| FirebaseAuth
    ReactSPA -->|"JWT secured calls"| ExpressAPI
    ReactSPA -->|"GET /collections"| ExpressAPI

    ExpressAPI -->|"routes to user endpoints"| UserRoutes
    ExpressAPI -->|"uses schema"| UserModel
    ExpressAPI -->|"loads secrets"| EnvConfig
    ExpressAPI -->|"POST /generate-sketch or text"| FlaskAPI
    ExpressAPI -->|"store metadata"| Datastore
    ExpressAPI -->|"store image binary"| ObjectStorage

    FlaskAPI -->|"calls inference"| ImageProc
    FlaskAPI -->|"calls inference"| TextProc
    FlaskAPI -->|"loads model file"| ModelFile
    FlaskAPI -->|"returns image"| ExpressAPI

    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef api fill:#DFFFE0,stroke:#28A745,color:#28A745;
    classDef ml fill:#FFE8B0,stroke:#F29E1E,color:#F29E1E;
    classDef db fill:#E0D0FF,stroke:#6F42C1,color:#6F42C1;
    classDef external fill:#F0F0F0,stroke:#6C757D,color:#6C757D;

    click ReactSPA "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/tree/main/client/src"
    click ReactComps "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/tree/main/client/src/components"
    click FirebaseAuth "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/client/src/firebase/firebase-config.js"
    click ExpressAPI "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/server.js"
    click UserRoutes "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/user.js"
    click UserModel "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/userModel.js"
    click EnvConfig "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/.env"
    click FlaskAPI "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/model/app.py"
    click ImageProc "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/model/image_processing.py"
    click TextProc "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/model/instruct.py"
    click ModelFile "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/tree/main/api/model/"
    click RootPkg "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/package.json"
    click ApiPkg "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/api/package.json"
    click ClientPkg "https://github.com/ritesh2006m/jewellery-sketch-to-realistic-design-transformation-/blob/main/client/package.json"
```
