# vikparuchuri/marker architecture

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

- Interactive diagram: https://gitdiagram.com/vikparuchuri/marker
- Repository: https://github.com/vikparuchuri/marker

## Overview

##### Main Components
- Input/Providers – Components that ingest documents in various formats. Look at the “marker/providers” directory which includes providers for PDF, image, EPUB, HTML, etc.
- Builders – These components (in “marker/builders”) generate the initial document blocks using extracted text and layouts.
- Processors – Located in “marker/processors,” these refine blocks. They handle tasks like formatting tables, handling equations, inline math, references, and OCR.
- Renderers – In “marker/renderers,” these convert processed blocks into final output formats (markdown, HTML, JSON).
- Converters – Found in “marker/converters,” the converters (e.g., PdfConverter and TableConverter) integrate the whole pipeline by orchestrating providers, builders, processors, and renderers.
- Schema – In “marker/schema,” this defines and structures the blocks and components used across the pipeline.
- LLM Services Integration – Marker supports various external LLM services (see “marker/services”) to enhance conversion accuracy when the “--use_llm” flag is enabled.
- API Server & Interactive App – Marker exposes functionality through a FastAPI-based server (marker_server.py) and an interactive Streamlit app (via marker_app.py) for real-time document conversion.
- Utility and Configuration – The project uses configuration (e.g., marker/config and pyproject.toml), logging, and utility scripts for tasks such as file conversion and benchmarking.
- Testing & Benchmarks – The “tests” and “benchmarks” directories contain unit tests and benchmark scripts that validate performance and conversion quality.

##### Relationships and Data Flow
- A top-level “Document Conversion Pipeline.” Start with the “Input” layer (Providers) where documents are ingested.
- Flow from Providers to Builders: the provider extracts raw content (text, images, layout details) that the builder then organizes into a structured document model (using schema definitions).
- Finally, Renderers take the processed document blocks and output them in different formats.
- Optionally – include branches for the LLM service: an additional feedback loop where, if “--use_llm” is specified, the document or specific blocks are sent to an LLM service (Gemini, Claude, Vertex, Ollama, or OpenAI) to enhance accuracy.
- The API Server and Interactive App are depicted as front-end interfaces that accept files and invoke the conversion pipeline.

##### Architectural Patterns and Design Principles
- Modular Pipeline Architecture – Each stage of processing (providers, builders, processors, renderers) is encapsulated in its own module, which makes the design extensible.
- Separation of Concerns – The directory structure clearly separates functionality (conversion logic from API serving, testing, and benchmarking).
- Configuration Driven – Using configuration files and parsers (e.g., marker/config/parser.py) for runtime behavior.
- Integration with External Services – Incorporate LLM services integration as an optional enhancement layer.

##### Technologies and Frameworks
- Python 3.10+, PyTorch – For deep learning models and backend inference.
- Streamlit and FastAPI – For the interactive app and server respectively.
- GitHub Actions – Indicated by the .github/workflows directory for CI/CD processes.
- Testing frameworks (pytest) are used for validating functionality.
- Various internal utilities for logging, file conversion (e.g., marker/scripts), and benchmark processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces Layer
    subgraph "User Interfaces"
        API["API Server"]:::ui
        App["Interactive App"]:::ui
    end

    %% Document Ingestion Layer
    subgraph "Document Ingestion"
        prov["Providers"]:::core
    end

    %% Conversion Pipeline
    subgraph "Document Conversion Pipeline"
        build["Builders"]:::core
        proc["Processors"]:::core
        rend["Renderers"]:::core
        conv["Converters"]:::core
        schema["Schema"]:::core
    end

    %% Optional Enhancement via LLM
    subgraph "Optional Enhancement"
        llm["LLM Services"]:::core
    end

    %% Supporting Components
    subgraph "Supporting Components"
        util["Utility & Configuration"]:::support
        pyproj["pyproject.toml"]:::support
        test["Tests"]:::support
        bench["Benchmarks"]:::support
    end

    %% Data Flow
    API --> prov
    App --> prov
    prov --> build
    build --> proc
    proc --> rend

    %% Builders use Schema
    build -->|"uses"| schema

    %% Integration managed by Converters (dotted lines)
    conv -.-> prov
    conv -.-> build
    conv -.-> proc
    conv -.-> rend
    conv -.-> schema

    %% Optional LLM enhancement loop
    proc -->|"--use_llm?"| llm
    llm -->|"enhances"| proc

    %% Output delivery back to UIs (dotted)
    rend -.-> API
    rend -.-> App

    %% Supporting components linked via configuration and testing (dotted)
    util -.-> conv
    pyproj -.-> conv
    test -.-> conv
    bench -.-> conv

    %% Click Events
    click prov "https://github.com/vikparuchuri/marker/tree/master/marker/providers"
    click build "https://github.com/vikparuchuri/marker/tree/master/marker/builders"
    click proc "https://github.com/vikparuchuri/marker/tree/master/marker/processors"
    click rend "https://github.com/vikparuchuri/marker/tree/master/marker/renderers"
    click conv "https://github.com/vikparuchuri/marker/tree/master/marker/converters"
    click schema "https://github.com/vikparuchuri/marker/tree/master/marker/schema"
    click llm "https://github.com/vikparuchuri/marker/tree/master/marker/services"
    click API "https://github.com/vikparuchuri/marker/blob/master/marker_server.py"
    click App "https://github.com/vikparuchuri/marker/blob/master/marker_app.py"
    click util "https://github.com/vikparuchuri/marker/tree/master/marker/config"
    click pyproj "https://github.com/vikparuchuri/marker/blob/master/pyproject.toml"
    click test "https://github.com/vikparuchuri/marker/tree/master/tests"
    click bench "https://github.com/vikparuchuri/marker/tree/master/benchmarks"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef ui fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef support fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
