# spectronp/sizr architecture

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

- Interactive diagram: https://gitdiagram.com/spectronp/sizr
- Repository: https://github.com/spectronp/sizr

## Overview

##### Project Type and Purpose
- Project Type: Command-line tool (CLI) written in Go.
- Purpose: It calculates the cumulative size of package dependencies that become removable once a target package is deleted. The tool focuses on displaying packages in descending order based on their removable size.
- Use Cases: Running the tool to list high-impact packages, interacting with the package database, and integrating with package manager scripts particularly for Pacman (with possible future support for Apt).

##### File Structure
- Top-Level Files: Notice the presence of Makefile, LICENSE, README, .editorconfig, and main.go, which indicate a typical Go project with a clear entry point.
- Core Directories:
- data: Contains data handling functions (data.go, data_test.go) likely related to fetching and processing package size data.
- db: Includes code to interact with a database (db.go, db_test.go) – this likely manages the internal package database that tracks package dependencies.
- types: Provides core type definitions.
- utils: Contains utility functions for generic operations.
- vars: Holds global variables or configuration settings.
- scripts: Contains system and package manager-specific scripts (especially for Pacman). These scripts (e.g., get-all.sh, info.sh) likely fetch package details from the system.
- tests: Contains helper code and output files for running integration tests, plus scripts to wrap test execution.
- Configuration & Build: The Makefile, go.mod, and go.sum files are present to manage dependencies and build processes.

##### Readme Insights
- The README describes the tool’s usage, installation, dependencies (notably jq), and the process for loading package records on first run.
- Dependency on system permission (user being in the "wheel" group) and the interaction with external package managers like Pacman.

##### Putting It All Together
- Start from the top with the CLI interface and branch into the core processing modules.
- Recursive data processing flow that calculates sizes and the interactions with the database.
- Separate clusters that house the external Pacman scripts and note how these scripts communicate with the main application.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI (main.go)"]:::cli
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        DP["Data Processor (data/data.go)"]:::core
        DB["Database Handler (db/db.go)"]:::core
        subgraph "Business Logic Components"
            TD["Type Definitions (types/types.go)"]:::core
            UF["Utility Functions (utils/utils.go)"]:::core
            GC["Global Config (vars/vars.go)"]:::core
        end
    end

    %% External Integration
    subgraph "External Integration"
        PI["Pacman Integration (scripts/pacman)"]:::external
        GA["get-all.sh (scripts/pacman/get-all.sh)"]:::external
        IS["info.sh (scripts/pacman/info.sh)"]:::external
        JQ["jq (JSON Processor)"]:::external
    end

    %% Testing Layer
    subgraph "Testing"
        TEST["Testing Module (tests)"]:::test
    end

    %% Connections
    CLI -->|"initiates"| DP
    DP -->|"reads/writes"| DB
    DP -->|"uses"| TD
    DP -->|"uses"| UF
    DP -->|"uses"| GC
    DP -->|"calls"| PI
    PI -->|"runs"| GA
    PI -->|"runs"| IS
    PI -->|"processes"| JQ
    TEST ---|"validates"| DP
    TEST ---|"validates"| DB
    TEST ---|"verifies"| PI

    %% Click Events
    click CLI "https://github.com/spectronp/sizr/blob/main/main.go"
    click DP "https://github.com/spectronp/sizr/blob/main/data/data.go"
    click DB "https://github.com/spectronp/sizr/blob/main/db/db.go"
    click TD "https://github.com/spectronp/sizr/blob/main/types/types.go"
    click UF "https://github.com/spectronp/sizr/blob/main/utils/utils.go"
    click GC "https://github.com/spectronp/sizr/blob/main/vars/vars.go"
    click PI "https://github.com/spectronp/sizr/tree/main/scripts/pacman"
    click GA "https://github.com/spectronp/sizr/blob/main/scripts/pacman/get-all.sh"
    click IS "https://github.com/spectronp/sizr/blob/main/scripts/pacman/info.sh"
    click TEST "https://github.com/spectronp/sizr/tree/main/tests"

    %% Styles
    classDef cli fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef external fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef test fill:#90caf9,stroke:#333,stroke-width:2px;
```
