# confuzu/civitai_image_grabber architecture

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

- Interactive diagram: https://gitdiagram.com/confuzu/civitai_image_grabber
- Repository: https://github.com/confuzu/civitai_image_grabber

## Overview

- User Input → Download Manager
- Download Manager → CivitAI API
- CivitAI API → Image Processor
- Image Processor → File System Manager
- Metadata Handler → Storage System

- Download Manager → Tracking System
- Image Processor → Metadata Handler

##### Important Subsystems to Highlight

a. Tracking Mechanism:
- downloaded_images.json handler
- Download state management
- Redownload logic

b. Metadata Processing:
- Meta information extraction
- Details.txt generation
- CSV summary creation (for tag searches)

##### Technical Details
- Python 3 runtime
- File formats (JPEG/PNG)
- API interaction points
- Configuration parameters

- Multiple download modes (4 different types)
- Image quality variants
- Metadata processing
- File organization
- Download tracking
- Error handling

Keep the focus on the core functionality flows while showing how the system handles different modes of operation (interactive, command-line, and mixed mode).

Remember to indicate the extensibility points where new features could be added (like additional search modes or metadata processors) and show the error handling pathways clearly.

## Diagram (Mermaid)

```mermaid
%%{init: {'theme':'neutral'}}%%
flowchart TB
    classDef ui fill:#a8d1f0,stroke:#2980b9
    classDef core fill:#a8e6cf,stroke:#1abc9c
    classDef storage fill:#ffd3b6,stroke:#e67e22
    classDef external fill:#d7bde2,stroke:#8e44ad
    classDef file fill:#f8f9fa,stroke:#343a40

    subgraph UI["User Interface Layer"]
        CLI[("CLI Interface")]:::ui
        ArgParser["Arguments Parser"]:::ui
    end

    subgraph Core["Core Processing Layer"]
        DLManager["Download Manager"]:::core
        ImgProc["Image Processor"]:::core
        MetaHandler["Metadata Handler"]:::core
        TagProc["Tag Processor"]:::core
    end

    subgraph Storage["Storage Layer"]
        FSManager[("File System")]:::storage
        TrackSys[(Tracking System)]:::storage
    end

    subgraph External["External Integration"]
        CivitAPI["CivitAI API"]:::external
    end

    CLI --> ArgParser
    ArgParser --> DLManager
    DLManager -.-> TrackSys
    DLManager --> CivitAPI
    CivitAPI --> ImgProc
    ImgProc -.-> MetaHandler
    ImgProc --> FSManager
    MetaHandler --> FSManager
    TagProc --> DLManager

    %% Click events for component mapping
    click CLI "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/civit_image_downloader.py"
    click ArgParser "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/civit_image_downloader.py"
    click DLManager "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/civit_image_downloader.py"
    click ImgProc "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/civit_image_downloader.py"
    click MetaHandler "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/civit_image_downloader.py"
    click TagProc "https://github.com/Confuzu/CivitAI_Image_grabber/blob/main/tagnames.py"

    %% Legend
    subgraph Legend
        L1[("UI Component")]:::ui
        L2["Processing Component"]:::core
        L3[("Storage Component")]:::storage
        L4["External Service"]:::external
        L5["Data Flow"] --> L6
        L7["Dependency"] -.-> L8
    end
```
