# vishal7090/md-generator architecture

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

- Interactive diagram: https://gitdiagram.com/vishal7090/md-generator
- Repository: https://github.com/vishal7090/md-generator

## Overview

1. This repository is a multi-format document conversion platform packaged as a single Python distribution, `mdengine`, with the import namespace `md_generator`. Its core purpose is to turn different source document types into Markdown plus related artifacts such as extracted images, tables, manifests, and ZIP bundles.

2. The architecture is organized by input format, not by delivery channel. The main format subsystems live under `src/md_generator/` as separate packages for `pdf`, `word`, `ppt`, `xlsx`, `image`, `text`, and `archive`. Each subsystem has its own converter logic, option model, and often its own API layer, while sharing the same top-level packaging and runtime.

3. There are three primary execution surfaces over the same conversion engines:
   - CLI entry points like `md-pdf`, `md-word`, `md-ppt`, etc.
   - FastAPI HTTP services under each format’s `api` package.
   - MCP servers, either embedded in the HTTP app or run as standalone processes.
   The CLI, API, and MCP layers are thin wrappers around the same in-process conversion functions.

4. The shared data flow is consistent across formats: input file or upload enters a format-specific front door, passes through parsing/extraction logic, then a markdown emitter or artifact writer produces output files. For larger conversions, the output is often not just a `.md` file but an artifact directory or ZIP bundle containing the Markdown plus extracted assets and metadata.

5. The PDF pipeline is centered on extraction and emission. `pdf/pdf_extract.py` and `pdf/md_emit.py` suggest a two-stage flow: parse PDF content, then render Markdown. The API path supports sync and async conversion jobs, with downloadable results, which implies heavier jobs can be offloaded and retrieved later.

6. The Word subsystem is more document-structure oriented. It exposes converter logic, per-request job handling for API usage, artifact management, and a dedicated `settings.py`. The README and file layout indicate DOCX conversion produces Markdown and may also expose extracted images or related assets. There is also a smaller `api/convert_util.py` used to bridge API-facing requests to the conversion core.

7. The PowerPoint subsystem has the richest artifact model. It includes embedded media extraction, OOXML media handling, post-processing of extracted assets, and vendorized converters borrowed for PDF and Word-style Markdown conversion inside slides. This points to a pipeline that converts slide content, extracts tables/images/media, and then organizes them into a structured artifact directory.

8. Excel conversion is built differently from the document converters. It has a dedicated `converter_core.py`, `excel_reader.py`, `markdown_emitter.py`, and `convert_config.py`, suggesting a more tabular, sheet-oriented pipeline. The output can be Markdown and CSV-related artifacts, with the API package named `app.py` rather than `main.py`, but it follows the same service pattern.

9. The image subsystem is OCR-centric and backend-pluggable. It includes multiple OCR backends (`easyocr`, `paddle`, `tesseract`) behind a common backend interface, along with I/O utilities and `emit.py`. This subsystem is designed to support different OCR engines depending on installed extras and runtime options, which is a key architectural boundary.

10. The text subsystem handles plain text, JSON, and XML as structured text sources. Its split emitters (`md_emit_txt.py`, `md_emit_json.py`, `md_emit_xml.py`) and format detection module indicate that the conversion path first identifies the input type and then renders it using a format-specific Markdown strategy.

11. The archive subsystem is a recursive orchestration layer. ZIP inputs are unpacked, inspected, and then dispatched to the appropriate converter for nested office documents, PDFs, images, or text files. This is why the README emphasizes installing corresponding extras when archives contain nested formats: the archive engine is a coordinator over the other subsystems rather than a standalone extractor.

12. The API layer is standardized but per-format configurable. Each service uses its own environment-variable prefix for limits, temp directories, and CORS settings, and most expose `POST /convert/sync`, async job creation, job status, and result download endpoints. This implies a common request lifecycle with a format-specific settings boundary.

13. MCP support is a parallel integration channel for agentic clients. Some formats mount MCP on the same FastAPI server at `/mcp`, while others provide standalone MCP server modules. This is architecturally separate from the conversion core but uses the same underlying converter functions.

14. The repository is intentionally split between `src/md_generator/` and legacy `*-to-md/` folders. The `src` tree is the real library and runtime source, while the sibling folders mostly hold tests, fixtures, thin `converter.py` shims, and some helper launch scripts. That separation matters for diagrams: conversion logic lives in `src`, while the legacy folders are integration and compatibility surfaces.

15. Dependency boundaries are enforced through extras in `pyproject.toml` and the per-format `requirements*.txt` files. Heavy dependencies such as OCR engines, FastAPI, or MCP libraries are optional and only needed for the corresponding subsystem. This keeps the base package lightweight and makes format support composable rather than monolithic.

16. For an architecture diagram, the key nodes are: source document/file input, format-specific CLI/API/MCP entry points, the conversion core per format, asset extraction/emission components, and output targets such as Markdown files, artifact directories, ZIP bundles, or async job downloads. The main cross-cutting concern is that all front ends converge on the same in-process converters, while each format owns its own parsing, extraction, and output conventions.

Main entry points: [`src/md_generator/archive/convert_impl.py`](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/archive/convert_impl.py) (Archive core), [`src/md_generator/__init__.py`](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/__init__.py) (md_generator), [`src/md_generator/pdf/converter.py`](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/converter.py) (PDF core), [`src/md_generator/ppt/converter.py`](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/converter.py) (PPT core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_src_runtime["src/md_generator"]
  node_md_generator_pkg["md_generator<br/>python package<br/>[__init__.py]"]
  node_output_artifacts[("Outputs<br/>artifacts")]
  node_pdf_api["PDF API<br/>service entry<br/>[main.py]"]
  node_pdf_converter["PDF core<br/>pipeline<br/>[converter.py]"]
  node_pdf_extract["PDF extract<br/>extractor<br/>[pdf_extract.py]"]
  node_pdf_emit["PDF emit<br/>renderer<br/>[md_emit.py]"]
  node_word_api["Word API<br/>service entry<br/>[main.py]"]
  node_word_converter["Word core<br/>pipeline<br/>[converter.py]"]
  node_word_artifact[("Word artifact<br/>artifact writer<br/>[artifact.py]")]
  node_ppt_api["PPT API<br/>service entry<br/>[main.py]"]
  node_ppt_converter["PPT core<br/>pipeline<br/>[converter.py]"]
  node_ppt_extract["PPT extract<br/>extractor"]
  node_ppt_post["PPT post<br/>asset postprocess<br/>[post_assets.py]"]
  node_xlsx_api["XLSX API<br/>service entry<br/>[app.py]"]
  node_xlsx_core["XLSX core<br/>pipeline<br/>[converter_core.py]"]
  node_xlsx_reader["XLSX read<br/>reader<br/>[excel_reader.py]"]
  node_xlsx_emit["XLSX emit<br/>renderer"]
  node_image_api["Image API<br/>service entry<br/>[main.py]"]
  node_image_core["Image core<br/>pipeline<br/>[converter.py]"]
  node_image_backends{{"OCR backends<br/>backend pool<br/>[base.py]"}}
  node_image_emit["Image emit<br/>renderer<br/>[emit.py]"]
  node_text_api["Text API<br/>service entry<br/>[main.py]"]
  node_text_detect["Text detect<br/>classifier<br/>[format_detect.py]"]
  node_text_emitters["Text emitters<br/>renderer set<br/>[md_emit_txt.py]"]
  node_archive_api["Archive API<br/>service entry<br/>[main.py]"]
  node_archive_core["Archive core<br/>orchestrator<br/>[convert_impl.py]"]
end

subgraph group_legacy_surfaces["Legacy wrappers"]
  node_legacy_wrappers["Legacy CLIs<br/>compatibility layer"]
end

node_md_generator_pkg -->|"contains"| node_pdf_api
node_md_generator_pkg -->|"contains"| node_word_api
node_md_generator_pkg -->|"contains"| node_ppt_api
node_md_generator_pkg -->|"contains"| node_xlsx_api
node_md_generator_pkg -->|"contains"| node_image_api
node_md_generator_pkg -->|"contains"| node_text_api
node_md_generator_pkg -->|"contains"| node_archive_api
node_legacy_wrappers -->|"wraps"| node_pdf_converter
node_legacy_wrappers -->|"wraps"| node_word_converter
node_legacy_wrappers -->|"wraps"| node_ppt_converter
node_legacy_wrappers -->|"wraps"| node_xlsx_core
node_legacy_wrappers -->|"wraps"| node_image_core
node_legacy_wrappers -->|"wraps"| node_text_detect
node_legacy_wrappers -->|"wraps"| node_archive_core
node_pdf_api -->|"dispatches"| node_pdf_converter
node_pdf_converter -->|"parses"| node_pdf_extract
node_pdf_converter -->|"renders"| node_pdf_emit
node_pdf_converter -->|"writes"| node_output_artifacts
node_word_api -->|"dispatches"| node_word_converter
node_word_converter -->|"assembles"| node_word_artifact
node_word_artifact -->|"writes"| node_output_artifacts
node_ppt_api -->|"dispatches"| node_ppt_converter
node_ppt_converter -->|"extracts"| node_ppt_extract
node_ppt_converter -->|"postprocesses"| node_ppt_post
node_ppt_converter -->|"writes"| node_output_artifacts
node_xlsx_api -->|"dispatches"| node_xlsx_core
node_xlsx_core -->|"reads"| node_xlsx_reader
node_xlsx_core -->|"renders"| node_xlsx_emit
node_xlsx_core -->|"writes"| node_output_artifacts
node_image_api -->|"dispatches"| node_image_core
node_image_core -->|"selects"| node_image_backends
node_image_core -->|"renders"| node_image_emit
node_image_emit -->|"writes"| node_output_artifacts
node_text_api -->|"dispatches"| node_text_detect
node_text_detect -->|"routes"| node_text_emitters
node_text_emitters -->|"writes"| node_output_artifacts
node_archive_api -->|"dispatches"| node_archive_core
node_archive_core -->|"dispatches"| node_pdf_converter
node_archive_core -->|"dispatches"| node_word_converter
node_archive_core -->|"dispatches"| node_ppt_converter
node_archive_core -->|"dispatches"| node_xlsx_core
node_archive_core -->|"dispatches"| node_image_core
node_archive_core -->|"dispatches"| node_text_detect
node_archive_core -->|"writes"| node_output_artifacts

click node_md_generator_pkg "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/__init__.py"
click node_pdf_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/api/main.py"
click node_pdf_converter "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/converter.py"
click node_pdf_extract "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/pdf_extract.py"
click node_pdf_emit "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/md_emit.py"
click node_word_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/api/main.py"
click node_word_converter "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/converter.py"
click node_word_artifact "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/artifact.py"
click node_ppt_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/api/main.py"
click node_ppt_converter "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/converter.py"
click node_ppt_extract "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/embedded_extract.py"
click node_ppt_post "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/post_assets.py"
click node_xlsx_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/api/app.py"
click node_xlsx_core "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/converter_core.py"
click node_xlsx_reader "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/excel_reader.py"
click node_xlsx_emit "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/markdown_emitter.py"
click node_image_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/api/main.py"
click node_image_core "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/converter.py"
click node_image_backends "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/backends/base.py"
click node_image_emit "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/emit.py"
click node_text_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/api/main.py"
click node_text_detect "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/format_detect.py"
click node_text_emitters "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/md_emit_txt.py"
click node_archive_api "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/archive/api/main.py"
click node_archive_core "https://github.com/vishal7090/md-generator/blob/main/src/md_generator/archive/convert_impl.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_md_generator_pkg,node_output_artifacts,node_pdf_api,node_pdf_converter,node_pdf_extract,node_pdf_emit,node_word_api,node_word_converter,node_word_artifact,node_ppt_api,node_ppt_converter,node_ppt_extract,node_ppt_post,node_xlsx_api,node_xlsx_core,node_xlsx_reader,node_xlsx_emit,node_image_api,node_image_core,node_image_backends,node_image_emit,node_text_api,node_text_detect,node_text_emitters,node_archive_api,node_archive_core toneBlue
class node_legacy_wrappers toneAmber
```

## Components

### src/md_generator

Primary library and runtime source tree

- [md_generator](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/__init__.py): python package · Top-level library namespace for all converters · `src/md_generator/__init__.py`
- **Outputs**: artifacts · Markdown files, extracted assets, ZIP bundles, and job downloads
- [PDF API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/api/main.py): service entry · HTTP front door for PDF conversion and job retrieval · `src/md_generator/pdf/api/main.py`
- [PDF core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/converter.py): pipeline · Coordinates PDF extraction and Markdown emission · `src/md_generator/pdf/converter.py`
- [PDF extract](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/pdf_extract.py): extractor · Parses PDF content and prepares structured extraction data · `src/md_generator/pdf/pdf_extract.py`
- [PDF emit](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/pdf/md_emit.py): renderer · Renders extracted PDF content into Markdown output · `src/md_generator/pdf/md_emit.py`
- [Word API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/api/main.py): service entry · HTTP front door for DOCX conversion and job handling · `src/md_generator/word/api/main.py`
- [Word core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/converter.py): pipeline · Document-structure converter for Word inputs · `src/md_generator/word/converter.py`
- [Word artifact](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/word/artifact.py): artifact writer · Builds Markdown plus extracted assets and related package output · `src/md_generator/word/artifact.py`
- [PPT API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/api/main.py): service entry · HTTP front door for slide conversion and jobs · `src/md_generator/ppt/api/main.py`
- [PPT core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/converter.py): pipeline · Coordinates slide parsing, extraction, and artifact assembly · `src/md_generator/ppt/converter.py`
- [PPT extract](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/embedded_extract.py): extractor · Extracts embedded media and OOXML-backed slide assets · `src/md_generator/ppt/embedded_extract.py`
- [PPT post](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/ppt/post_assets.py): asset postprocess · Normalizes extracted media, tables, and bundled assets · `src/md_generator/ppt/post_assets.py`
- [XLSX API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/api/app.py): service entry · HTTP front door for spreadsheet conversion · `src/md_generator/xlsx/api/app.py`
- [XLSX core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/converter_core.py): pipeline · Sheet-oriented conversion engine · `src/md_generator/xlsx/converter_core.py`
- [XLSX read](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/excel_reader.py): reader · Loads workbook and sheet data for conversion · `src/md_generator/xlsx/excel_reader.py`
- [XLSX emit](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/xlsx/markdown_emitter.py): renderer · Produces Markdown and CSV-oriented output · `src/md_generator/xlsx/markdown_emitter.py`
- [Image API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/api/main.py): service entry · HTTP front door for OCR-based image conversion · `src/md_generator/image/api/main.py`
- [Image core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/converter.py): pipeline · Coordinates OCR backend selection and emission · `src/md_generator/image/converter.py`
- [OCR backends](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/backends/base.py): backend pool · Pluggable OCR engines behind a shared interface · `src/md_generator/image/backends/base.py`
- [Image emit](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/image/emit.py): renderer · Writes Markdown and artifact outputs for image OCR results · `src/md_generator/image/emit.py`
- [Text API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/api/main.py): service entry · HTTP front door for plain text, JSON, and XML conversion · `src/md_generator/text/api/main.py`
- [Text detect](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/format_detect.py): classifier · Detects structured text input type before rendering · `src/md_generator/text/format_detect.py`
- [Text emitters](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/text/md_emit_txt.py): renderer set · Format-specific Markdown emitters for text, JSON, and XML · `src/md_generator/text/md_emit_txt.py`
- [Archive API](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/archive/api/main.py): service entry · HTTP front door for recursive archive conversion · `src/md_generator/archive/api/main.py`
- [Archive core](https://github.com/vishal7090/md-generator/blob/main/src/md_generator/archive/convert_impl.py): orchestrator · Unpacks ZIP inputs and dispatches nested files to the right converter · `src/md_generator/archive/convert_impl.py`

### Legacy wrappers

Compatibility folders and thin entrypoints around the shared source tree

- **Legacy CLIs**: compatibility layer · Thin repo-root converter shims and launch scripts for format-specific entrypoints

## Connections

- md_generator → PDF API: contains · Top-level package exposes PDF runtime
- md_generator → Word API: contains · Top-level package exposes Word runtime
- md_generator → PPT API: contains · Top-level package exposes PowerPoint runtime
- md_generator → XLSX API: contains · Top-level package exposes spreadsheet runtime
- md_generator → Image API: contains · Top-level package exposes image OCR runtime
- md_generator → Text API: contains · Top-level package exposes structured text runtime
- md_generator → Archive API: contains · Top-level package exposes archive runtime
- Legacy CLIs → PDF core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Word core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → PPT core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → XLSX core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Image core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Text detect: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Archive core: wraps · Repo-root shims invoke the shared converters
- PDF API → PDF core: dispatches · HTTP layer delegates to in-process conversion
- PDF core → PDF extract: parses · Conversion begins with PDF extraction
- PDF core → PDF emit: renders · Extracted PDF data is turned into Markdown
- PDF core → Outputs: writes · May produce Markdown plus bundled artifacts
- Word API → Word core: dispatches · HTTP layer delegates to in-process conversion
- Word core → Word artifact: assembles · Word conversion builds artifact bundles
- Word artifact → Outputs: writes · DOCX output becomes Markdown and extracted assets
- PPT API → PPT core: dispatches · HTTP layer delegates to in-process conversion
- PPT core → PPT extract: extracts · Slides are parsed for embedded media and content
- PPT core → PPT post: postprocesses · Extracted assets are normalized and organized
- PPT core → Outputs: writes · Produces Markdown plus artifact directory or ZIP bundle
- XLSX API → XLSX core: dispatches · HTTP layer delegates to in-process conversion
- XLSX core → XLSX read: reads · Workbook data is loaded before rendering
- XLSX core → XLSX emit: renders · Sheet data is emitted as Markdown or CSV-related output
- XLSX core → Outputs: writes · Spreadsheet conversion can produce files and logs
- Image API → Image core: dispatches · HTTP layer delegates to in-process conversion
- Image core → OCR backends: selects · OCR backend is chosen by runtime options and extras
- Image core → Image emit: renders · OCR results are emitted to Markdown and assets
- Image emit → Outputs: writes · Image OCR output may include extracted artifacts
- Text API → Text detect: dispatches · HTTP layer delegates to format detection and conversion
- Text detect → Text emitters: routes · Input type determines which Markdown emitter is used
- Text emitters → Outputs: writes · Text, JSON, and XML render to Markdown output
- Archive API → Archive core: dispatches · HTTP layer delegates to recursive archive orchestration
- Archive core → PDF core: dispatches · Nested PDFs are sent to the PDF pipeline
- Archive core → Word core: dispatches · Nested Word files are sent to the Word pipeline
- Archive core → PPT core: dispatches · Nested presentations are sent to the PPT pipeline
- Archive core → XLSX core: dispatches · Nested spreadsheets are sent to the XLSX pipeline
- Archive core → Image core: dispatches · Nested images are sent to the OCR pipeline
- Archive core → Text detect: dispatches · Nested text-like files are sent to the text pipeline
- Archive core → Outputs: writes · Archive conversion coordinates final Markdown and bundles
