# saikrishna1876/f2md architecture

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

- Interactive diagram: https://gitdiagram.com/saikrishna1876/f2md
- Repository: https://github.com/saikrishna1876/f2md

## Overview

f2md is a CLI and library for converting PDFs, DOCX files, and images into Markdown with Gemini. The main workflow accepts a file and output destination, extracts document content (or prepares an image for OCR), sends the material to the model, writes Markdown, and removes unused extracted images. The CLI also supports interactive setup and configuration; the public API exposes the same conversion function. Conversion details and these relationships are based on the excerpts and README; extraction branches are implemented within the sampled conversion module.

Main entry points: [`src/convert.ts`](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts) (Conversion workflow), [`src/cli.ts`](https://github.com/saikrishna1876/f2md/blob/main/src/cli.ts) (Interactive CLI), [`src/index.ts`](https://github.com/saikrishna1876/f2md/blob/main/src/index.ts) (Public API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and configuration"]
  node_cli["Interactive CLI<br/>[cli.ts]"]
  node_config["Setup and config<br/>[cli.ts]"]
end

subgraph group_conversion["Document conversion"]
  node_converter["Conversion workflow<br/>[convert.ts]"]
  node_pdf["PDF extraction<br/>[convert.ts]"]
  node_docx["DOCX extraction<br/>[convert.ts]"]
  node_image["Image OCR preparation<br/>[convert.ts]"]
  node_gemini["Gemini model"]
end

subgraph group_outputs["Output management"]
  node_output["Markdown and image files<br/>[convert.ts]"]
  node_cleanup["Unused image cleanup<br/>[convert.ts]"]
end

subgraph group_api["Library API"]
  node_library["Public API<br/>[index.ts]"]
end

node_user(("User"))
node_filesystem[("Local filesystem")]
node_apiuser(("Library consumer"))

node_user -->|"provides file"| node_cli
node_cli -->|"resolves config"| node_config
node_user -->|"runs setup"| node_config
node_config -->|"reads or writes config"| node_filesystem
node_cli -->|"calls convert"| node_converter
node_converter -->|"extracts PDF"| node_pdf
node_converter -->|"extracts DOCX"| node_docx
node_converter -->|"prepares image"| node_image
node_converter -->|"streams request"| node_gemini
node_converter -->|"reads input"| node_filesystem
node_converter -->|"writes Markdown"| node_output
node_converter -->|"cleans images"| node_cleanup
node_cleanup -->|"deletes unused images"| node_filesystem
node_output -->|"stores files"| node_filesystem
node_apiuser -->|"calls API"| node_library
node_library -->|"exports convert"| node_converter

click node_cli "https://github.com/saikrishna1876/f2md/blob/main/src/cli.ts"
click node_config "https://github.com/saikrishna1876/f2md/blob/main/src/cli.ts"
click node_converter "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_pdf "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_docx "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_image "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_output "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_cleanup "https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts"
click node_library "https://github.com/saikrishna1876/f2md/blob/main/src/index.ts"

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_cli,node_config,node_user toneBlue
class node_converter,node_pdf,node_docx,node_image,node_gemini,node_filesystem toneAmber
class node_output,node_cleanup toneMint
class node_library toneRose
class node_apiuser toneIndigo
```

## Components

### Entry and configuration

- [Interactive CLI](https://github.com/saikrishna1876/f2md/blob/main/src/cli.ts): `src/cli.ts`
- [Setup and config](https://github.com/saikrishna1876/f2md/blob/main/src/cli.ts): `src/cli.ts`

### Document conversion

- [Conversion workflow](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`
- [PDF extraction](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`
- [DOCX extraction](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`
- [Image OCR preparation](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`
- **Gemini model**

### Output management

- [Markdown and image files](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`
- [Unused image cleanup](https://github.com/saikrishna1876/f2md/blob/main/src/convert.ts): `src/convert.ts`

### Library API

- [Public API](https://github.com/saikrishna1876/f2md/blob/main/src/index.ts): `src/index.ts`

### Other components

- **User**
- **Local filesystem**
- **Library consumer**

## Connections

- User → Interactive CLI: provides file (evidence: `README.md`)
- Interactive CLI → Setup and config: resolves config (evidence: `src/cli.ts`)
- User → Setup and config: runs setup (evidence: `README.md`)
- Setup and config → Local filesystem: reads or writes config (evidence: `src/cli.ts`)
- Interactive CLI → Conversion workflow: calls convert (evidence: `src/cli.ts`)
- Conversion workflow → PDF extraction: extracts PDF (evidence: `src/convert.ts`)
- Conversion workflow → DOCX extraction: extracts DOCX (evidence: `src/convert.ts`)
- Conversion workflow → Image OCR preparation: prepares image (evidence: `src/convert.ts`)
- Conversion workflow → Gemini model: streams request (evidence: `src/convert.ts`)
- Conversion workflow → Local filesystem: reads input (evidence: `src/convert.ts`)
- Conversion workflow → Markdown and image files: writes Markdown (evidence: `src/convert.ts`)
- Conversion workflow → Unused image cleanup: cleans images (evidence: `src/convert.ts`)
- Unused image cleanup → Local filesystem: deletes unused images (evidence: `src/convert.ts`)
- Markdown and image files → Local filesystem: stores files (evidence: `src/convert.ts`)
- Library consumer → Public API: calls API (evidence: `README.md`)
- Public API → Conversion workflow: exports convert (evidence: `src/index.ts`)
