# ik4rd/svd architecture

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

- Interactive diagram: https://gitdiagram.com/ik4rd/svd
- Repository: https://github.com/ik4rd/svd

## Overview

##### Project type and purpose
- This is an open-source, CLI-based C utility (“svd”) that compresses images via truncated Singular Value Decomposition (SVD).
- It reads an input image (any format supported by ImageMagick), converts it to PGM/PPM, performs SVD per channel or grayscale, deflates the matrix, caches singular triplets, and writes out a compressed image.

##### File structure
- Top-level files: CMakeLists.txt (build), main.c (CLI entry), README.md, LICENSE.
- / & src/: mirror each other in modules:
- cache/       – cache I/O API (cache.h, cache.c)
- core/        – CLI parser (cli.h/c), processor orchestrator (processor.h/c), utilities (utils.h/c)
- image-processor/ – convert any image to PGM/PPM, image interface, PGM/PPM parsers
- linear-algebra/ – SVD algorithm (svd.h/c)

##### README for additional insights
- Describes math behind SVD, power iteration + deflation loop.
- Project layout details exactly how modules map to folders and responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Modules
    CLI["CLI Interface"]:::io
    CORE["Core Processor"]:::processing
    IMG["Image Processor"]:::processing
    SVD["Linear-Algebra SVD Engine"]:::algorithm
    CACHE["Cache Manager"]:::algorithm
    FS[(File System)]:::storage

    %% Data and control flow
    CLI -->|"parse flags & args"| CORE
    CORE -->|"load/convert input"| IMG
    IMG -->|"matrix A"| CORE
    CORE -->|"check cache (--cache)"| CACHE
    CACHE -->|"cache hit/miss"| CORE
    CORE -->|"compute SVD"| SVD
    SVD -->|"singular triplets"| CORE
    CORE -->|"persist cache"| CACHE
    CORE -->|"reconstruct image"| IMG
    IMG -->|"writes output file"| FS
    FS -->|"input image file"| IMG

    %% Click events for source mapping
    click CLI "https://github.com/ik4rd/svd/blob/main/src/main.c"
    click CLI "https://github.com/ik4rd/svd/blob/main/src/core/cli.c"
    click CLI "https://github.com/ik4rd/svd/blob/main/include/core/cli.h"
    click CORE "https://github.com/ik4rd/svd/blob/main/src/core/processor.c"
    click CORE "https://github.com/ik4rd/svd/blob/main/include/core/processor.h"
    click CORE "https://github.com/ik4rd/svd/blob/main/src/core/utils.c"
    click CORE "https://github.com/ik4rd/svd/blob/main/include/core/utils.h"
    click IMG "https://github.com/ik4rd/svd/blob/main/src/image-processor/convert.c"
    click IMG "https://github.com/ik4rd/svd/blob/main/include/image-processor/convert.h"
    click IMG "https://github.com/ik4rd/svd/blob/main/src/image-processor/image.c"
    click IMG "https://github.com/ik4rd/svd/blob/main/include/image-processor/image.h"
    click IMG "https://github.com/ik4rd/svd/blob/main/src/image-processor/pgm-ppm-parsers/pgm.c"
    click IMG "https://github.com/ik4rd/svd/blob/main/include/image-processor/pgm-ppm-parsers/pgm.h"
    click IMG "https://github.com/ik4rd/svd/blob/main/src/image-processor/pgm-ppm-parsers/ppm.c"
    click IMG "https://github.com/ik4rd/svd/blob/main/include/image-processor/pgm-ppm-parsers/ppm.h"
    click SVD "https://github.com/ik4rd/svd/blob/main/src/linear-algebra/svd.c"
    click SVD "https://github.com/ik4rd/svd/blob/main/include/linear-algebra/svd.h"
    click CACHE "https://github.com/ik4rd/svd/blob/main/src/cache/cache.c"
    click CACHE "https://github.com/ik4rd/svd/blob/main/include/cache/cache.h"
    click FS "https://github.com/ik4rd/svd/blob/main/CMakeLists.txt"
    click FS "https://github.com/ik4rd/svd/blob/main/README.md"
    click FS "https://github.com/ik4rd/svd/tree/main/images/"

    %% Styles
    classDef io fill:#add8e6,stroke:#000,stroke-width:1px
    classDef processing fill:#90ee90,stroke:#000,stroke-width:1px
    classDef algorithm fill:#ffcc99,stroke:#000,stroke-width:1px
    classDef storage fill:#d3d3d3,stroke:#000,stroke-width:1px
```
