# dhyanshah22/researchgpt architecture

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

- Interactive diagram: https://gitdiagram.com/dhyanshah22/researchgpt
- Repository: https://github.com/dhyanshah22/researchgpt

## Overview

##### Project Type & Purpose
- ResearchGPT is a full-stack application. Its core functionality allows users to upload PDFs, extract text, generate embeddings, and interact with the content via an AI-driven conversational interface.

##### Key Parts from the File Structure
- At the root, you have key files such as app.py (and app1.py) which likely serve as the entry point for the interactive UI built with Streamlit.
- The “backend” directory is subdivided into two main sections:
– backend/api: Contains the core API logic such as models, views, serializers, URL configurations, and migrations. This indicates a well-structured backend likely following an MVC or Django REST Framework pattern.
– backend/backend: Contains configuration-related files like settings, asgi, wsgi, and URL routing for the backend. This further confirms the use of a framework (likely Django) for managing the server-side functionality.
- Supporting files such as requirements.txt, config.toml, and the .devcontainer folder suggest that the project is containerized and dependencies are clearly specified.

##### Main Components
a. Frontend (UI):
- Streamlit-based interface (app.py) where users interact with the system.
- Handles PDF upload and chat interactions.
b. Backend API:
- API layer (backend/api) managing endpoints, including uploading documents, processing PDF data, and handling user queries.
- Controllers/views, serializers, and models forming the business logic.
c. Data Processing & Storage:
- PDF Extraction Component: Utilizes PyPDFLoader to extract text from uploaded PDFs.
- Embeddings & Vector Store: Uses Google Gemini AI to generate embeddings and FAISS for efficient vector-based search.
d. External Services:
- Google Gemini AI – for generating intelligent, context-aware responses.
e. Dependencies & Services:
- LangChain for managing conversational flows.
- Additional middleware/configurations for asynchronous communications, as seen in asgi.py and wsgi.py.
f. Development & Deployment:
- DevContainer and configuration files indicate containerized development and deployment practices (e.g., using Streamlit Cloud or other cloud providers as mentioned in the README).

##### Relationships and Data Flow
- The UI sends the document to the backend API (via endpoints defined in backend/api/urls.py and handled by backend/api/views.py).
- The backend extracts text from the PDF, generates vector embeddings (through PyPDFLoader and the Google Gemini integration), and stores these in FAISS.
- When users input queries, these are forwarded to the backend which, possibly with the help of LangChain, retrieves contextual information from FAISS and uses Gemini AI to generate responses.
- The final answer, complete with source references, is sent back to the UI for display.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear division between the interactive frontend (Streamlit) and the backend API (likely Django), ensuring maintainability and scalability.
- Modular Design: The “backend/api” and “backend/backend” directories separate API concerns from overall configuration and deployment logic.
- Containerized Environment: Presence of the .devcontainer folder indicates an environment conducive to container-based development.
- External Service Integration: Integrates external AI hardware/services (Google Gemini AI) and external database (FAISS) in a loosely coupled manner.

##### Detailed Component Elements
- Clear labels for each component (e.g., “Streamlit UI App,” “Django API Backend,” “PDF Processor/Embedding Generator,” “FAISS Vector Store,” “Google Gemini AI Service”).
- Optionally, split the API layer into subcomponents if needed (e.g., authentication, document management, query handling) to capture more granularity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    U["User"]
    
    %% Frontend Layer
    UI["Streamlit UI App"]:::frontend

    %% Backend Layer Subgraph
    subgraph "Django Backend"
        APIEndpoints["API Endpoints (backend/api)"]:::backend
        ServerConfig["Server Config (backend/backend)"]:::backend
    end

    %% Processing Components
    PDFProc["PDF Processor & Embedding Generator"]:::processor
    Lang["LangChain Middleware"]:::middleware
    Vector["FAISS Vector Store"]:::external
    Gemini["Google Gemini AI Service"]:::external

    %% Containerized Environment
    Container["Containerized Environment & Dependencies"]:::container

    %% Relationships
    U -->|"initiates"| UI
    UI -->|"sends request"| APIEndpoints
    APIEndpoints -->|"invokes"| PDFProc
    PDFProc -->|"generates embeddings"| Vector
    PDFProc -->|"calls"| Gemini
    Gemini -->|"returns response"| PDFProc
    PDFProc -->|"formats convo"| Lang
    Lang -->|"sends final answer"| APIEndpoints
    APIEndpoints -->|"responds"| UI
    Container -->|"hosts"| APIEndpoints
    Container -->|"hosts"| UI

    %% Internal Backend Relationship
    APIEndpoints -->|"configured_by"| ServerConfig

    %% Styles
    classDef frontend fill:#d0e6f8,stroke:#0066cc,stroke-width:2px;
    classDef backend fill:#f8d0d0,stroke:#cc0000,stroke-width:2px;
    classDef processor fill:#e6e6fa,stroke:#9370db,stroke-width:2px;
    classDef external fill:#d0f8d0,stroke:#008000,stroke-width:2px;
    classDef middleware fill:#ffe4e1,stroke:#ff6347,stroke-width:2px;
    classDef container fill:#fffacd,stroke:#ffd700,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/dhyanshah22/researchgpt/blob/main/app.py"
    click UI "https://github.com/dhyanshah22/researchgpt/blob/main/app1.py"
    click APIEndpoints "https://github.com/dhyanshah22/researchgpt/tree/main/backend/api"
    click ServerConfig "https://github.com/dhyanshah22/researchgpt/tree/main/backend/backend"
    click Container "https://github.com/dhyanshah22/researchgpt/blob/main/.devcontainer"
    click Container "https://github.com/dhyanshah22/researchgpt/blob/main/config.toml"
    click Container "https://github.com/dhyanshah22/researchgpt/blob/main/requirements.txt"
```
