# asjaytee/pb-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/asjaytee/pb-chatbot
- Repository: https://github.com/asjaytee/pb-chatbot

## Overview

##### Project’s Core Purpose and Components
- Purpose: A chatbot that handles user queries using a custom RAG system (focusing on embedding questions, not answers) combined with an intelligent therapist matching module.
- Main components include:
- Frontend Interface: A Streamlit-based demo (demo.py) as the user interface to interact with the chatbot.
- Backend Logic: The main application (main.py) which coordinates between various systems.
- RAG System: Implemented in systems/RAG.py, this module orchestrates the optimized retrieval of Q&A data.
- Therapist Matching & Filtering: Located in systems/filtering_agent.py, systems/therapists.py, and systems/refer.py, this part handles multi-factor filtering and matching of client preferences.
- Cost & Efficiency Management: In systems/cost.py, covering calculations and cost-efficiency measures.
- Data Management: The systems/data folder contains example datasets (FAQs and therapists), ensuring separation of data.
- Model and Vector Store: Within systems/model (especially model.py) and systems/vectorstore.py, which likely deal with embedding generation (using cosine similarity, etc.) and storage/retrieval of these embeddings.
- Additional Utility & Testing: Files like test.py provide unit or integration checks, and demo.py offers a quick demonstration.

##### File Structure for Architectural Relationships
- Directory Significance:
- The “systems” directory encapsulates the business logic split into several core components (RAG, filtering, cost, model, vector store).
- The “resources” directory houses assets (logos, demo images) used by the frontend.
- Files like .env.example, requirements.txt, and devcontainer configurations set up the environment and dependencies.
- Interaction Patterns:
- The main file (main.py) likely acts as the entry point for backend operations.
- The Streamlit UI (demo.py) interacts with the backend modules.
- The RAG system works by processing and embedding only the question components, routed through model and vector store components—this emphasizes the separation of concerns in data handling.
- Therapist matching modules communicate with user query data and stored therapist profiles (JSON files in systems/data) to deliver recommendations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        UI["Streamlit UI (demo.py)"]:::frontend
    end

    subgraph "Backend Layer"
        APP["Main Application (main.py)"]:::backend
        COST["Cost Management (systems/cost.py)"]:::backend
    end

    subgraph "RAG Subsystem"
        RAG["RAG Engine (systems/RAG.py)"]:::rag
        MODEL["Model (systems/model/model.py)"]:::rag
        VECTOR["Vector Store (systems/vectorstore.py)"]:::rag
    end

    subgraph "Therapist Matching"
        FILTER["Filtering Agent (systems/filtering_agent.py)"]:::match
        MATCHER["Therapist Matcher (systems/therapists.py)"]:::match
        REF["Reference Module (systems/refer.py)"]:::match
    end

    subgraph "Data Management"
        DATA["Data Store (systems/data)"]:::data
    end

    %% Connections
    UI -->|"sends_query"| APP
    APP -->|"processes_query"| RAG
    RAG -->|"generates_embedding"| MODEL
    RAG -->|"retrieves_vector"| VECTOR
    APP -->|"initiates_matching"| FILTER
    FILTER -->|"filters_client"| MATCHER
    FILTER -->|"refers_client"| REF
    APP -->|"calculates_cost"| COST
    FILTER -->|"accesses_data"| DATA
    MATCHER -->|"accesses_data"| DATA
    REF -->|"accesses_data"| DATA

    %% Click Events
    click UI "https://github.com/asjaytee/pb-chatbot/blob/main/demo.py"
    click APP "https://github.com/asjaytee/pb-chatbot/blob/main/main.py"
    click COST "https://github.com/asjaytee/pb-chatbot/blob/main/systems/cost.py"
    click RAG "https://github.com/asjaytee/pb-chatbot/blob/main/systems/RAG.py"
    click MODEL "https://github.com/asjaytee/pb-chatbot/blob/main/systems/model/model.py"
    click VECTOR "https://github.com/asjaytee/pb-chatbot/blob/main/systems/vectorstore.py"
    click FILTER "https://github.com/asjaytee/pb-chatbot/blob/main/systems/filtering_agent.py"
    click MATCHER "https://github.com/asjaytee/pb-chatbot/blob/main/systems/therapists.py"
    click REF "https://github.com/asjaytee/pb-chatbot/blob/main/systems/refer.py"
    click DATA "https://github.com/asjaytee/pb-chatbot/tree/main/systems/data"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef rag fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef match fill:#ffc0cb,stroke:#000,stroke-width:2px;
    classDef data fill:#ffcc99,stroke:#000,stroke-width:2px;
```
