# jmaupetit/md2pdf architecture

> Architecture diagram of the GitHub repository jmaupetit/md2pdf, 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/jmaupetit/md2pdf
- Repository: https://github.com/jmaupetit/md2pdf

## Overview

##### Project type and purpose
- This is a Python-based command-line tool and library (“md2pdf”) whose sole responsibility is to take Markdown input (file or raw text), render it via a Markdown-to-HTML engine and WeasyPrint, and produce a styled PDF. It also ships as a Docker image and is published on PyPI.

##### File structure
- **md2pdf/**
- __main__.py – entry point for Python invocation
- cli.py – Click (or argparse)-based CLI interface
- core.py – central conversion logic (md to HTML, HTML to PDF)
- conf.py – default settings (CSS path, extras list, base_url, etc.)
- exceptions.py – domain-specific error types
- **tests/** – unit tests for CLI and core logic
- **.github/workflows/** – CI pipelines for Docker image build and Python package tests
- Dockerfile, Makefile, pyproject.toml – build, package and release configuration

##### README for additional insights
- Shows three user-visible interfaces: `pip install md2pdf` for library/API use, `md2pdf` for CLI use, and `docker run jmaupetit/md2pdf` for container use.
- Emphasizes external dependency WeasyPrint’s installation.
- Documents primary function signatures, flags, and default behavior.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User["User"]:::frontend

    %% User Interfaces
    subgraph "User Interfaces"
        CLI["cli.py"]:::frontend
        API["__main__.py"]:::frontend
        Docker["Docker Container"]:::frontend
    end

    %% Configuration & Error Handling
    subgraph "Internal Modules"
        Conf["conf.py"]:::internal
        Core["core.md2pdf()"]:::internal
        Exceptions["exceptions.py"]:::internal
    end

    %% External Services
    subgraph "External Dependencies"
        MDParser["markdown2"]:::external
        WeasyPrint["WeasyPrint"]:::external
    end

    %% I/O
    subgraph "File I/O"
        Input[".md file or raw text"]:::external
        Output[".pdf file"]:::external
    end

    %% CI/CD & Release
    subgraph "CI/CD & Release" 
        GH_Py["python-package.yml"]:::devops
        GH_Dock["docker-image.yml"]:::devops
        PyProj["pyproject.toml"]:::devops
        Make["Makefile"]:::devops
        TestsCore["tests/test_core.py"]:::devops
        TestsCLI["tests/test_cli.py"]:::devops
        Assets["tests/assets"]:::devops
        Defaults["tests/defaults.py"]:::devops
    end

    %% Data Flows
    User -->|runs| CLI
    User -->|imports| API
    User -->|runs| Docker

    Docker -->|invokes| CLI

    CLI -->|reads defaults| Conf
    API -->|reads defaults| Conf

    CLI -->|calls| Core
    API -->|calls| Core

    Input -->|provides markdown| Core
    Conf -->|provides CSS/extras| Core

    Core -->|parses markdown| MDParser
    Core -->|renders PDF| WeasyPrint
    Core -->|raises errors| Exceptions

    Exceptions -->|caught by| CLI
    Exceptions -->|caught by| API

    Core -->|produces| Output

    %% CI/CD flows
    GH_Py -->|runs tests| TestsCore
    GH_Py -->|runs tests| TestsCLI
    GH_Py -->|uses fixtures| Assets
    GH_Py -->|uses fixtures| Defaults
    GH_Py -->|publishes| PyProj

    GH_Dock -->|builds image| Docker
    GH_Dock -->|uses| Docker

    %% Click Events
    click CLI "https://github.com/jmaupetit/md2pdf/blob/main/md2pdf/cli.py"
    click API "https://github.com/jmaupetit/md2pdf/blob/main/md2pdf/__main__.py"
    click Core "https://github.com/jmaupetit/md2pdf/blob/main/md2pdf/core.py"
    click Conf "https://github.com/jmaupetit/md2pdf/blob/main/md2pdf/conf.py"
    click Exceptions "https://github.com/jmaupetit/md2pdf/blob/main/md2pdf/exceptions.py"
    click Docker "https://github.com/jmaupetit/md2pdf/tree/main/Dockerfile"
    click PyProj "https://github.com/jmaupetit/md2pdf/blob/main/pyproject.toml"
    click Make "https://github.com/jmaupetit/md2pdf/tree/main/Makefile"
    click GH_Py "https://github.com/jmaupetit/md2pdf/blob/main/.github/workflows/python-package.yml"
    click GH_Dock "https://github.com/jmaupetit/md2pdf/blob/main/.github/workflows/docker-image.yml"
    click TestsCore "https://github.com/jmaupetit/md2pdf/blob/main/tests/test_core.py"
    click TestsCLI "https://github.com/jmaupetit/md2pdf/blob/main/tests/test_cli.py"
    click Assets "https://github.com/jmaupetit/md2pdf/tree/main/tests/assets"
    click Defaults "https://github.com/jmaupetit/md2pdf/blob/main/tests/defaults.py"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9,stroke-width:1px
    classDef internal fill:#E8F5E9,stroke:#A5D6A7,stroke-width:1px
    classDef external fill:#FFF3E0,stroke:#FFCC80,stroke-width:1px
    classDef devops fill:#F3E5F5,stroke:#CE93D8,stroke-width:1px
```
