# nasa-petal/bidara-deep-chat architecture

> Architecture diagram of the GitHub repository nasa-petal/bidara-deep-chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nasa-petal/bidara-deep-chat
- Repository: https://github.com/nasa-petal/bidara-deep-chat

## Overview

##### Project Type and Purpose
- Type: Single‐page, front-end web application (no custom backend).
- Purpose: A Svelte-based UI that connects directly to OpenAI Assistants API (the “deep-chat” component) to deliver a bio-inspired design assistant.

##### File Structure
- public/
– index.html & global.css: static entry point served to the browser
- src/
– main.js: Svelte app bootstrap
– App.svelte & components/: UI layer
– assistant/: wrappers around assistant logic & function handlers
– utils/: local storage, IndexedDB, OpenAI helper utilities, logging
- python/: Development tool for translating an OpenAPI spec (ss-spec-v3.json) into JS function definitions
- rollup.config.js: build tool config
- package.json / package-lock.json: dependencies (deep-chat web component, Svelte, etc.)

##### README for Insights
- No custom backend; uses OpenAI Assistants API exclusively
- Integrates “deep-chat” web component for speech & function calling
- Leverages built-in Code Interpreter & Knowledge Retrieval tools
- Supports custom functions calling external APIs: Semantic Scholar, DALL-E, PQAI, Tavily

##### Main Components & Interactions
a. Browser / Client
– Svelte SPA (App.svelte + components)
– deep-chat web component (handles chat UI, speech-to/text, function call plumbing)
– Local storage layer: IndexedDB (via utils/indexDBUtils.js) for offline chat persistence
b. Build / Dev Tools (local)
– rollup (bundles JS/CSS into /public)
– python/openapi-to-functions.py: generates functions interface code before build
c. OpenAI Assistants API
– Chat completion endpoint with Functions support
– Code Interpreter & Knowledge Retrieval plugins (handled server-side by OpenAI)
d. External Services (invoked via Functions)
– Semantic Scholar API
– DALL-E image generation
– PQAI patent search
– Tavily web search

##### Architectural Patterns & Principles
- SPA layering: Presentation (Svelte components), Logic (assistant wrappers + utils), Data (IndexedDB)
- Function-call pattern: JSON-RPC style via Assistants API → local JS handlers
- Static hosting: GitHub Pages or any CDN for /public

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Static Asset Host"
        HTML["public/index.html"]:::build
        CSS["public/global.css"]:::build
    end

    subgraph "Build Pipeline"
        Rollup["rollup.config.js"]:::build
        OpenAPIgen["openapi-to-functions.py"]:::build
        Spec["ss-spec-v3.json"]:::build
    end

    subgraph "Browser Runtime"
        Main["src/main.js"]:::client
        App["src/App.svelte"]:::client
        subgraph "UI Components"
            Components["src/components/"]:::client
            DeepChatWrapper["src/components/AssistantDeepChat.svelte"]:::client
        end
        subgraph "Assistant Logic"
            AssistantIndex["src/assistant/index.js"]:::client
            Common["src/assistant/common.js"]:::client
            CommonFuncs["src/assistant/commonFunctions.js"]:::client
            BidaraLogic["src/assistant/bidara.js"]:::client
            BidaraFuncs["src/assistant/bidaraFunctions.js"]:::client
        end
        subgraph "Utils"
            DBUtils["src/utils/indexDBUtils.js"]:::client
            StorageUtils["src/utils/storageUtils.js"]:::client
            BidaraDB["src/utils/bidaraDB.js"]:::client
            OpenAIUtils["src/utils/openaiUtils.js"]:::client
            Logger["src/utils/logger.js"]:::client
            ThreadUtils["src/utils/threadUtils.js"]:::client
        end
        IDB[(IndexedDB Storage)]:::client
    end

    subgraph "Cloud Services"
        OpenAI["OpenAI Assistants API"]:::external
        subgraph "External Function Services"
            Semantic["Semantic Scholar API"]:::external
            Dalle["DALL-E API"]:::external
            PQAI["PQAI API"]:::external
            Tavily["Tavily API"]:::external
        end
    end

    HTML -->|Served To| Main
    CSS -->|Served To| Main
    Rollup -->|Bundles Into| HTML
    Rollup -->|Bundles Into| CSS
    Spec -->|Feeds| OpenAPIgen
    OpenAPIgen -->|Generates Interfaces| AssistantIndex

    Main -->|Bootstraps| App
    App -->|Renders| Components
    App -->|Integrates| DeepChatWrapper
    DeepChatWrapper -->|Plumbs| AssistantIndex
    DeepChatWrapper -->|Updates UI| App

    App -->|IndexedDB read/write| IDB
    DBUtils -->|Abstraction| IDB
    StorageUtils -->|LocalStorage| IDB
    BidaraDB -->|DB Abstraction| IDB

    OpenAIUtils -->|Calls| OpenAI
    ThreadUtils -->|Handles Threads| AssistantIndex
    Logger -->|Logs| AssistantIndex

    AssistantIndex -->|Imports| Common
    AssistantIndex -->|Imports| CommonFuncs
    AssistantIndex -->|Imports| BidaraLogic
    AssistantIndex -->|Imports| BidaraFuncs

    DeepChatWrapper -->|API Request| OpenAI
    OpenAI -->|Responds| DeepChatWrapper

    OpenAI -->|Function call| CommonFuncs
    CommonFuncs -->|API Request| Semantic

    OpenAI -->|Function call| BidaraFuncs
    BidaraFuncs -->|API Request| Dalle
    BidaraFuncs -->|API Request| PQAI
    BidaraFuncs -->|API Request| Tavily

    classDef client fill:#D6EAF8,stroke:#3498DB,color:#1B4F72
    classDef build fill:#D5F5E3,stroke:#27AE60,color:#145A32
    classDef external fill:#FAD7A0,stroke:#D35400,color:#6E2C00

    click HTML "https://github.com/nasa-petal/bidara-deep-chat/blob/main/public/index.html"
    click CSS "https://github.com/nasa-petal/bidara-deep-chat/blob/main/public/global.css"
    click Rollup "https://github.com/nasa-petal/bidara-deep-chat/blob/main/rollup.config.js"
    click OpenAPIgen "https://github.com/nasa-petal/bidara-deep-chat/blob/main/python/openapi-to-functions.py"
    click Spec "https://github.com/nasa-petal/bidara-deep-chat/blob/main/python/ss-spec-v3.json"
    click Main "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/main.js"
    click App "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/App.svelte"
    click Components "https://github.com/nasa-petal/bidara-deep-chat/tree/main/src/components/"
    click DeepChatWrapper "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/components/AssistantDeepChat.svelte"
    click AssistantIndex "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/assistant/index.js"
    click Common "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/assistant/common.js"
    click CommonFuncs "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/assistant/commonFunctions.js"
    click BidaraLogic "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/assistant/bidara.js"
    click BidaraFuncs "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/assistant/bidaraFunctions.js"
    click DBUtils "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/indexDBUtils.js"
    click StorageUtils "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/storageUtils.js"
    click BidaraDB "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/bidaraDB.js"
    click OpenAIUtils "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/openaiUtils.js"
    click Logger "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/logger.js"
    click ThreadUtils "https://github.com/nasa-petal/bidara-deep-chat/blob/main/src/utils/threadUtils.js"
```
