# k3tikvats/perplexity_clone architecture

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

- Interactive diagram: https://gitdiagram.com/k3tikvats/perplexity_clone
- Repository: https://github.com/k3tikvats/perplexity_clone

## Overview

##### Main Components

A. Frontend Layer (Flutter)
- Present as a multi-platform application container
- Main UI components:
- Home Page
- Chat Page
- Search Components
- Sidebar Navigation

B. Backend Server (Python)
- FastAPI/Python server structure
- Three main services:
- LLM Service (Gemini API integration)
- Search Service (Tavily API integration)
- Source Sorting Service

C. External Services
- Gemini API
- Tavily API
- Vector Embedding Service

**[Client Layer]**
- ↕️
**[Backend Layer]**
- ↕️
**[External Services Layer]**

##### Component Details

Frontend (Flutter):
- Main widget tree structure:
- Pages (home_page.dart, chat_page.dart)
- Widgets (search_bar_button.dart, search_section.dart, side_bar.dart)
- Services (chat_web_service.dart)

Backend (Python):
- Main service components:
- main.py (API endpoints)
- services/
- llm_service.py
- search_service.py
- sort_source_service.py
- pydantic_models/
- chat_body.py

##### User Query Flow
- User Input → Frontend → Backend → External Services
##### Response Flow
- External Services → Backend Processing → Frontend Display

##### Architectural Patterns to Highlight

- Service-oriented architecture
- Clean separation between UI and business logic
- Microservices-like backend structure
- API Gateway pattern for external service integration

##### Implementation Details

**[Flutter UI Layer]**
- Pages
- Widgets
- Services

**[Python Backend Layer]**
- API Endpoints
- Services
- Models

**[External Services Layer]**
- Gemini API
- Tavily API
- Vector Embeddings

##### Additional Elements

- Version/environment information
- Security boundaries
- Stateless/stateful components

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    
    %% Frontend Layer
    subgraph Frontend
        AppEntry["Application Entry"]
        HomePage["Home Page"]
        ChatPage["Chat Page"]
        SearchComponents["Search Components"]
        SideBar["Sidebar Navigation"]
        ChatWebService["Chat Web Service"]
        ThemeConfig["Theme Configuration"]
    end
    
    %% Backend Layer
    subgraph Backend
        MainServer["FastAPI Server"]
        LLMService["LLM Service"]
        SearchService["Search Service"]
        SortService["Source Sorting Service"]
        ChatModels["Chat Models"]
        Config["Configuration"]
    end
    
    %% External Services Layer
    subgraph External
        GeminiAPI["Gemini API"]
        TavilyAPI["Tavily API"]
        VectorService["Vector Embedding Service"]
    end
    
    %% Relationships
    AppEntry --> HomePage
    AppEntry --> ChatPage
    HomePage --> SearchComponents
    HomePage --> SideBar
    ChatPage --> ChatWebService
    ChatWebService --> MainServer
    
    MainServer --> LLMService
    MainServer --> SearchService
    MainServer --> SortService
    MainServer --> ChatModels
    
    LLMService --> GeminiAPI
    SearchService --> TavilyAPI
    SortService --> VectorService
    
    %% Click Events
    click AppEntry "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/main.dart"
    click HomePage "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/pages/home_page.dart"
    click ChatPage "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/pages/chat_page.dart"
    click SearchComponents "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/widgets/search_section.dart"
    click SideBar "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/widgets/side_bar.dart"
    click ChatWebService "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/services/chat_web_service.dart"
    click ThemeConfig "https://github.com/k3tikvats/perplexity_clone/blob/main/lib/theme/colors.dart"
    click MainServer "https://github.com/k3tikvats/perplexity_clone/blob/main/server/main.py"
    click LLMService "https://github.com/k3tikvats/perplexity_clone/blob/main/server/services/llm_service.py"
    click SearchService "https://github.com/k3tikvats/perplexity_clone/blob/main/server/services/search_service.py"
    click SortService "https://github.com/k3tikvats/perplexity_clone/blob/main/server/services/sort_source_service.py"
    click ChatModels "https://github.com/k3tikvats/perplexity_clone/blob/main/server/pydantic_models/chat_body.py"
    click Config "https://github.com/k3tikvats/perplexity_clone/blob/main/server/config.py"
    
    %% Styling
    class AppEntry,HomePage,ChatPage,SearchComponents,SideBar,ChatWebService,ThemeConfig frontend
    class MainServer,LLMService,SearchService,SortService,ChatModels,Config backend
    class GeminiAPI,TavilyAPI,VectorService external
```
