# plokmklo/freegem architecture

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

- Interactive diagram: https://gitdiagram.com/plokmklo/freegem
- Repository: https://github.com/plokmklo/freegem

## Overview

FreeGem bridges an existing Gemini Web session to HTTP, MCP, and CLI clients, while also providing guarded web tools. The main request path is an interface into the Gemini client and upstream service; separate web workflows cover scraping, research, verification, extraction, crawling, and monitoring. Edges rely on README statements or the supplied source index and excerpts; some subsystems are documented but their internal wiring was not sampled.

Main entry points: [`freegem/cli.py`](https://github.com/plokmklo/freegem/blob/main/freegem/cli.py) (CLI), [`freegem/mcp_tools.py`](https://github.com/plokmklo/freegem/blob/main/freegem/mcp_tools.py) (MCP tools), [`freegem/web_scraper.py`](https://github.com/plokmklo/freegem/blob/main/freegem/web_scraper.py) (Page scraping), [`freegem/crawler/runner.py`](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/runner.py) (Crawl runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_http["HTTP API<br/>[server.py]"]
  node_cli["CLI<br/>[cli.py]"]
  node_mcp["MCP tools<br/>[mcp_tools.py]"]
end

subgraph group_gemini["Gemini bridge"]
  node_config["Configuration<br/>[config.py]"]
  node_client["Gemini client<br/>[gemini.py]"]
  node_gemini_service["Gemini Web"]
end

subgraph group_web["Web tools"]
  node_scrape["Page scraping<br/>[web_scraper.py]"]
  node_smart_fetch["Smart fetching<br/>[smart_fetch.py]"]
  node_ssrf["SSRF protection<br/>[ssrf.py]"]
  node_research["Cited research<br/>[web_research.py]"]
  node_verification["Claim verification<br/>[claim_verify.py]"]
  node_ai_scrape["AI scraping<br/>[ai_scrape.py]"]
  node_llm_extract["Structured extraction<br/>[llm_extract.py]"]
end

subgraph group_crawl["Crawler"]
  node_crawler["Crawl runner<br/>[runner.py]"]
  node_crawl_fetch["Guarded crawl fetch<br/>[fetch.py]"]
  node_crawl_resilience["Fetch resilience<br/>[resilient.py]"]
  node_crawl_extract["Crawl extraction<br/>[extract.py]"]
  node_crawl_frontier["Frontier and URLs<br/>[frontier.py]"]
  node_crawl_output["Crawl output<br/>[output.py]"]
end

subgraph group_operations["Jobs and monitoring"]
  node_jobs["Job runner<br/>[jobs.py]"]
  node_watch["Change monitoring<br/>[watch.py]"]
  node_metrics["Metrics<br/>[metrics.py]"]
end

node_user(("Client or user"))

node_user -->|"sends requests"| node_http
node_user -->|"runs commands"| node_cli
node_user -->|"calls tools"| node_mcp
node_http -->|"requests generation"| node_client
node_cli -->|"requests generation"| node_client
node_mcp -->|"runs Gemini tools"| node_client
node_client -->|"sends prompts"| node_gemini_service
node_cli -->|"runs scrape"| node_scrape
node_cli -->|"runs research"| node_research
node_cli -->|"runs verification"| node_verification
node_cli -->|"runs AI scrape"| node_ai_scrape
node_cli -->|"runs crawl"| node_crawler
node_mcp -->|"exposes scraping"| node_scrape
node_mcp -->|"exposes research"| node_research
node_mcp -->|"exposes verification"| node_verification
node_scrape -->|"guards requests"| node_ssrf
node_scrape -->|"uses fetching"| node_smart_fetch
node_research -->|"fetches pages"| node_scrape
node_ai_scrape -->|"fetches pages"| node_scrape
node_ai_scrape -->|"extracts fields"| node_llm_extract
node_llm_extract -->|"generates extraction"| node_client
node_verification -->|"uses research"| node_research
node_crawler -->|"fetches pages"| node_crawl_fetch
node_crawler -->|"manages URLs"| node_crawl_frontier
node_crawler -->|"extracts records"| node_crawl_extract
node_crawler -->|"writes results"| node_crawl_output
node_crawl_fetch -->|"uses retries"| node_crawl_resilience
node_crawl_resilience -->|"guards resolution"| node_ssrf
node_http -->|"submits jobs"| node_jobs
node_mcp -->|"submits jobs"| node_jobs
node_cli -->|"runs monitoring"| node_watch
node_http -->|"serves metrics"| node_metrics

click node_http "https://github.com/plokmklo/freegem/blob/main/freegem/server.py"
click node_cli "https://github.com/plokmklo/freegem/blob/main/freegem/cli.py"
click node_mcp "https://github.com/plokmklo/freegem/blob/main/freegem/mcp_tools.py"
click node_config "https://github.com/plokmklo/freegem/blob/main/freegem/config.py"
click node_client "https://github.com/plokmklo/freegem/blob/main/freegem/gemini.py"
click node_scrape "https://github.com/plokmklo/freegem/blob/main/freegem/web_scraper.py"
click node_smart_fetch "https://github.com/plokmklo/freegem/blob/main/freegem/smart_fetch.py"
click node_ssrf "https://github.com/plokmklo/freegem/blob/main/freegem/ssrf.py"
click node_research "https://github.com/plokmklo/freegem/blob/main/freegem/web_research.py"
click node_verification "https://github.com/plokmklo/freegem/blob/main/freegem/claim_verify.py"
click node_ai_scrape "https://github.com/plokmklo/freegem/blob/main/freegem/ai_scrape.py"
click node_llm_extract "https://github.com/plokmklo/freegem/blob/main/freegem/llm_extract.py"
click node_crawler "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/runner.py"
click node_crawl_fetch "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/fetch.py"
click node_crawl_resilience "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/resilient.py"
click node_crawl_extract "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/extract.py"
click node_crawl_frontier "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/frontier.py"
click node_crawl_output "https://github.com/plokmklo/freegem/blob/main/freegem/crawler/output.py"
click node_jobs "https://github.com/plokmklo/freegem/blob/main/freegem/jobs.py"
click node_watch "https://github.com/plokmklo/freegem/blob/main/freegem/watch.py"
click node_metrics "https://github.com/plokmklo/freegem/blob/main/freegem/metrics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_cli,node_mcp,node_user toneBlue
class node_config,node_client,node_gemini_service toneAmber
class node_scrape,node_smart_fetch,node_ssrf,node_research,node_verification,node_ai_scrape,node_llm_extract toneMint
class node_crawler,node_crawl_fetch,node_crawl_resilience,node_crawl_extract,node_crawl_frontier,node_crawl_output toneRose
class node_jobs,node_watch,node_metrics toneIndigo
```

## Components

### User interfaces

- [HTTP API](https://github.com/plokmklo/freegem/blob/main/freegem/server.py): `freegem/server.py`
- [CLI](https://github.com/plokmklo/freegem/blob/main/freegem/cli.py): `freegem/cli.py`
- [MCP tools](https://github.com/plokmklo/freegem/blob/main/freegem/mcp_tools.py): `freegem/mcp_tools.py`

### Gemini bridge

- [Configuration](https://github.com/plokmklo/freegem/blob/main/freegem/config.py): `freegem/config.py`
- [Gemini client](https://github.com/plokmklo/freegem/blob/main/freegem/gemini.py): `freegem/gemini.py`
- **Gemini Web**

### Web tools

- [Page scraping](https://github.com/plokmklo/freegem/blob/main/freegem/web_scraper.py): `freegem/web_scraper.py`
- [Smart fetching](https://github.com/plokmklo/freegem/blob/main/freegem/smart_fetch.py): `freegem/smart_fetch.py`
- [SSRF protection](https://github.com/plokmklo/freegem/blob/main/freegem/ssrf.py): `freegem/ssrf.py`
- [Cited research](https://github.com/plokmklo/freegem/blob/main/freegem/web_research.py): `freegem/web_research.py`
- [Claim verification](https://github.com/plokmklo/freegem/blob/main/freegem/claim_verify.py): `freegem/claim_verify.py`
- [AI scraping](https://github.com/plokmklo/freegem/blob/main/freegem/ai_scrape.py): `freegem/ai_scrape.py`
- [Structured extraction](https://github.com/plokmklo/freegem/blob/main/freegem/llm_extract.py): `freegem/llm_extract.py`

### Crawler

- [Crawl runner](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/runner.py): `freegem/crawler/runner.py`
- [Guarded crawl fetch](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/fetch.py): `freegem/crawler/fetch.py`
- [Fetch resilience](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/resilient.py): `freegem/crawler/resilient.py`
- [Crawl extraction](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/extract.py): `freegem/crawler/extract.py`
- [Frontier and URLs](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/frontier.py): `freegem/crawler/frontier.py`
- [Crawl output](https://github.com/plokmklo/freegem/blob/main/freegem/crawler/output.py): `freegem/crawler/output.py`

### Jobs and monitoring

- [Job runner](https://github.com/plokmklo/freegem/blob/main/freegem/jobs.py): `freegem/jobs.py`
- [Change monitoring](https://github.com/plokmklo/freegem/blob/main/freegem/watch.py): `freegem/watch.py`
- [Metrics](https://github.com/plokmklo/freegem/blob/main/freegem/metrics.py): `freegem/metrics.py`

### Other components

- **Client or user**

## Connections

- Client or user → HTTP API: sends requests
- Client or user → CLI: runs commands
- Client or user → MCP tools: calls tools
- HTTP API → Gemini client: requests generation (evidence: `freegem/server.py`)
- CLI → Gemini client: requests generation (evidence: `freegem/cli.py`)
- MCP tools → Gemini client: runs Gemini tools (evidence: `freegem/mcp_tools.py`)
- Gemini client → Gemini Web: sends prompts (evidence: `freegem/gemini.py`)
- CLI → Page scraping: runs scrape (evidence: `freegem/cli.py`)
- CLI → Cited research: runs research (evidence: `freegem/cli.py`)
- CLI → Claim verification: runs verification (evidence: `freegem/cli.py`)
- CLI → AI scraping: runs AI scrape (evidence: `freegem/cli.py`)
- CLI → Crawl runner: runs crawl (evidence: `freegem/cli.py`)
- MCP tools → Page scraping: exposes scraping (evidence: `freegem/mcp_tools.py`)
- MCP tools → Cited research: exposes research (evidence: `freegem/mcp_tools.py`)
- MCP tools → Claim verification: exposes verification (evidence: `freegem/mcp_tools.py`)
- Page scraping → SSRF protection: guards requests (evidence: `freegem/web_scraper.py`)
- Page scraping → Smart fetching: uses fetching (evidence: `freegem/web_scraper.py`)
- Cited research → Page scraping: fetches pages (evidence: `freegem/web_research.py`)
- AI scraping → Page scraping: fetches pages (evidence: `freegem/ai_scrape.py`)
- AI scraping → Structured extraction: extracts fields (evidence: `freegem/ai_scrape.py`)
- Structured extraction → Gemini client: generates extraction (evidence: `freegem/llm_extract.py`)
- Claim verification → Cited research: uses research (evidence: `freegem/claim_verify.py`)
- Crawl runner → Guarded crawl fetch: fetches pages (evidence: `freegem/crawler/runner.py`)
- Crawl runner → Frontier and URLs: manages URLs (evidence: `freegem/crawler/runner.py`)
- Crawl runner → Crawl extraction: extracts records (evidence: `freegem/crawler/runner.py`)
- Crawl runner → Crawl output: writes results (evidence: `freegem/crawler/runner.py`)
- Guarded crawl fetch → Fetch resilience: uses retries (evidence: `freegem/crawler/fetch.py`)
- Fetch resilience → SSRF protection: guards resolution (evidence: `freegem/crawler/resilient.py`)
- HTTP API → Job runner: submits jobs (evidence: `freegem/server.py`)
- MCP tools → Job runner: submits jobs (evidence: `freegem/mcp_tools.py`)
- CLI → Change monitoring: runs monitoring (evidence: `freegem/cli.py`)
- HTTP API → Metrics: serves metrics (evidence: `freegem/server.py`)
