# aniike-t/content-based-image-retrieval architecture

> Architecture diagram of the GitHub repository aniike-t/content-based-image-retrieval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aniike-t/content-based-image-retrieval
- Repository: https://github.com/aniike-t/content-based-image-retrieval

## Overview

##### Project Type and Purpose
- This is a full-stack application that implements a CBIR system using a Vision Transformer (ViT) for image feature extraction along with NLP (utilizing spaCy, NLTK, and WordNet) to process natural language queries.
- The backend (Python/Flask) handles image processing (including quadtree segmentation and vector space modeling) and interacts with an SQLite database, while the frontend (React.js) provides an interactive interface for image uploads, searches, and user feedback.

##### Main Components
- Frontend:
– React-based UI (see frontend/CBIR_Frontend) with components for image upload (UploadArea), search functionality (SearchBar), results display (ImageGrid), and feedback (binary and textual).
– The frontend communicates (via HTTP calls) with the backend server.
- Backend:
– HTTP API Server (main.py in backend/system) that orchestrates the retrieval and processing tasks.
– Retrieval Module: Includes algorithms for retrieving and ranking images (backend/system/Retrieval/RetrieveAlgo.py).
– NLP / Tokenisation Module: Contains scripts for generating SQL queries and processing sentences and word extraction (backend/system/tokenisation).
– Feature Extraction and Image Processing Modules: Handle tasks like downloading models (downloadModel), getting features using CNN (getFeaturesCNN), and image verification (checkIfImage).
– ThreadPool Module: Manages multi-threaded image processing tasks (backend/system/ThreadPool).
– SQL Methods: Database connection and common SQL operations (backend/system/SQLmethods) for interacting with SQLite (backend/database.db).
– Utility Modules: Helper scripts (randomStringGenerator, math.py, etc.) that assist other operations.
- Database:
– SQLite database (backend/database.db) stores image features, metadata, and user feedback.
- External Libraries & Frameworks:
– Vision Transformer (ViT) via Hugging Face Transformers.
– NLP libraries: spaCy, NLTK, and WordNet.
– Other dependencies as declared in requirements.txt and package.json.

##### Relationships and Data Flow
- Frontend-to-Backend:
– The React app sends HTTP requests (e.g., image upload, search query submission, or user feedback) to the backend API.
- Within the Backend:
– Upon receiving a request (for search or image upload), the backend delegates work to specialized modules:
▪ The Retrieval module processes image data.
▪ The Tokenisation/NLP module refines user queries.
▪ The ThreadPool manages parallel image processing.
– These components interact with the SQLite database via SQL methods to store or retrieve image features and metadata.
- Feedback Cycle:
– User interactions (likes, dislikes, textual feedback) result in updates to the database which help refine future retrieval results.

##### Important Architectural Patterns
- Full-stack modular separation: Clear boundaries between the frontend UI and backend processing layers.
- Micro-modular design in the backend: The separation into modules (retrieval, tokenisation, thread pool, etc.) promotes maintainability.
- Use of a thread pool pattern for concurrency in image processing.
- Integration of external services and libraries for feature extraction and NLP.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["UploadArea"]:::frontend
        FE2["SearchBar"]:::frontend
        FE3["ImageGrid"]:::frontend
        FE4["Footer"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE1["Main API Server"]:::backend
        subgraph "Processing Modules"
            RM["Retrieval Module"]:::backendDetail
            TM["Tokenisation Module"]:::backendDetail
            subgraph "Image Processing Modules"
                DM["Download Model"]:::imageProc
                CNN["CNN Feature Extraction"]:::imageProc
                IV["Image Verification"]:::imageProc
                IM["Metadata Extraction"]:::imageProc
                CE["Color Extraction"]:::imageProc
            end
            TP["ThreadPool Module"]:::backendDetail
            SQLM["SQL Methods Module"]:::database
            UT["Utilities"]:::backendDetail
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["SQLite Database"]:::database
    end

    %% External Dependencies
    subgraph "External Dependencies"
        EX1["Vision Transformer (ViT)"]:::external
        EX2["NLP Libraries (spaCy,NLTK,WordNet)"]:::external
    end

    %% Data Flow Connections
    FE1 -->|"HTTP_Request"| BE1
    FE2 -->|"HTTP_Request"| BE1
    FE4 -->|"HTTP_Request"| BE1
    BE1 -->|"Feature_Extraction"| RM
    BE1 -->|"NLP_Processing"| TM
    BE1 -->|"Parallel_Processing"| TP
    RM -->|"Image_Processing"| DM
    DM -->|"Process"| CNN
    CNN -->|"Validation"| IV
    IV -->|"Metadata"| IM
    IM -->|"Color_Extraction"| CE
    RM -->|"SQL_rw"| SQLM
    TM -->|"SQL_rw"| SQLM
    TP -->|"SQL_rw"| SQLM
    SQLM -->|"DB_Write_Read"| DB
    DB -->|"DB_Response"| SQLM
    SQLM -->|"Return_Data"| BE1
    BE1 -->|"Return_Results"| FE3
    RM <-->|"Helper_Functions"| UT
    TM <-->|"Helper_Functions"| UT
    EX1 -->|"Supports_FeatureExtraction"| RM
    EX2 -->|"Supports_NLP"| TM

    %% Click Events
    click FE1 "https://github.com/aniike-t/content-based-image-retrieval/blob/master/frontend/CBIR_Frontend/src/components/UploadArea.jsx"
    click FE2 "https://github.com/aniike-t/content-based-image-retrieval/blob/master/frontend/CBIR_Frontend/src/components/SearchBar.jsx"
    click FE3 "https://github.com/aniike-t/content-based-image-retrieval/blob/master/frontend/CBIR_Frontend/src/components/ImageGrid.jsx"
    click FE4 "https://github.com/aniike-t/content-based-image-retrieval/blob/master/frontend/CBIR_Frontend/src/components/Footer.jsx"
    click BE1 "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/main.py"
    click RM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/Retrieval/RetrieveAlgo.py"
    click TM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/tokenisation/SQLqueryGenerator.py"
    click TM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/tokenisation/SentenceConv.py"
    click TM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/tokenisation/wordnetExtraction.py"
    click DM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/methods/downloadModel/downloadmodel.py"
    click CNN "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/methods/getFeaturesCNN.py"
    click IV "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/utils/checkIfImage.py"
    click IM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/methods/getMetadata.py"
    click CE "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/methods/getColors.py"
    click TP "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/ThreadPool/ImageProcessorManager.py"
    click TP "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/ThreadPool/threads.py"
    click SQLM "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/SQLmethods/connectDB.py"
    click UT "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/utils/math.py"
    click UT "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/system/utils/randomStringGenerator.py"
    click DB "https://github.com/aniike-t/content-based-image-retrieval/blob/master/backend/database.db"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backendDetail fill:#ccf,stroke:#333,stroke-width:2px;
    classDef imageProc fill:#cfc,stroke:#333,stroke-width:2px;
    classDef database fill:#ff9,stroke:#333,stroke-width:2px;
    classDef external fill:#fcf,stroke:#333,stroke-width:2px;
```
