# astrabert/praivatesearch architecture

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

- Interactive diagram: https://gitdiagram.com/astrabert/praivatesearch
- Repository: https://github.com/astrabert/praivatesearch

## Overview

##### Project type and purpose
- PrAIvateSearch is a full-stack application combining a Next.js frontend (“chatbot-ui”) and a Python FastAPI backend (“qwen-on-api”) to provide private, local AI-powered web search.

##### File structure
- Top‐level:
- `.env.example`, `compose.yaml`, `conda_environment.yaml` – environment and orchestration.
- `chatbot-ui/` – Next.js frontend, Dockerfile, workspace config, public/static assets, styles, pages (layout.js, page.js).
- `qwen-on-api/` – FastAPI app with `main.py`, utilities (`chatHistoryUtils.py`, `textUtils.py`, `webSearch.py`, `qdrantRag.py`), `compose.yaml`, `static/`.
- `docs/`, `imgs/` – documentation and flowchart.
- Indicators of architecture: frontend/backend separation, containerization (Dockerfiles, compose.yaml), MVC‐style page structure in Next.js, service‐oriented design in Python module decomposition.

##### README for additional insights
- Confirms two service areas: Next.js UI on port 3000, FastAPI backend on port 8000.
- Describes dependencies: PostgreSQL, Crawl4AI crawler, Qwen model inference via Uvicorn, Docker Compose orchestration.
- Includes a flowchart (`imgs/PrAIvateSearch_Flowchart.png`) illustrating: user query → crawl & search pipeline → vector retrieval → language model inference → UI response.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Browser["User's Browser"]:::external

    %% Docker Compose Cluster
    subgraph "Docker Compose Orchestrator" 
        direction TB

        %% Frontend Service
        subgraph "Next.js UI Container" 
            direction TB
            UI["Next.js UI"]:::frontend
            DockerfileUI["UI Dockerfile"]:::frontend
            Layout["App Layout"]:::frontend
            Page["App Page"]:::frontend
            AssetsUI["Static Assets & Styles"]:::frontend
        end

        %% Backend Service
        subgraph "FastAPI Backend Container"
            direction TB
            API["FastAPI API"]:::backend
            MainPy["Entry Point (main.py)"]:::backend
            ChatHist["Chat History Utils"]:::backend
            TextUtil["Text Processing Utils"]:::backend
            WebSearch["Crawl4AI Integration"]:::backend
            RAG["RAG Pipeline Module"]:::backend
            AssetsBE["Backend Static Assets"]:::backend
        end

        %% Supporting Services
        Crawl["Crawl4AI Crawler"]:::external
        Postgres[(PostgreSQL)]:::db
        Qdrant[(Qdrant Vector Store)]:::db
        Model["Qwen-2.5B Model Server"]:::backend
    end

    %% External Web
    Web["External Web"]:::external

    %% Flows
    Browser -->|"HTTP JSON"| UI
    UI -->|"REST JSON"| API
    API -->|"trigger crawl"| Crawl
    Crawl -->|"HTML/Text"| API
    API -->|"vector embeddings"| Qdrant
    API -->|"vector query"| Qdrant
    Qdrant -->|"top-k contexts"| API
    API -->|"prompt"| Model
    Model -->|"completion"| API
    API -->|"SQL"| Postgres
    Postgres -->|"ACK"| API
    API -->|"HTTP JSON"| UI
    UI --> Browser

    Web -->|"live crawl"| Crawl

    %% Click Events
    click UI "https://github.com/astrabert/praivatesearch/tree/main/chatbot-ui/"
    click DockerfileUI "https://github.com/astrabert/praivatesearch/blob/main/chatbot-ui/Dockerfile.ui"
    click Layout "https://github.com/astrabert/praivatesearch/blob/main/chatbot-ui/src/app/layout.js"
    click Page "https://github.com/astrabert/praivatesearch/blob/main/chatbot-ui/src/app/page.js"
    click AssetsUI "https://github.com/astrabert/praivatesearch/tree/main/chatbot-ui/public/"
    click API "https://github.com/astrabert/praivatesearch/tree/main/qwen-on-api/"
    click MainPy "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/main.py"
    click ChatHist "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/chatHistoryUtils.py"
    click TextUtil "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/textUtils.py"
    click WebSearch "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/webSearch.py"
    click RAG "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/qdrantRag.py"
    click AssetsBE "https://github.com/astrabert/praivatesearch/tree/main/qwen-on-api/static/"
    click Crawl "https://github.com/astrabert/praivatesearch/blob/main/qwen-on-api/compose.yaml"
    click Postgres "https://github.com/astrabert/praivatesearch/blob/main/compose.yaml"
    click Model "https://github.com/astrabert/praivatesearch/blob/main/conda_environment.yaml"
    click Web "https://github.com/astrabert/praivatesearch/blob/main/imgs/PrAIvateSearch_Flowchart.png"
    click docs "https://github.com/astrabert/praivatesearch/tree/main/docs/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3B82F6,color:#000;
    classDef backend fill:#DFFFE0,stroke:#10B981,color:#000;
    classDef db fill:#FFE8D0,stroke:#F59E0B,color:#000;
    classDef external fill:#F3E8FF,stroke:#8B5CF6,color:#000;
```
