# ursisterbtw/markdown_lab architecture

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

- Interactive diagram: https://gitdiagram.com/ursisterbtw/markdown_lab
- Repository: https://github.com/ursisterbtw/markdown_lab

## Overview

##### Project Type and Purpose
- Markdown Lab is a web scraping and conversion tool that mixes Python for orchestration, web scraping, and high-level operations with Rust for performance-intensive tasks like HTML-to-Markdown/JSON/XML conversion and semantic chunking.
- Key use cases include scraping websites (with optional sitemap discovery), converting HTML content into various output formats, and performing intelligent content chunking for RAG (Retrieval-Augmented Generation).

##### Break Down the Main Components
- User Interface / CLI:
– Exposed via the Python __main__.py module which serves as the command-line entry point.
- Python Orchestration / Controller:
– The core scraper (found in markdown_lab/main.py) that accepts URLs, schedules the scraping, handles command-line arguments, and manages output.
– Supporting utilities in modules like chunk_utils.py (for RAG chunking), sitemap_utils.py (for sitemap parsing), and throttle.py (for rate limiting).
- Rust Integration / Performance Modules:
– The Rust library (in the src directory) that includes conversion functionality (markdown_converter.rs), HTML parsing (html_parser.rs), JavaScript rendering (js_renderer.rs), and semantic chunking logic (chunker.rs).
– Exposed to Python via the markdown_lab_rs.py interface, bridging both ecosystems.
- External Integrations:
– HTTP operations with libraries like requests and BeautifulSoup in Python.
– CI/CD components (GitHub Actions in .github/workflows) handling automated builds, tests, and releases.
- Utility & Auxiliary Components:
– Examples, scripts, tests, and benchmarks, which support development, testing, visualization of benchmark results, and usage demonstrations.

##### Relationships and Data Flow
- User Input (URL and conversion options) flows from the command-line or module entry point to the Python controller.
- The Python controller coordinates:
– Initiating HTTP requests (using requests and BeautifulSoup) to fetch website content.
– Passing the raw HTML to the Rust conversion functions, invoking either direct conversion (via markdown_converter.rs) or chunking (via chunker.rs) for performance-critical operations.
– Handling sitemap parsing by calling sitemap_utils to discover additional URLs.
– Managing rate limiting through the throttle module.
- The Rust library processes HTML content fast and returns the conversion results (in Markdown, JSON, or XML) back to Python.
- Finally, the Python side saves the output to files or directories and (if enabled) organizes content chunks for RAG systems.

##### Architectural Patterns and Design Principles
- Hybrid Architecture – Python for high-level orchestration and Rust for performance:
– Clearly separate components by language, showing Python modules interfacing with the Rust backend.
- Modular Design – Each main function (scraping, converting, chunking, sitemap parsing) is encapsulated in its own module, enabling independent testing and extensions.
- Dependency Management – Indicate external libraries, third-party integrations (e.g., BeautifulSoup, requests) and CI/CD flows for tests and benchmarks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entry
    A["User / CLI"]:::external

    %% Python Components Cluster
    subgraph "Python Components"
        B["Python Scraper Controller"]:::python
        C["Sitemap Parser"]:::python
        D["Chunking Module"]:::python
        E["Rate Limiter"]:::python
        F["Python Interface to Rust"]:::python
    end

    %% Rust Components Cluster
    subgraph "Rust Components"
        G["Markdown Converter"]:::rust
        H["HTML Parser"]:::rust
        I["JS Renderer"]:::rust
        J["Chunker"]:::rust
    end

    %% Auxiliary Components
    K["CI/CD Pipeline"]:::ci
    L["Tests"]:::aux
    M["Benchmarks"]:::aux
    N["Output Storage (Markdown/JSON/XML)"]:::external

    %% Data Flow
    A -->|"initiates"| B
    B -->|"sitemap"| C
    B -->|"chunking"| D
    B -->|"rate-limit"| E
    B -->|"conversion call"| F

    F -->|"conversion task"| G
    F -->|"conversion task"| H
    F -->|"conversion task"| I
    F -->|"conversion task"| J

    G -->|"result"| F
    H -->|"result"| F
    I -->|"result"| F
    J -->|"result"| F

    F -->|"returns result"| B
    B -->|"writes output"| N

    %% CI/CD and Testing support
    K ---|"triggers tests/build"| B
    L ---|"validates"| B
    M ---|"benchmarks"| B

    %% Click Events
    click A "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/__main__.py"
    click B "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/main.py"
    click C "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/sitemap_utils.py"
    click D "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/chunk_utils.py"
    click E "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/throttle.py"
    click F "https://github.com/ursisterbtw/markdown_lab/blob/main/markdown_lab/markdown_lab_rs.py"
    click G "https://github.com/ursisterbtw/markdown_lab/blob/main/src/markdown_converter.rs"
    click H "https://github.com/ursisterbtw/markdown_lab/blob/main/src/html_parser.rs"
    click I "https://github.com/ursisterbtw/markdown_lab/blob/main/src/js_renderer.rs"
    click J "https://github.com/ursisterbtw/markdown_lab/blob/main/src/chunker.rs"
    click K "https://github.com/ursisterbtw/markdown_lab/tree/main/.github/workflows"
    click L "https://github.com/ursisterbtw/markdown_lab/tree/main/tests"
    click M "https://github.com/ursisterbtw/markdown_lab/tree/main/benches"

    %% Styles
    classDef external fill:#ccf,stroke:#333,stroke-width:2px;
    classDef python fill:#f9f,stroke:#333,stroke-width:2px;
    classDef rust fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef ci fill:#cfc,stroke:#333,stroke-width:2px;
    classDef aux fill:#fc9,stroke:#333,stroke-width:2px;
```
