# lrigaux/technical_test_tby architecture

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

- Interactive diagram: https://gitdiagram.com/lrigaux/technical_test_tby
- Repository: https://github.com/lrigaux/technical_test_tby

## Overview

##### Project type and purpose
- This is a full-stack, single-page web application built with Streamlit.
- Its purpose is to ingest raw product data (CSV), clean and analyze it, enhance product descriptions with a generative AI (Google AI API via LangChain/LangGraph), harmonize images, and store history locally in DuckDB.

##### File structure
- Top level
– app.py: Streamlit entry point (UI layer + orchestration trigger)
– data/: raw inputs (CSV prompts), outputs (processed_images), DB file
– requirements.txt, .devcontainer/: environment config
- src/
– config.py: global paths, default model and image options
– data_handler.py: CSV loading, pandas-based cleaning/prep
– db_handler.py: DuckDB persistence and history queries
– graph_workflow.py: LangGraph workflow definition (map, generate, enhance, image, aggregate, persist)
– llm_models.py: initializes Google AI client via LangChain
– image_processor.py: optional image-background removal, resizing
– utils.py: helper functions (HTML cleanup, etc.)

##### README for additional insights
- Workflow steps are explicitly listed (map_selected, gen_titles, enhance_desc, proc_images, aggregate_results, persist_db).
- Key external dependencies: Streamlit, Pandas, Plotly Express, LangChain, LangGraph, Google AI, Pillow, Rembg, DuckDB.

a. Main components
1. Streamlit UI layer (app.py + sidebar configuration)
2. Data Ingestion & Cleaning (data_handler module + user upload widget)
3. Workflow Orchestrator (graph_workflow module running LangGraph)
4. LLM Service (llm_models module → Google AI API)
5. Image Processing Service (image_processor module)
6. Persistence Layer (db_handler module → DuckDB local file)
7. File System (data/ folder for CSVs, prompts, images)
b. Relationships and interactions
– UI triggers upload → Data Ingestion
– Cleaned data passed to Workflow Orchestrator
– Orchestrator dispatches to LLM Service and Image Processor in parallel or sequence
– Aggregated results returned to UI and forwarded to Persistence Layer
– Persistence Layer writes to DuckDB and File System (processed_images)
– UI can query Persistence Layer for history
c. Architectural patterns and principles
– Modular layered architecture: UI / Application Logic / Services / Persistence
– Pipeline/workflow pattern implemented via LangGraph (directed acyclic graph of tasks)
– Separation of concerns: each module handles one responsibility
– Local-first data storage (DuckDB) and stateless service calls to Google AI
d. Relevant technologies and libraries
– Frontend: Streamlit
– Data analysis & viz: Pandas, Plotly Express
– Workflow orchestration: LangChain + LangGraph
– LLM integration: langchain-google-genai (Google AI Gemini)
– Image processing: Pillow, Rembg
– Persistence: DuckDB
– Utility: Python 3.12

– UI (blue),
– Processing services (green),
– External APIs (orange),
– Persistence (gray)

##### Detail without over-fragmenting
- Key modules and flows listed above
- Avoid splitting modules beyond their single responsibility

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        App["Streamlit UI"]:::ui
        Config["Configuration"]:::service
    end

    %% Processing Layer
    subgraph "Processing Layer"
        DataHandler["DataHandler"]:::service
        GraphWorkflow["GraphWorkflow"]:::service
        ImageProcessor["ImageProcessor"]:::service
        LLMService["LLM Service"]:::external
        GoogleAI["Google AI API"]:::external
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DBHandler["DB Handler"]:::persistence
        DBFile[(DuckDB File)]:::persistence
        FileSystem["File System"]:::persistence
    end

    %% Data Flow
    App -->|"upload CSV"| DataHandler
    DataHandler -->|"cleaned DataFrame"| GraphWorkflow
    GraphWorkflow -->|"LLM request"| LLMService
    LLMService -->|"API call"| GoogleAI
    GoogleAI -->|"response"| LLMService
    LLMService -->|"titles/descriptions"| GraphWorkflow
    GraphWorkflow -->|"image tasks"| ImageProcessor
    ImageProcessor -->|"processed images"| FileSystem
    GraphWorkflow -->|"aggregate results"| App
    GraphWorkflow -->|"persist data"| DBHandler
    DBHandler -->|"write history"| DBFile
    DBHandler -->|"store files"| FileSystem
    App -->|"query history"| DBHandler

    %% Click Events
    click App "https://github.com/lrigaux/technical_test_tby/blob/master/app.py"
    click Config "https://github.com/lrigaux/technical_test_tby/blob/master/src/config.py"
    click DataHandler "https://github.com/lrigaux/technical_test_tby/blob/master/src/data_handler.py"
    click GraphWorkflow "https://github.com/lrigaux/technical_test_tby/blob/master/src/graph_workflow.py"
    click LLMService "https://github.com/lrigaux/technical_test_tby/blob/master/src/llm_models.py"
    click ImageProcessor "https://github.com/lrigaux/technical_test_tby/blob/master/src/image_processor.py"
    click DBHandler "https://github.com/lrigaux/technical_test_tby/blob/master/src/db_handler.py"
    click FileSystem "https://github.com/lrigaux/technical_test_tby/tree/master/data/"

    %% Styles
    classDef ui fill:#CCE5FF,stroke:#333,stroke-width:1px
    classDef service fill:#CCFFCC,stroke:#333,stroke-width:1px
    classDef external fill:#FFD699,stroke:#333,stroke-width:1px
    classDef persistence fill:#E0E0E0,stroke:#333,stroke-width:1px
```
