# leviborodenko/primify architecture

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

- Interactive diagram: https://gitdiagram.com/leviborodenko/primify
- Repository: https://github.com/leviborodenko/primify

## Overview

##### Main Components
- CLI Interface – Represented by the src/primify/cli.py module. This is the entry point for users invoking the command-line tool.
- Core Library – Built around the PrimeImage class in src/primify/base.py. This class encapsulates the image transformation procedures.
- Prime Search Module – Found in src/primify/prime_finder.py, this module handles prime testing and adjustment of the number until a prime is obtained.

##### Processing Pipeline
- Followed by “Image Enhancement” (edge enhancement, smoothing).
- Then, “Grey-scale Conversion” leading into “Quantisation” (reducing the range to 5 to 10 levels).
- Next, a “Mapping to Digits” stage where each quantised level translates into a digit.
- Finally, incorporate the “Prime Searching and Tweaking” module (using the Baillie–PSW test and other prime-finding logic). The output is the prime number that retains the image’s structure.

##### Relationships and Data Flow
- Dependencies between modules. For example, the CLI receives parameters (image path, max-digits, etc.) and passes them to the PrimeImage class, which then orchestrates the image processing pipeline and calls the prime_finder module.
- How the output (a prime number that “looks like” the source image) is generated and either returned to the CLI for display or saved to a file.

##### Architectural Patterns and Design Principles
- Separation of concerns: splitting the CLI input handling from the actual processing logic.
- Modular design: each processing stage (resizing, enhancement, mapping, prime testing) is distinct and can potentially be unit-tested (as seen in the tests folder).
- That the design is essentially a pipeline, with sequential processing steps feeding into the next stage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    subgraph "User Interaction"
        CLI["CLI Interface"]:::ui
    end

    %% Processing Engine Layer
    subgraph "Processing Engine"
        CORE["Core Processor (PrimeImage)"]:::process
        subgraph "Image Processing Pipeline"
            INPUT["Image Input"]:::pipeline
            RESIZE["Resize Image"]:::pipeline
            ENHANCE["Image Enhancement"]:::pipeline
            GREYSCALE["Grey-scale Conversion"]:::pipeline
            QUANT["Quantisation"]:::pipeline
            MAPPING["Mapping to Digits"]:::pipeline
        end
        PRIME["Prime Search Module"]:::primeSearch
        OUTPUT["Final Output: Prime Number"]:::process
    end

    %% Supporting Components
    subgraph "Supporting Components"
        TESTS["Tests"]:::support
        DOCS["Docs"]:::support
        EXAMPLES["Examples"]:::support
    end

    %% Connections - Data Flow
    CLI -->|"input_params"| CORE
    CORE -->|"load_image"| INPUT
    INPUT -->|"raw_image"| RESIZE
    RESIZE -->|"resized_image"| ENHANCE
    ENHANCE -->|"enhanced_image"| GREYSCALE
    GREYSCALE -->|"grey_image"| QUANT
    QUANT -->|"levels"| MAPPING
    MAPPING -->|"digit_sequence"| PRIME
    PRIME -->|"validated_prime"| OUTPUT

    %% Click Events
    click CLI "https://github.com/leviborodenko/primify/blob/refactor/src/primify/cli.py"
    click CORE "https://github.com/leviborodenko/primify/blob/refactor/src/primify/base.py"
    click PRIME "https://github.com/leviborodenko/primify/blob/refactor/src/primify/prime_finder.py"
    click TESTS "https://github.com/leviborodenko/primify/tree/refactor/tests"
    click DOCS "https://github.com/leviborodenko/primify/tree/refactor/docs"
    click EXAMPLES "https://github.com/leviborodenko/primify/tree/refactor/examples"

    %% Style Definitions
    classDef ui fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef process fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef primeSearch fill:#f08080,stroke:#333,stroke-width:2px;
    classDef support fill:#d3d3d3,stroke:#333,stroke-width:2px;
```
