# thanhphamtmu/word2pdf-batch architecture

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

- Interactive diagram: https://gitdiagram.com/thanhphamtmu/word2pdf-batch
- Repository: https://github.com/thanhphamtmu/word2pdf-batch

## Overview

##### Project type and purpose
- This is a single-process, CLI batch-conversion tool written in Python.
- It scans a user-supplied directory for Word documents and images, normalizes filenames, groups related images, converts each group or document to PDF, and writes outputs to separate folders.

1 → 2: User invokes the script with a folder path.
2 → 3: Scanner produces normalized file list → Prefix Grouper builds batches.
3 → 4 and 3 → 5:
- Word files go to Word Converter.
- Image groups go to Image Converter.
4 & 5 → 6: Converted intermediate PDFs are saved into `converted_tmp`.
6 → 7: Finalize or move PDFs into `converted_pdf`.

##### Architectural patterns & design principles
- Pipeline architecture: each stage performs a single responsibility.
- Separation of concerns: file scanning, grouping, conversion, and storage are distinct.
- External-dependency isolation: conversion modules encapsulate calls to COM or PIL.

##### Technologies & frameworks
- Python 3.8+
- `docx2pdf` library (depends on MS Word COM)
- `Pillow` (PIL fork) for image handling
- Standard `os`, `shutil`, `re` modules for filesystem and regex operations

##### Essential elements
- Notes: grouping rules, temp vs final paths.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    CLI["CLI / User Input"]:::core
    Scanner["File Scanner & Normalizer"]:::core
    Grouper["Prefix Grouper"]:::core
    WordConv["Word Converter Module"]:::core
    ImgConv["Image Converter Module"]:::core

    %% Storage
    Temp["converted_tmp"]:::storage
    Output["converted_pdf"]:::storage

    %% External Dependencies
    ExDeps["External Dependencies"]:::external

    %% Project Files
    subgraph "Project Files"
        GitIgnore[".gitignore"]:::external
        README["README.md"]:::external
        Requirements["requirements.txt"]:::external
    end

    %% Data Flow
    CLI -->|"source folder path"| Scanner
    Scanner -->|".doc/.docx & images list"| Grouper
    Grouper -->|"word file batches"| WordConv
    Grouper -->|"image batches"| ImgConv
    WordConv -->|".pdf files"| Temp
    ImgConv -->|".pdf files"| Temp
    Temp -->|"finalize PDFs"| Output

    %% External Dependencies Flow
    ExDeps -->|"docx2pdf & Pillow"| WordConv
    ExDeps -->|"docx2pdf & Pillow"| ImgConv

    %% Click Events
    click CLI "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click Scanner "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click Grouper "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click WordConv "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click ImgConv "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click Temp "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click Output "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/word2pdf-batch.py"
    click ExDeps "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/requirements.txt"
    click GitIgnore "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/.gitignore"
    click README "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/README.md"
    click Requirements "https://github.com/thanhphamtmu/word2pdf-batch/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef storage fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px;
```
