# bhushan-amit/mini_perplexity_qna architecture

> Architecture diagram of the GitHub repository bhushan-amit/mini_perplexity_qna, 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/bhushan-amit/mini_perplexity_qna
- Repository: https://github.com/bhushan-amit/mini_perplexity_qna

## Overview

##### Project Type and Purpose
- This is a full-stack web application that offers a Q&A system. The backend retrieves information using the Bing Search API and processes it with OpenAI’s GPT-4 for generating answers. The frontend, built in React, provides a user interface for entering queries and displaying responses.
- The README clearly outlines the use of FastAPI for asynchronous handling and a clear separation of API responsibilities, while also providing deployment details to Render (backend) and Vercel (frontend).

##### Analyzing the File Structure
- At the top level, you have separate directories for the backend, frontend, and CI/CD configurations within the .github folder.
- Within the backend directory, notice:
- app directory with subdirectories for core configuration, main application startup, services (for Bing search and GPT integration), and tests to ensure functionality.
- The use of __init__.py files indicates a Python package structure that helps modularize the application.
- The requirements.txt file for dependencies.
- The frontend directory contains configuration files such as .env, package.json, and public resources like index.html. The src folder contains React components, indicating a clear separation of UI components (SearchBar, CitationList, etc.) and application logic.
- This organization shows a separation of concerns and hints at using an API-first design on the backend with React consuming these APIs on the frontend.

##### Key Components and Their Roles
- Frontend (React):
- Components: App, SearchBar, ResultDisplay, CitationList.
- Configuration files (.env) used to point to the backend API.
- Package dependencies managed by package.json and package-lock.json.
- Backend (FastAPI):
- Main entry point: backend/app/main.py.
- Configuration: backend/app/core/config.py for environment-specific settings.
- Services:
- bing_search.py: Interfaces with the Bing Search API to obtain web results.
- gpt_integration.py: Handles calls to the OpenAI GPT-4 model for generating query responses.
- Tests located in backend/app/tests to ensure core functionality.
- External Services:
- Bing Search API: For web results.
- OpenAI GPT-4: For generating responses.
- Deployment platforms: Render for backend deployment and Vercel for the frontend.

##### Relationships and Interactions
- The user interacts with the React frontend. Once a query is entered:
- The frontend sends the query to the FastAPI backend.
- The backend fetches relevant web data by calling the Bing Search API (via the bing_search.py service).
- The backend then processes this data and uses gpt_integration.py to generate a coherent answer using GPT-4.
- The final response, including citations from Bing, is sent back to the frontend for display.

##### Architectural Patterns and Design Principles
- Modular separation of concerns: Backend services are divided into configuration, main application logic, business services (for Bing and GPT), and tests.
- API-driven design: The FastAPI backend exposes endpoints that the React frontend consumes.
- Use of third-party APIs for search and AI generation, making the overall design extensible should you decide to add alternative providers.
- Component-based design in the frontend ensures the UI is maintainable and scalable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    U("User"):::external

    %% Frontend Layer
    subgraph "Frontend Layer [React]"
        FE("React Frontend"):::frontend
        FEComponents("UI Components: App, SearchBar, ResultDisplay, CitationList"):::component
        FE -->|"contains"| FEComponents
    end

    %% Backend Layer
    subgraph "Backend Layer [FastAPI]"
        BA("FastAPI Server"):::backend
        BC("Configuration Module"):::config
        Services("Service Modules"):::backend
        BA -->|"uses"| BC
        BA -->|"invokes"| Services
        subgraph "Backend Services"
            Bing("Bing Search API Service"):::service
            GPT("GPT-4 Integration Service"):::service
            Services --> Bing
            Services --> GPT
        end
        Tests("Testing Suite"):::test
    end

    %% External APIs
    subgraph "External APIs"
        BingAPI("Bing Search API"):::external
        OpenAI("OpenAI GPT-4"):::external
    end

    %% Deployment & CI/CD
    subgraph "Deployment & CI/CD"
        DeploymentBE("Render (Backend Deployment)"):::deployment
        DeploymentFE("Vercel (Frontend Deployment)"):::deployment
        CICD("CI/CD Pipeline (GitHub Actions)"):::cicd
    end

    %% Data Flow
    U -->|"submits_query"| FE
    FE -->|"API_request"| BA
    BA -->|"calls"| Bing
    BA -->|"calls"| GPT
    Bing -->|"fetches_data"| BingAPI
    GPT -->|"generates_response"| OpenAI
    BA -->|"returns_response"| FE

    %% Deployment Flow
    BA -->|"deployed_on"| DeploymentBE
    FE -->|"deployed_on"| DeploymentFE
    Tests -->|"triggers"| CICD

    %% Click Events
    click FE "https://github.com/bhushan-amit/mini_perplexity_qna/tree/main/frontend/"
    click FEComponents "https://github.com/bhushan-amit/mini_perplexity_qna/tree/main/frontend/src/components"
    click BA "https://github.com/bhushan-amit/mini_perplexity_qna/blob/main/backend/app/main.py"
    click BC "https://github.com/bhushan-amit/mini_perplexity_qna/blob/main/backend/app/core/config.py"
    click Bing "https://github.com/bhushan-amit/mini_perplexity_qna/blob/main/backend/app/services/bing_search.py"
    click GPT "https://github.com/bhushan-amit/mini_perplexity_qna/blob/main/backend/app/services/gpt_integration.py"
    click Tests "https://github.com/bhushan-amit/mini_perplexity_qna/tree/main/backend/app/tests"
    click CICD "https://github.com/bhushan-amit/mini_perplexity_qna/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#FFCCCB,stroke:#000,stroke-width:1px;
    classDef external fill:#E6E6FA,stroke:#000,stroke-width:1px;
    classDef deployment fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef cicd fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef config fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef service fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef test fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef component fill:#F0E68C,stroke:#000,stroke-width:1px;
```
