# larssjogreen/imgsnapper architecture

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

- Interactive diagram: https://gitdiagram.com/larssjogreen/imgsnapper
- Repository: https://github.com/larssjogreen/imgsnapper

## Overview

##### Main Components

a. Command Line Interface (CLI)
- Entry point through cli.js
- Command parsing and validation
- Help system

b. Browser Automation Layer
- Selenium WebDriver integration
- Chrome/Firefox driver management
- Browser instance control (headless/visible modes)

c. Image Processing
- Screenshot capture
- Image saving and naming
- Directory management

d. Task Scheduling
- Repeat/Cron functionality
- Process management (especially for Windows via killproc.bat)

##### Component Relationships

**[CLI Layer] → [Browser Automation Layer] → [Web Browsers]**
- ↓
- [Image Processing] → [File System]
- ↓
- [Task Scheduler] ← → [Process Management]

##### Specific Elements

a. External Dependencies (show as external systems):
- ChromeDriver
- GeckoDriver
- Chrome Browser
- Firefox Browser

b. Input/Output:
- Command line arguments (input)
- Screenshot/image files (output)
- Image directory structure

##### Important Flows to Highlight

a. Primary Flow:
##### File saving

b. Secondary Flow (for repeat mode):

##### Technical Details

- Node.js runtime environment
- Selenium WebDriver integration
- File system interactions
- Process management (especially for Windows)

##### Architectural Notes

- Modular design allowing for different browsers
- Separation between CLI handling and core functionality
- Async nature of browser automation
- Error handling paths

Remember to show both the synchronous (command processing) and asynchronous (browser automation and image capture) aspects of the system, as this is crucial for understanding the tool's operation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI
        CLI_ENTRY["Command Line Interface"]
        CLI_PARSE["Command Parser"]
        CLI_HELP["Help System"]
    end

    subgraph BROWSER_AUTO
        SELENIUM["Selenium WebDriver"]
        DRIVER_MGR["Driver Manager"]
        BROWSER_CTRL["Browser Controller"]
    end

    subgraph IMG_PROC
        SCREENSHOT["Screenshot Capture"]
        IMG_SAVE["Image Saver"]
        DIR_MGR["Directory Manager"]
    end

    subgraph TASK_SCHED
        SCHEDULER["Task Scheduler"]
        PROC_MGR["Process Manager"]
    end

    subgraph EXT_DEPS
        CHROME["Chrome Browser"]
        FIREFOX["Firefox Browser"]
        CHROMEDRIVER["ChromeDriver"]
        GECKODRIVER["GeckoDriver"]
    end

    subgraph FS
        FILES["File System"]
    end

    %% Relationships
    CLI_ENTRY --> CLI_PARSE
    CLI_PARSE --> CLI_HELP
    CLI_PARSE --> SELENIUM
    SELENIUM --> DRIVER_MGR
    DRIVER_MGR --> BROWSER_CTRL
    BROWSER_CTRL --> CHROME
    BROWSER_CTRL --> FIREFOX
    DRIVER_MGR --> CHROMEDRIVER
    DRIVER_MGR --> GECKODRIVER
    BROWSER_CTRL --> SCREENSHOT
    SCREENSHOT --> IMG_SAVE
    IMG_SAVE --> DIR_MGR
    DIR_MGR --> FILES
    CLI_PARSE --> SCHEDULER
    SCHEDULER --> PROC_MGR
    PROC_MGR --> BROWSER_CTRL

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef browser fill:#4CAF50,stroke:#2E7D32,color:white
    classDef fs fill:#FFC107,stroke:#FFA000,color:black
    classDef external fill:#9E9E9E,stroke:#616161,color:white

    class CLI_ENTRY,CLI_PARSE,CLI_HELP core
    class SELENIUM,DRIVER_MGR,BROWSER_CTRL core
    class SCREENSHOT,IMG_SAVE,DIR_MGR core
    class SCHEDULER,PROC_MGR core
    class CHROME,FIREFOX,CHROMEDRIVER,GECKODRIVER browser
    class FILES fs
    class EXT_DEPS external

    %% Click events
    click CLI_ENTRY "https://github.com/LarsSjogreen/imgsnapper/blob/main/cli.js"
    click PROC_MGR "https://github.com/LarsSjogreen/imgsnapper/blob/main/win/killproc.bat"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Browser Components"]:::browser
        L3["File System"]:::fs
        L4["External Dependencies"]:::external
    end
```
