# alrashid-alkiswane/chatbot-for-dental-clinic architecture

> Architecture diagram of the GitHub repository alrashid-alkiswane/chatbot-for-dental-clinic, 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/alrashid-alkiswane/chatbot-for-dental-clinic
- Repository: https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic

## Overview

##### Main Components
- Entry Point & Environment Configuration:
- main.py: Acts as the application launcher.
- .env.example: Environment variables handling.
- API Layer & Frontend:
- src/api: Contains RESTful endpoints that serve both API interactions and the Web UI.
○ chatbot_api.py: Provides routes for handling chat requests.
○ templates (chat.html) and static (styles.css): Serve the web frontend.
- Chatbot Pipeline:
- src/pipeline_chatbot/chatbot_pipeline.py: Orchestrates the conversation flow and overall pipeline.
- Retrieval Augmented Generation (RAG) Module:
- src/RetrievalAugmentedGeneration: Implements document retrieval and generative responses.
○ generative.py: Handles language model–based response generation.
○ retrieve_relevant_documents.py: Manages the logic for fetching relevant documentation.
- Models:
- src/models: Houses different language models and embedding models.
○ embedding_model.py: Feature extraction from text.
○ llm_huggingface.py & openai_model.py: Interfaces for different LLM implementations.
- Data Operations & Database Integration:
- src/data_operation: Functions for ingesting data to and retrieving data from a database.
○ ingest_database.py, pull_from_database.py: Manage CRUD operations.
○ combine_dataframe_with_text.py, unzip_file.py: Pre-processing and data handling.
- Auxiliary & Support Components:
- src/cash: Likely provides caching support.
- src/configs: Configuration modules.
- src/save_pydantic: Implements history or logging functions using Pydantic models.
- src/utils: Utility modules for generic operations (like get_size and monitoring functions).
- Additional Resources:
- assets: Stores images (e.g., for documentation) and potential other static resources (like the dental clinic image).

##### Relationships and Interactions
● The User Interface (UI)/Client sends chat requests via the API (src/api) to main.py.
● The API endpoints (chatbot_api.py) relay these requests to the Chatbot Pipeline, which is orchestrated by src/pipeline_chatbot/chatbot_pipeline.py.
● The chatbot pipeline leverages two key subcomponents:
– The Retrieval Augmented Generation module (src/RetrievalAugmentedGeneration) which retrieves documents and uses language models to generate responses.
– The Models module (src/models) provides the underlying LLM and embedding functionalities (using either Hugging Face or OpenAI based implementations).
● Data Operations (ingest_database.py, pull_from_database.py in src/data_operation) support the pipeline by managing patient information and historical interactions.
● Caching (src/cash) and Logging/History (src/save_pydantic/history_chat.py) enhance performance and allow tracking/logging of conversations.
● Utility functions (src/utils) support monitoring and other general system checks.
● Config modules (config/pipeline_config.yaml and src/configs) centrally manage settings, parameters, and secrets (with .env providing environment variable overrides).

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly separated layers for presentation (frontend/API), business logic (pipeline, generative modules), and data handling (database operations).
- Modularization: Each major functionality is isolated into its own subdirectory (RAG, models, data_operation, etc.), allowing independent evolution and testing.
- Dependency Injection & Configuration Management: Use of config files and environment settings to manage dependencies and runtime parameters.
- Extensibility: The design supports plugging in different machine learning models (e.g., Huggingface, OpenAI) and easily modifying data ingestion or retrieval strategies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["User/Browser"]:::client

    %% Entry Point & Environment Configuration
    subgraph "Entry Point & Env Config"
        main_py["main.py"]:::entry
        env_example[".env.example"]:::entry
    end

    %% API Layer & Frontend
    subgraph "API Layer & Frontend"
        api_chat["chatbot_api.py"]:::api
        chat_template["chat.html"]:::api
        styles_css["styles.css"]:::api
    end

    %% Chatbot Pipeline
    subgraph "Chatbot Pipeline"
        chatbot_pipeline["Chatbot Pipeline"]:::pipeline
    end

    %% Retrieval Augmented Generation (RAG) Module
    subgraph "RAG Module"
        generative["Generative Response (generative.py)"]:::rag
        doc_retrieval["Document Retrieval (retrieve_relevant_documents.py)"]:::rag
    end

    %% Models
    subgraph "Models"
        embedding_model["Embedding Model (embedding_model.py)"]:::models
        hf_llm["Huggingface LLM (llm_huggingface.py)"]:::models
        openai_model["OpenAI Model (openai_model.py)"]:::models
    end

    %% Data Operations & Database Integration
    subgraph "Data Operations"
        data_ingest["Data Ingestion (ingest_database.py)"]:::dataops
        data_pull["Data Retrieval (pull_from_database.py)"]:::dataops
        data_preprocess["Data Preprocessing (combine_dataframe_with_text.py)"]:::dataops
        file_handling["File Handling (unzip_file.py)"]:::dataops
    end

    %% Auxiliary & Support Components
    subgraph "Auxiliary & Support"
        caching["Caching"]:::support
        config_dir["Config Modules (src/configs)"]:::support
        pipeline_config["Pipeline Config (pipeline_config.yaml)"]:::support
        logging["Logging/History (history_chat.py)"]:::support
        utilities["Utilities (src/utils)"]:::support
    end

    %% Connections
    Client -->|"request"| api_chat
    main_py -->|"launches"| api_chat
    api_chat -->|"receives chat"| chatbot_pipeline
    chatbot_pipeline -->|"orchestrates chat"| generative
    chatbot_pipeline -->|"orchestrates chat"| doc_retrieval
    chatbot_pipeline -->|"calls model"| embedding_model
    chatbot_pipeline -->|"calls model"| hf_llm
    chatbot_pipeline -->|"calls model"| openai_model
    chatbot_pipeline -->|"data operations"| data_ingest
    chatbot_pipeline -->|"data operations"| data_pull
    chatbot_pipeline -->|"data operations"| data_preprocess
    chatbot_pipeline -->|"data operations"| file_handling
    chatbot_pipeline -->|"supports"| caching
    chatbot_pipeline -->|"logs"| logging
    chatbot_pipeline -->|"monitors"| utilities
    config_dir ---|"configures"| api_chat
    config_dir ---|"configures"| chatbot_pipeline
    config_dir ---|"configures"| data_ingest
    pipeline_config ---|"configures"| chatbot_pipeline

    %% Styles
    classDef entry fill:#e3f2fd,stroke:#2196f3,stroke-width:2px;
    classDef api fill:#fce4ec,stroke:#e91e63,stroke-width:2px;
    classDef pipeline fill:#e8f5e9,stroke:#4caf50,stroke-width:2px;
    classDef rag fill:#fff3e0,stroke:#ff9800,stroke-width:2px;
    classDef models fill:#f3e5f5,stroke:#9c27b0,stroke-width:2px;
    classDef dataops fill:#ede7f6,stroke:#673ab7,stroke-width:2px;
    classDef support fill:#f3f3f3,stroke:#9e9e9e,stroke-width:2px;
    classDef client fill:#fffde7,stroke:#fdd835,stroke-width:2px;

    %% Click Events
    click main_py "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/main.py"
    click env_example "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/.env.example"
    click api_chat "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/api/chatbot_api.py"
    click chat_template "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/api/templates/chat.html"
    click styles_css "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/api/static/styles.css"
    click chatbot_pipeline "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/pipeline_chatbot/chatbot_pipeline.py"
    click generative "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/RetrievalAugmentedGeneration/generative.py"
    click doc_retrieval "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/RetrievalAugmentedGeneration/retrieve_relevant_documents.py"
    click embedding_model "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/models/embedding_model.py"
    click hf_llm "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/models/llm_huggingface.py"
    click openai_model "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/models/openai_model.py"
    click data_ingest "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/data_operation/ingest_database.py"
    click data_pull "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/data_operation/pull_from_database.py"
    click data_preprocess "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/data_operation/combine_dataframe_with_text.py"
    click file_handling "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/data_operation/unzip_file.py"
    click caching "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/tree/main/src/cash"
    click config_dir "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/tree/main/src/configs"
    click pipeline_config "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/config/pipeline_config.yaml"
    click logging "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/blob/main/src/save_pydantic/history_chat.py"
    click utilities "https://github.com/alrashid-alkiswane/chatbot-for-dental-clinic/tree/main/src/utils"
```
