# lalithasree-2599/pricewise_ai architecture

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

- Interactive diagram: https://gitdiagram.com/lalithasree-2599/pricewise_ai
- Repository: https://github.com/lalithasree-2599/pricewise_ai

## Overview

##### Project type and purpose
- This is a specialized full-stack data/AI assistant for retail pricing, implemented as a Streamlit front end coupled with a Python-based backend “pricing agent.” It uses RAG (Retrieval-Augmented Generation) with ChromaDB + OpenAI embeddings, enforces semantic guardrails, and implements a risk-based approval workflow.

##### File structure
- Top level:
- context_notepads – reference PDFs/txts (design notes, guides)
- data – the raw product CSV and persisted Chroma SQLite vector store
- iteration_1 – the working code for v1:
– streamlit_app.py (UI entry point)
– requirements.txt
– src/ – core modules (data_loader, vector_store, simple_retriever, prompts, pricing_agent, guardrails, models)
– hybrid_guardrails_example.py & sample prompts
- Configuration files: .gitignore, .python-version, README.md
- Patterns: single-process app, modular backend components, clear data-vs-logic separation.

##### Key architecture details from README
- RAG pipeline: ChromaDB + OpenAI for retrieval & embeddings
- Hybrid guardrails: keyword + semantic checks
- Approval workflow: escalation tiers (Manager → Director → C-Level) based on price/risk thresholds
- Elasticity-based revenue optimization
- Tech stack: Python, LangChain, OpenAI GPT-4o, Streamlit, ChromaDB

##### Main components & their interactions
a. Frontend (Streamlit UI)
- Accepts user queries, displays recommendations & dashboards
- Triggers download/export
b. Pricing Agent Core
- Data Loader – ingests product CSV
- Vector Store – manages ChromaDB interactions
- Retriever – executes similarity searches via embeddings
- Prompts – templates for LLM calls
- LLM Service – OpenAI API → embeddings & completions
- Models – price elasticity & revenue calculations
c. Guardrails Layer
- Keyword filters (fast checks)
- Semantic validator (LLM-based fraud/topic checks)
- Configuration thresholds (min price, max change, etc.)
d. Approval Workflow
- Risk assessment → tier determination
- Escalation paths (Manager, Director, C-suite)
- Hook for human sign-off before final output
e. Data Persistence
- ChromaDB (SQLite) for vector store
- Optional CSV export
f. External Dependencies
- OpenAI API
- Host environment (Streamlit server)

##### Architectural patterns & design principles
- Modular layering: UI → service layer (pricing_agent) → persistence/third-party
- Separation of concerns: retrieval, modeling, guardrails, and approval decoupled
- Configuration-driven guardrails (inject thresholds via dict)
- RAG pattern: combine embeddings store + LLM for retrieval & generation

##### Final recommendations
- Be granular: break the “pricing_agent” into its sub-modules to show clear responsibilities
- Every component has a clear label, and group related modules within containers for readability

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        UI["Streamlit UI"]:::internal
    end

    subgraph "Pricing Agent Service"
        DL["Data Loader"]:::internal
        VS["Vector Store"]:::internal
        RET["Retriever"]:::internal
        P["Prompt Templates"]:::internal
        PA["Pricing Agent Core"]:::internal
        M["Models"]:::internal
    end

    subgraph "Guardrails Layer"
        KG["Keyword Guardrails"]:::control
        SG["Semantic Guardrails"]:::control
    end

    subgraph "Approval Workflow"
        AR["Risk Assessment"]:::control
        TIER["Escalation Tiers"]:::control
        HU["Human Sign-Off"]:::control
    end

    subgraph "Data Persistence"
        CSV["Raw Product CSV"]:::external
        CDB["ChromaDB Store"]:::external
    end

    OpenAI["OpenAI API"]:::external

    UI -->|"user query"| PA
    PA -->|"load data"| DL
    DL -->|"raw data"| CSV
    PA -->|"vector query"| RET
    RET -->|"query store"| VS
    VS -->|"SQL operations"| CDB
    RET -->|"embeddings request"| OpenAI
    PA -->|"LLM completion"| OpenAI
    PA -->|"generate price rec"| UI
    PA -->|"invoke prompts"| P
    PA -->|"apply models"| M
    PA -->|"guardrail request"| KG
    KG -->|"keyword pass"| SG
    SG -->|"semantic verdict"| AR
    AR -->|"risk tier"| TIER
    TIER -->|"needs approval"| HU
    HU -->|"approved rec"| UI

    click UI "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/streamlit_app.py"
    click DL "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/data_loader.py"
    click VS "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/vector_store.py"
    click RET "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/simple_retriever.py"
    click P "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/prompts.py"
    click PA "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/pricing_agent.py"
    click M "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/models.py"
    click SG "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/src/semantic_guardrails.py"
    click HybridExample "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/hybrid_guardrails_example.py"
    click GuardrailsDoc "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/SEMANTIC_GUARDRAILS_GUIDE.md"
    click PromptExamples "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/PROMPTS_EXAMPLE.md"
    click CSV "https://github.com/lalithasree-2599/pricewise_ai/blob/main/data/apparel_pricing_data.csv"
    click CDB "https://github.com/lalithasree-2599/pricewise_ai/blob/main/data/chroma_db/chroma.sqlite3"
    click IterCDB "https://github.com/lalithasree-2599/pricewise_ai/blob/main/iteration_1/data/chroma_db/chroma.sqlite3"
    click README "https://github.com/lalithasree-2599/pricewise_ai/blob/main/README.md"
    click Context "https://github.com/lalithasree-2599/pricewise_ai/tree/main/context_notepads/"

    classDef internal fill:#bbefff,stroke:#333,stroke-width:1px
    classDef external fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef control fill:#ffd699,stroke:#333,stroke-width:1px
```
