# osnieltux/tinyrepo architecture

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

- Interactive diagram: https://gitdiagram.com/osnieltux/tinyrepo
- Repository: https://github.com/osnieltux/tinyrepo

## Overview

##### Project type and purpose
- tinyrepo is a single‐binary, command‐line Go application meant to create and manage small local APT repositories for Debian derivatives. It is not a web service or full-stack app, but rather a CLI tool with modular internal components and a few external dependencies (TOML parser, XZ decompressor, remote HTTP servers, local filesystem).

##### File structure
- Top-level Go files:
- main.go – CLI entrypoint, flag parsing, dispatch to subcommands
- config.go – definition of configuration struct, loading/saving via BurntSushi/toml
- global.go – global constants, paths, shared variables (e.g., cache location, repo root)
- package.go – logic for downloading and indexing .deb packages, generating Packages files
- utils.go – helper functions (HTTP download, decompression, file operations)
- go.mod & go.sum declare external dependencies.
- No frontend, database server, or network services beyond invoking HTTP clients.

##### README for additional insights
- Describes four main CLI actions: generate config (`-gc`), download indexes (`-di`), create local indexes (`-ci`), download packages (`-dp`).
- External interactions: reads remote “Indexes” over HTTP, decompresses `.xz`, writes local index files, downloads `.deb` packages.

##### Essential architectural elements
- Boundary between internal logic and external dependencies (remote servers, libraries)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Modules
    CLI["CLI Interface"]:::internal
    Config["Configuration Module"]:::internal
    Globals["Global Constants & Paths"]:::internal
    IdxDown["Index Downloader Module"]:::internal
    IdxBuilder["Index Builder Module"]:::internal
    PkgDown["Package Downloader Module"]:::internal

    %% Storage
    FileSys["Local Filesystem"]:::storage

    %% External Services & Libraries
    ExtRepos["External Debian Repos"]:::external
    LibToml["BurntSushi/toml"]:::external
    LibXZ["github.com/ulikunitz/xz"]:::external
    GoMod["go.mod"]:::external
    GoSum["go.sum"]:::external
    Readme["README.md"]:::external

    %% Flows
    CLI -->|"parses flags"| Globals
    CLI -->|"uses flags"| Config
    CLI -->|"shows commands"| Readme

    Config -->|"loads/saves config.toml"| FileSys
    Config -->|"uses"| LibToml

    CLI -->|"-di"| IdxDown
    IdxDown -->|"fetch Packages.xz"| ExtRepos
    IdxDown -->|"decompress data"| LibXZ
    IdxDown -->|"raw index data"| IdxBuilder

    CLI -->|"-ci"| IdxBuilder
    IdxBuilder -->|"writes index files"| FileSys

    CLI -->|"-dp"| PkgDown
    PkgDown -->|"reads index"| FileSys
    PkgDown -->|"download .deb"| ExtRepos
    PkgDown -->|"cache .deb"| FileSys

    %% Dependencies on go.mod & go.sum
    CLI -->|deps| GoMod
    Config -->|deps| GoMod
    Globals -->|deps| GoMod
    IdxDown -->|deps| GoMod
    IdxBuilder -->|deps| GoMod
    PkgDown -->|deps| GoMod

    CLI -->|deps| GoSum
    Config -->|deps| GoSum
    Globals -->|deps| GoSum
    IdxDown -->|deps| GoSum
    IdxBuilder -->|deps| GoSum
    PkgDown -->|deps| GoSum

    %% Click Events
    click CLI "https://github.com/osnieltux/tinyrepo/blob/main/main.go"
    click Config "https://github.com/osnieltux/tinyrepo/blob/main/config.go"
    click Globals "https://github.com/osnieltux/tinyrepo/blob/main/global.go"
    click IdxDown "https://github.com/osnieltux/tinyrepo/blob/main/utils.go"
    click IdxBuilder "https://github.com/osnieltux/tinyrepo/blob/main/package.go"
    click PkgDown "https://github.com/osnieltux/tinyrepo/blob/main/package.go"
    click GoMod "https://github.com/osnieltux/tinyrepo/blob/main/go.mod"
    click GoSum "https://github.com/osnieltux/tinyrepo/blob/main/go.sum"
    click Readme "https://github.com/osnieltux/tinyrepo/blob/main/README.md"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#21618C,stroke-width:2px
    classDef storage fill:#F5B041,stroke:#B9770E,stroke-width:2px
    classDef external fill:#82E0AA,stroke:#196F3D,stroke-dasharray: 5 5,stroke-width:2px
```
