# notmeher/memory-based-ai-chatbot-with-gpt architecture

> Architecture diagram of the GitHub repository notmeher/memory-based-ai-chatbot-with-gpt, 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/notmeher/memory-based-ai-chatbot-with-gpt
- Repository: https://github.com/notmeher/memory-based-ai-chatbot-with-gpt

## Overview

##### Main Components
- User Interface: This is the Streamlit app (app.py) that acts as the front end where users can log in, ask questions, and view past conversations.
- AI Engine / Agent: The agent.py file likely implements the core logic for communicating with OpenAI’s API (gpt-4 or gpt-3.5-turbo), processing user queries, and formatting responses.
- Conversation Memory & Storage: ChromaDB is used for storing user messages, metadata (role, timestamp, conversation IDs), and managing persistent conversation histories.
- Authentication Module: The application handles user sign-up/login, where user passwords are securely hashed (using SHA-256) and verified during authentication.

##### Relationships and Interactions
- The UI layer (Streamlit front end) collects user input and displays chat history.
- The agent or backend component (agent.py) processes user requests, calls the OpenAI API for generating responses, and interacts with ChromaDB for storing and retrieving conversation data.
- The authentication process verifies user credentials (after hashing) before allowing access to the chat and conversation history.
- External Services: The OpenAI API serves as an external service to provide GPT model responses.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separate the presentation layer (Streamlit app) from the business logic (agent module) and data access (ChromaDB interactions).
- Integration with External APIs: Clearly show the connection between the business logic and OpenAI’s API.
- Persistent Data Storage: Emphasize the role of ChromaDB to index and store conversations securely.
- Environment-based Configuration: Utilize .env for managing sensitive API keys and configuration variables.

##### Relevant Technologies & Frameworks
- Streamlit for building the web interface.
- Python as the core programming language.
- ChromaDB as the persistent storage solution.
- OpenAI API for processing input and generating responses.
- dotenv for environment variable management.
- Security (SHA-256 hashing for passwords) in the authentication process.

##### Elements
- Clear labels for each component (e.g., “Streamlit UI”, “Agent Module”, “Authentication Service”, “ChromaDB”, “OpenAI API”).
- Notations on important processes (like user authentication, conversation persistence, and API integrations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    user("User")
    
    subgraph "Presentation Layer"
        streamlit("Streamlit UI")
        auth("Auth Service")
    end

    subgraph "Business Logic"
        agent("Agent Module")
    end

    subgraph "Data & External Services"
        openai("OpenAI API")
        chroma("ChromaDB")
    end

    subgraph "Configuration"
        env(".env")
        req("requirements.txt")
    end

    %% Data Flow
    user -->|"input"| streamlit
    streamlit -->|"login"| auth
    streamlit -->|"sendQuery"| agent
    auth -->|"verifyCreds"| agent
    agent -->|"apiCall"| openai
    agent -->|"storeRetrieve"| chroma
    agent -->|"response"| streamlit
    env -->|"configures"| agent
    env -->|"configures"| streamlit
    req -->|"managesDeps"| streamlit
    req -->|"managesDeps"| agent

    %% Click Events
    click streamlit "https://github.com/notmeher/memory-based-ai-chatbot-with-gpt/blob/main/app.py"
    click agent "https://github.com/notmeher/memory-based-ai-chatbot-with-gpt/blob/main/agent.py"
    click chroma "https://github.com/notmeher/memory-based-ai-chatbot-with-gpt/tree/main/chroma_db/"
    click env "https://github.com/notmeher/memory-based-ai-chatbot-with-gpt/blob/main/.env"
    click req "https://github.com/notmeher/memory-based-ai-chatbot-with-gpt/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0077b6,stroke-width:2px;
    classDef backend fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#f1c232,stroke-width:2px;
    classDef db fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    class streamlit,auth frontend;
    class agent backend;
    class openai external;
    class chroma db;
    class env,req config;
```
