# mhd-gdev/browsellama architecture

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

- Interactive diagram: https://gitdiagram.com/mhd-gdev/browsellama
- Repository: https://github.com/mhd-gdev/browsellama

## Overview

##### Project type and purpose
- BrowseLlama is an open-source Python-based CLI tool that augments a local LLM (via llama.cpp) with live web search. It ships two entry-points:
- online.py for quick search on the first few pages
- deep.py for multi-page, deeper scraping
- The goal is: take a user’s question, search the web, collect content, then feed that into a local LLM to generate an answer.

##### File structure
- Top level:
- README.md – project overview and install/usage instructions
- online.py – “quick” search + single-page pipeline
- deep.py – “deep” multi-page search + pipeline
- No subdirectories or microservices. All functionality lives in these two Python scripts.
- Dependencies: llama_cpp_python (wrapper for llama.cpp), beautifulsoup4, requests, duckduckgo-search – each plays a distinct architectural role.

##### Architecture gleaned from README
- Local model files (downloaded separately; loaded by llama_cpp_python)
- HTTP search (duckduckgo-search)
- HTTP fetch (requests)
- HTML parsing (BeautifulSoup)
- LLM inference (llama.cpp via llama_cpp_python)
- CLI orchestration

a. Main components
1. CLI Layer
- online.py / deep.py
2. Search Layer
- duckduckgo-search library → returns URLs
3. Fetch Layer
- requests library → downloads raw HTML
4. Parse Layer
- BeautifulSoup → extracts text
5. LLM Inference Layer
- llama_cpp_python → llama.cpp → local model files
6. Local Storage
- Model directory (user-specified)
b. Relationships & data flow
- User CLI input → Search Layer (queries DuckDuckGo)
- Search Layer → list of URLs → Fetch Layer
- Fetch Layer → raw HTML → Parse Layer
- Parse Layer → cleaned text → LLM Inference Layer
- LLM Inference Layer → generated answer → CLI output
c. Architectural patterns & design principles
- Pipeline pattern: each layer has a single responsibility
- Modular: search, fetch, parse, inference can be swapped or extended
- CLI orchestration: thin wrapper that chains stages
d. Key technologies & libraries
- Python 3.x
- llama_cpp_python (bridges to llama.cpp)
- duckduckgo-search (web search API)
- requests (HTTP client)
- BeautifulSoup4 (HTML parser)

##### Essential details without over-splitting
- Where the user must configure paths (the “model directory”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Documentation"
        README["README.md"]:::doc
    end

    subgraph "CLI Layer"
        Online["online.py\n(quick search)"]:::cli
        Deep["deep.py\n(deep search)"]:::cli
    end

    subgraph "Pipeline"
        Search["Search Service\nduckduckgo-search"]:::library
        Fetch["Fetch Service\nrequests"]:::library
        Parse["Parse Layer\nBeautifulSoup4"]:::library
        LLM["LLM Inference\nllama_cpp_python\n(llama.cpp)"]:::library
        Storage["Model Files Directory"]:::storage
        Duck["DuckDuckGo API"]:::external
    end

    README ---> Online
    README ---> Deep

    Online -->|"query"| Search
    Deep -->|"query\n(max_pages)"| Search

    Search -->|"send HTTP request"| Duck
    Duck -->|"returns URLs"| Search

    Search -->|"URLs"| Fetch
    Fetch -->|"raw HTML"| Parse
    Parse -->|"cleaned text"| LLM
    Storage -->|"model files"| LLM

    LLM -->|"answer"| Online
    LLM -->|"answer"| Deep

    click online.py "https://github.com/mhd-gdev/browsellama/blob/master/online.py"
    click deep.py "https://github.com/mhd-gdev/browsellama/blob/master/deep.py"
    click README.md "https://github.com/mhd-gdev/browsellama/blob/master/README.md"

    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef library fill:#90EE90,stroke:#333,stroke-width:1px
    classDef cli fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef doc fill:#FFDEAD,stroke:#333,stroke-width:1px
```
