# aprendeingenia/shopping-ai architecture

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

- Interactive diagram: https://gitdiagram.com/aprendeingenia/shopping-ai
- Repository: https://github.com/aprendeingenia/shopping-ai

## Overview

##### Project Type and Purpose
- This is an edge‐oriented AI inference application (“Shopping-AI”) written in Python that performs real-time object detection of shopping items (fruits, vegetables, books, peripherals, etc.).
- Purpose: download a pre-trained model from Hugging Face, load it (PyTorch or ONNX), capture or ingest input frames/images, run inference, and pass detected items to a simple “store” business logic layer.

##### File Structure Analysis
Top-level
- README.md – project overview and instructions
- python_files/
– .gitignore
– get_pytorch_models.bat / get_onnx_models.bat (model-download scripts)
– requirements.txt
– ShoppingIA.py (inference module: load model, preprocess, detect)
– Tienda.py (business logic: manage detected items, pricing, “shopping cart”)
– main.py (application orchestrator: calls downloader, inference, business logic)

##### README Insights
- Emphasizes two supported runtimes: PyTorch and ONNX.
- Real-time, resource-constrained environments (e.g., peripheral devices).
- Uses advanced deep-learning frameworks.
- No frontend server or UI beyond CLI or local display.

##### Main Components
a. External Model Repository (Hugging Face)
b. Model Downloader Scripts (.bat files)
c. Local Model Storage (folder on disk)
d. Inference Module (ShoppingIA.py)
– Subcomponents:
- Model Loader (PyTorch / ONNX runtime)
- Preprocessor (resize, normalize)
- Detector (forward pass + postprocess)
e. Business Logic Module (Tienda.py)
– Shopping cart management, item lookup, pricing
f. Orchestrator (main.py)
– Initialization, selecting runtime, wiring modules
g. Input Source
– Camera / Video feed / Image input
h. Output Sink
– CLI console / Optional display overlay
i. Dependencies
– PyTorch / ONNX Runtime
– OpenCV or image-capture library
– Other Python libraries (from requirements.txt)

##### Relationships and Data Flow
1) User runs main.py ➔
2) main.py invokes model-download scripts if models not present ➔
3) model files saved to local storage ➔
4) Inference Module loads model ➔
5) Inference Module pulls frames from Input Source ➔
6) Preprocessor transforms frames ➔
7) Detector runs inference ➔
8) Detected items + metadata passed to Business Logic Module ➔
9) Business Logic outputs “shopping cart” summary to Output Sink

##### Architectural Patterns and Design Principles
- Modular layering: downloader, inference, business logic, orchestrator
- Strategy pattern for supporting multiple runtimes (PyTorch vs ONNX)
- Pipeline for data flow: capture ➔ preprocess ➔ infer ➔ postprocess ➔ consume
- Separation of concerns: detection vs shopping‐cart management

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Services
    HF["Hugging Face Model Repo"]:::external

    %% Model Acquisition
    Pbat["get_pytorch_models.bat"]:::compute
    Obat["get_onnx_models.bat"]:::compute

    %% Storage
    Storage[(Local Model Storage)]:::storage

    %% Core Application
    subgraph "Core Application"
        Orch["main.py"]:::compute
        Decision{"Select Runtime\n(PyTorch vs ONNX)"}:::compute
        subgraph "Inference Module"
            InMod["ShoppingIA.py"]:::compute
            Loader["Model Loader\n(PyTorch/ONNX)"]:::compute
            Pre["Preprocessor\n(resize, normalize)"]:::compute
            Det["Detector\n(forward + postprocess)"]:::compute
        end
        BL["Tienda.py\n(Business Logic)"]:::compute
    end

    %% Dependencies
    Req["requirements.txt\n(Dependencies)"]:::storage

    %% I/O
    Input["Camera/Video Feed"]:::io
    Output["CLI Console / Display"]:::io

    %% Project Overview
    README["README.md\n(Project Overview)"]:::storage

    %% Data Flow
    HF -->|download| Pbat
    HF -->|download| Obat
    Pbat -->|save model| Storage
    Obat -->|save model| Storage

    Orch -->|requires models| Storage
    Orch --> Decision
    Decision -->|PyTorch| InMod
    Decision -->|ONNX| InMod
    Orch -->|inject| BL
    Storage -->|model path| InMod

    Input -->|frame stream| Pre
    InMod --> Loader
    Loader --> Pre
    Pre --> Det
    Det -->|inference result| BL
    BL -->|shopping summary| Output

    Orch -->|reads| Req
    Orch -->|reads| README

    %% Click Events
    click Pbat "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/get_pytorch_models.bat"
    click Obat "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/get_onnx_models.bat"
    click InMod "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/ShoppingIA.py"
    click BL "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/Tienda.py"
    click Orch "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/main.py"
    click Req "https://github.com/aprendeingenia/shopping-ai/blob/main/python_files/requirements.txt"
    click README "https://github.com/aprendeingenia/shopping-ai/blob/main/README.md"

    %% Styles
    classDef external fill:#DDEBF7,stroke:#6C8EBF,stroke-width:1px
    classDef storage fill:#F2F2F2,stroke:#CCCCCC,stroke-width:1px
    classDef compute fill:#E2EFDA,stroke:#548235,stroke-width:1px
    classDef io fill:#FFF2CC,stroke:#BF9000,stroke-width:1px
```
