# hawkeyes1094/crlite-python architecture

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

- Interactive diagram: https://gitdiagram.com/hawkeyes1094/crlite-python
- Repository: https://github.com/hawkeyes1094/crlite-python

## Overview

##### Project type and purpose
- Project type: An open-source Python package that provides CRLite support by wrapping a Rust library (`crlite-clubcard`) via PyO3.
- Purpose: Allow Python developers to load and query Mozilla’s Clubcard filter files (used for efficient certificate revocation checks) through a clean Python API.

##### File structure
- Top-level:
- Cargo.toml, src/lib.rs         → Rust library crate (the PyO3 binding layer sits here).
- pyproject.toml, python/…       → Python package source (`crlite_python`), setup, and metadata.
- requirements.txt, sample.py    → Python dependencies and example usage.
- tests/test_all.py              → End-to-end tests covering both Python API and underlying Rust logic.
- .github/workflows/CI.yml       → CI pipeline building Rust, running Python tests, publishing.
- Key patterns:
- Hybrid Rust/Python codebase via PyO3.
- Clear separation: Rust core logic in `src/lib.rs`; Python wrappers in `python/crlite_python/*`.
- Build artifacts managed by Cargo (Rust) and pip/pyproject for Python.

##### README for additional insights
- Describes use of Mozilla’s Clubcard CRLite filters.
- Indicates Rust dependency (`crlite-clubcard`) and PyO3 binding approach.

a. Main components
1. Python Application Layer
2. PyO3 Binding Layer
3. Rust Library (`crlite-clubcard`)
4. External Data Source (Mozilla Clubcard filter files)
5. Build/CI System (GitHub Actions)
b. Relationships and interactions
- The Python API invokes functions in the PyO3 binding.
- PyO3 marshals data and calls into the Rust library.
- The Rust library loads/parses filter files and runs certificate lookup algorithms.
- External data (filter files) are downloaded or loaded at runtime by the Rust layer.
- CI pipeline builds Rust wheels, installs Python deps, and runs tests end to end.
c. Architectural patterns and design principles
- Language interoperability: PyO3 FFI bridging Python ↔ Rust.
- Single-responsibility: Python code handles user-facing API and packaging; Rust code handles heavy-weight filter logic.
- CI automation ensures consistency across platforms (Linux, macOS, Windows).
d. Key technologies and frameworks
- Python 3.x, setuptools/pyproject.toml
- PyO3 for FFI
- Rust, Cargo.toml for dependency management
- GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Python Layer
    subgraph "Python Layer"
        direction TB
        Sample["Python Client\n(sample.py)"]:::python
        subgraph "crlite_python Package"
            direction TB
            API["crlite.py"]:::python
            Exceptions["exceptions.py"]:::python
            Init["__init__.py"]:::python
        end
        Packaging["Packaging & Metadata\n(pyproject.toml, requirements.txt)"]:::metadata
    end

    %% Binding Layer
    Binding["PyO3 Binding Layer\n(src/lib.rs)"]:::rust

    %% Rust Library
    subgraph "Rust Library\n(crlite-clubcard)"
        direction TB
        Cargo["Cargo.toml"]:::rust
    end

    %% External Data
    Filters["Mozilla Clubcard Filters"]:::external

    %% Tests and CI
    Tests["End-to-End Tests\n(test_all.py)"]:::test
    CI["GitHub Actions CI\n(.github/workflows/CI.yml)"]:::ci

    %% Connections
    Sample -->|"uses API"| API
    API -->|"calls FFI"| Binding
    Binding -->|"invokes"| Cargo
    Cargo -->|"load_filters() / check_revoked()"| Filters
    Tests -->|"exercises API"| API
    Tests -->|"exercises Rust"| Cargo
    CI -->|"builds Rust"| Cargo
    CI -->|"installs & tests Python"| API
    CI -->|"runs tests"| Tests
    CI -->|"publishes wheel"| Packaging

    %% Click Events
    click Sample "https://github.com/hawkeyes1094/crlite-python/blob/main/sample.py"
    click API "https://github.com/hawkeyes1094/crlite-python/blob/main/python/crlite_python/crlite.py"
    click Exceptions "https://github.com/hawkeyes1094/crlite-python/blob/main/python/crlite_python/exceptions.py"
    click Init "https://github.com/hawkeyes1094/crlite-python/blob/main/python/crlite_python/__init__.py"
    click Binding "https://github.com/hawkeyes1094/crlite-python/blob/main/src/lib.rs"
    click Cargo "https://github.com/hawkeyes1094/crlite-python/blob/main/Cargo.toml"
    click Packaging "https://github.com/hawkeyes1094/crlite-python/blob/main/pyproject.toml"
    click Packaging "https://github.com/hawkeyes1094/crlite-python/blob/main/requirements.txt"
    click Tests "https://github.com/hawkeyes1094/crlite-python/blob/main/tests/test_all.py"
    click CI "https://github.com/hawkeyes1094/crlite-python/blob/main/.github/workflows/CI.yml"

    %% Styles
    classDef python fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef rust fill:#fff3e0,stroke:#e65100,color:#bf360c
    classDef external fill:#e8eaf6,stroke:#3949ab,color:#1a237e
    classDef ci fill:#fce4ec,stroke:#ad1457,color:#880e4f
    classDef test fill:#e0f2f1,stroke:#00796b,color:#004d40
    classDef metadata fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
```
