# sahanasankar13/abby_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sahanasankar13/abby_chatbot
- Repository: https://github.com/sahanasankar13/abby_chatbot

## Overview

##### Main Components
- API/Web Server: The entry point is app.py, which initializes your FastAPI application. This component handles incoming HTTP requests, routing, and ties together business logic.
- Chatbot Core Logic: Located in the chatbot/ directory, this contains various modules for processing conversations (e.g., conversation_manager.py, preprocessor.py, response_composer.py) and integrating with external services (e.g., gpt_integration.py, citation_manager.py, policy_handler.py). Each module represents a distinct responsibility in handling language processing, classification, and response generation.
- Machine Learning Models: The models/ directory encapsulates the data structures and algorithms that power feedback, metric calculations, user data handling, etc.
- Configuration & Environment Handling: The config/ directory includes model_config.py, server configuration files (e.g., gunicorn.conf.py), and multiple dependency and environment configuration files (such as .env.example and requirements files). This area governs runtime behavior and deployment settings.
- Data Management: The data/ directory holds training data, conversation transcripts, and supplementary files (e.g., FAQs, clinic data). These are vital for the chatbot’s knowledge base.
- Deployment Pipeline: The deployment/ directory contains AWS CloudFormation templates, deployment scripts, and related policies. It’s where the infrastructure as code is defined for deploying the chatbot on AWS.
- Frontend Components: The templates/ and static/ directories support the user interface aspect, where HTML, CSS, and JavaScript (including chat.js, maps.js, etc.) offer the client-side interface.
- Utility & Testing Components: Directories like utils/, scripts/, and tests/ provide supplemental functionality, handling scripts for model management, text processing utilities, and comprehensive test suites.

##### Relationships and Interactions
- User Interaction: Start at the client (web browser or API consumer) which makes requests. The frontend (HTML & JS) interacts with the API (app.py).
- API Layer: The FastAPI application processes the request and delegates tasks to the chatbot core logic.
- Chatbot Engine: Inside chatbot/, individual modules work collaboratively to preprocess input, classify queries, manage conversation state, and generate responses possibly via integrations like GPT or policy APIs.
- Data & Model Handling: The chatbot interacts with models in the models/ directory to push/pop data for feedback, metrics, and user management. It also consults the data/ repository for static data and NLTK data (nltk_data/) for language processing.
- Configuration & Deployment: The configurations in config/ inform the running environment of the API and server. Meanwhile, the deployment/ folder defines how the code and infrastructure are pushed to AWS, including CloudFormation templates, Codedeploy policies, scripts for managing application state (start, stop, health check), etc.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into distinct directories (chatbot, config, models, utils) indicates a clear separation of concerns. Each module or service has its own responsibility.
- API-Driven Architecture: The FastAPI app acts as the orchestration layer. This design facilitates scalability (possibly via microservices or standalone modules if needed) and testing.
- Extensibility: The breakdown of the chatbot logic into smaller, manageable units (e.g., response composers, policy handlers) makes it easy to extend functionality.
- Deployment as Code: With CloudFormation, Terraform (mentioned in README), and CI/CD setup in .github/workflows, the project follows infrastructure-as-code and automated deployment best practices.

##### Relevant Technologies and Frameworks
- Python 3.8+ as the main language.
- FastAPI for web serving and asynchronous request handling.
- NLTK for natural language processing (evident from the nltk_data directory).
- ML libraries and custom modeling in the models/ directory.
- AWS tools for deployment (CloudFormation, AWS CLI).
- Standard web technologies (HTML, CSS, JavaScript) for frontend presentation.

##### Final Advice
- Be detailed, ensuring each of the key modules (even submodules in the chatbot directory) is briefly represented.
- Don’t shy away from adding annotations or legends to explain technology stacks or interdependencies.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Layer
    subgraph "User Layer"
        Client["Client (Browser)"]:::client
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        Templates["HTML Templates (templates/)"]:::frontend
        Static["Static Assets (static/)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["FastAPI Server (app.py)"]:::backend
        Chatbot["Chatbot Core Logic (chatbot/)"]:::backend
        ML["ML Models (models/)"]:::backend
        Data["Data Management (data/)"]:::data
        NLTK["NLTK Data (nltk_data/)"]:::data
    end

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        Config["Configuration Manager (config/)"]:::config
        Deploy["Deployment Pipeline (deployment/)"]:::deployment
    end

    %% Development & Utilities
    subgraph "Development & Utilities"
        Util["Utilities & Testing (utils/, scripts/, tests/)"]:::util
    end

    %% Connections
    Client -->|"request"| API
    API -->|"handles"| Chatbot
    Chatbot -->|"uses"| ML
    Chatbot -->|"queries"| Data
    Chatbot -->|"accesses"| NLTK
    API -->|"renders"| Templates
    API -->|"serves"| Static
    Config -->|"configures"| API
    Deploy -->|"deploys"| API
    Util -->|"supports"| Chatbot

    %% Styles
    classDef client fill:#CFD8DC,stroke:#607D8B,stroke-width:2px, color:#000000
    classDef frontend fill:#B3E5FC,stroke:#039BE5,stroke-width:2px, color:#000000
    classDef backend fill:#C8E6C9,stroke:#388E3C,stroke-width:2px, color:#000000
    classDef data fill:#F8BBD0,stroke:#C2185B,stroke-width:2px, color:#000000
    classDef config fill:#FFE082,stroke:#FBC02D,stroke-width:2px, color:#000000
    classDef deployment fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px, color:#000000
    classDef util fill:#FFCCBC,stroke:#E64A19,stroke-width:2px, color:#000000

    %% Click Events
    click API "https://github.com/sahanasankar13/abby_chatbot/blob/main/app.py"
    click Chatbot "https://github.com/sahanasankar13/abby_chatbot/tree/main/chatbot/"
    click ML "https://github.com/sahanasankar13/abby_chatbot/tree/main/models/"
    click Data "https://github.com/sahanasankar13/abby_chatbot/tree/main/data/"
    click NLTK "https://github.com/sahanasankar13/abby_chatbot/tree/main/nltk_data/"
    click Config "https://github.com/sahanasankar13/abby_chatbot/tree/main/config/"
    click Deploy "https://github.com/sahanasankar13/abby_chatbot/tree/main/deployment/"
    click Templates "https://github.com/sahanasankar13/abby_chatbot/tree/main/templates/"
    click Static "https://github.com/sahanasankar13/abby_chatbot/tree/main/static/"
    click Util "https://github.com/sahanasankar13/abby_chatbot/tree/main/utils/"
```
