# visioncortex/vtracer architecture

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

- Interactive diagram: https://gitdiagram.com/visioncortex/vtracer
- Repository: https://github.com/visioncortex/vtracer

## Overview

##### Project type and purpose
- This is a multi-target vectorization tool built around a core Rust library (vtracer).
- It exposes three front ends:
- A command-line application (cmdapp)
- A Python extension via PyO3
- A Web application (webapp) compiled to WebAssembly and wrapped by JavaScript/HTML
- There is also a static documentation site in the docs/ folder.

##### File structure
- Top level:
- Cargo.toml – workspace containing the core library and possibly sub-crates
- cmdapp/ – Rust crate for the CLI and Python bindings
- webapp/ – Rust crate plus JS/HTML for the browser UI
- docs/ – prebuilt HTML/CSS/JS assets for documentation
- cmdapp/src holds modules: config.rs, converter.rs, python.rs (bindings), svg.rs
- webapp/src holds modules: canvas.rs, svg.rs, conversion pipeline (binary_image.rs, color_image.rs), utils.rs
- Build/deployment:
- GitHub Actions workflows for Python, Rust, and release
- pyproject.toml for Python packaging
- package.json and webpack.config.js for bundling the Web UI

##### README for additional insights
- Core functionality: raster→vector conversion using an O(n) tracing and clustering pipeline
- Interfaces: CLI flags, Rust library API, Python pip package, WebAssembly
- Dependencies: visioncortex core library, wasm-pack/webpack, PyO3

##### Elements
- From each front end → Core Library (indicating API calls)
- Within Core: Config → Clustering → Fitting → SVG Output
- Web UI: HTML/JS → WASM → Canvas Rendering
- Another for JS/HTML/Web assets
- Another for Python extension
- Optionally, a highlight for build/deploy flows (CI pipelines)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Adapters Layer
    subgraph "Adapters"
        direction TB
        CLI["CLI (cmdapp)"]:::rust
        PyExt["Python Extension (PyO3)"]:::python
        subgraph "Web Front End"
            direction TB
            WebAsm["WebAssembly Module"]:::rust
            JSUI["JS/HTML UI"]:::js
        end
    end

    %% Core Library
    subgraph "vtracer Core Library"
        direction TB
        CoreLib["Core Library"]:::rust
        Config["Config Module"]:::rust
        Clustering["Image Clustering"]:::rust
        Fitting["Curve Fitting"]:::rust
        SVGGen["SVG Generator"]:::rust
    end

    %% Static Docs
    Docs["Static Documentation Site"]:::static

    %% CI / Build Pipelines
    subgraph "CI / Build Pipelines"
        direction TB
        GH_Python["python.yml"]:::ci
        GH_Rust["rust.yml"]:::ci
        GH_Release["release.yml"]:::ci
    end

    %% Connections
    CLI -->|"calls API"| CoreLib
    PyExt -->|"invokes API"| CoreLib
    WebAsm -->|"calls API"| CoreLib
    CoreLib --> Config --> Clustering --> Fitting --> SVGGen
    JSUI -->|"uses WASM API"| WebAsm

    %% CI flows
    GH_Python --> CLI
    GH_Rust --> CoreLib
    GH_Release --> CLI
    GH_Release --> WebAsm
    GH_Release --> PyExt

    %% Click Events for component mapping
    click CLI "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/main.rs"
    click CoreLib "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/lib.rs"
    click Config "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/config.rs"
    click Clustering "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/converter.rs"
    click SVGGen "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/svg.rs"
    click PyExt "https://github.com/visioncortex/vtracer/blob/master/cmdapp/src/python.rs"
    click WebAsm "https://github.com/visioncortex/vtracer/blob/master/webapp/src/lib.rs"
    click JSUI "https://github.com/visioncortex/vtracer/blob/master/webapp/app/index.js"
    click Docs "https://github.com/visioncortex/vtracer/blob/master/docs/index.html"
    click GH_Python "https://github.com/visioncortex/vtracer/blob/master/.github/workflows/python.yml"
    click GH_Rust "https://github.com/visioncortex/vtracer/blob/master/.github/workflows/rust.yml"
    click GH_Release "https://github.com/visioncortex/vtracer/blob/master/.github/workflows/release.yml"

    %% Styles
    classDef rust fill:#fddfdf,stroke:#d32f2f,stroke-width:1px
    classDef python fill:#eafde7,stroke:#388e3c,stroke-width:1px
    classDef js fill:#fff0b3,stroke:#fbc02d,stroke-width:1px
    classDef static fill:#dfefff,stroke:#1976d2,stroke-width:1px
    classDef ci fill:#f0f0f0,stroke:#616161,stroke-width:1px
```
