# dagimg-dot/gitsnip architecture

> Architecture diagram of the GitHub repository dagimg-dot/gitsnip, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dagimg-dot/gitsnip
- Repository: https://github.com/dagimg-dot/gitsnip

## Overview

gitsnip is a command-line tool for downloading selected files and folders from Git repositories. The main workflow parses the source, ref, and requested paths; selects a downloader; stages a repository snapshot; selects matching files; and safely writes them to the destination before reporting the result. The README also documents support for multiple Git hosts, private-repository credentials, and a GitHub API fallback. Some downloader and output details are documented but not fully excerpted, so those relationships are shown only where the README or source index supports them.

Main entry points: [`internal/cli/root.go`](https://github.com/dagimg-dot/gitsnip/blob/main/internal/cli/root.go) (Command workflow), [`internal/app/downloader/factory.go`](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/factory.go) (Method selection), [`internal/app/files.go`](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/files.go) (File selection and writing), [`internal/app/app.go`](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/app.go) (Download orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["CLI and reporting"]
  node_entry["Signal entry point<br/>[main.go]"]
  node_cli["Command workflow<br/>[root.go]"]
  node_reporting["Result formatting<br/>[output.go]"]
  node_ui["Terminal feedback"]
end

subgraph group_request["Request interpretation"]
  node_source["Source parsing<br/>[source.go]"]
  node_paths["Path patterns<br/>[pathspec.go]"]
  node_requestmodel["Request and snapshot<br/>[types.go]"]
end

subgraph group_download["Download methods"]
  node_downloadapp["Download orchestration<br/>[app.go]"]
  node_factory["Method selection<br/>[factory.go]"]
  node_sparse["Sparse Git checkout<br/>[sparse_checkout.go]"]
  node_githubapi["GitHub API fetch<br/>[github_api.go]"]
  node_gitutil["Git command runner<br/>[command.go]"]
end

subgraph group_processing["Selection and writing"]
  node_fileops["File selection and writing<br/>[files.go]"]
  node_fsutil["Safe file utilities<br/>[fs.go]"]
end

node_user(("CLI user"))
node_gitremote(("Git repository host"))
node_github(("GitHub API and raw content"))
node_filesystem[("Local filesystem")]

node_user -->|"runs command"| node_entry
node_entry -->|"starts"| node_cli
node_cli -->|"parses source"| node_source
node_cli -->|"parses paths"| node_paths
node_cli -->|"builds request"| node_requestmodel
node_cli -->|"invokes download"| node_downloadapp
node_cli -->|"reports progress"| node_ui
node_downloadapp -->|"selects method"| node_factory
node_factory -->|"constructs"| node_sparse
node_factory -->|"constructs"| node_githubapi
node_factory -->|"uses runner"| node_gitutil
node_sparse -->|"fetches repository"| node_gitremote
node_sparse -->|"runs Git commands"| node_gitutil
node_githubapi -->|"requests trees and files"| node_github
node_downloadapp -->|"selects and writes"| node_fileops
node_fileops -->|"matches patterns"| node_paths
node_fileops -->|"copies files safely"| node_fsutil
node_fileops -->|"reads and writes"| node_filesystem
node_cli -->|"formats result"| node_reporting
node_reporting -->|"builds summary"| node_ui

click node_entry "https://github.com/dagimg-dot/gitsnip/blob/main/cmd/gitsnip/main.go"
click node_cli "https://github.com/dagimg-dot/gitsnip/blob/main/internal/cli/root.go"
click node_reporting "https://github.com/dagimg-dot/gitsnip/blob/main/internal/cli/output.go"
click node_ui "https://github.com/dagimg-dot/gitsnip/tree/main/internal/ui"
click node_source "https://github.com/dagimg-dot/gitsnip/blob/main/internal/source/source.go"
click node_paths "https://github.com/dagimg-dot/gitsnip/blob/main/internal/pathspec/pathspec.go"
click node_requestmodel "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/model/types.go"
click node_downloadapp "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/app.go"
click node_factory "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/factory.go"
click node_sparse "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/sparse_checkout.go"
click node_githubapi "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/github_api.go"
click node_gitutil "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/gitutil/command.go"
click node_fileops "https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/files.go"
click node_fsutil "https://github.com/dagimg-dot/gitsnip/blob/main/internal/util/fs.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_cli,node_reporting,node_ui,node_user toneBlue
class node_source,node_paths,node_requestmodel,node_filesystem toneAmber
class node_downloadapp,node_factory,node_sparse,node_githubapi,node_gitutil,node_github toneMint
class node_fileops,node_fsutil toneRose
class node_gitremote toneIndigo
```

## Components

### CLI and reporting

- [Signal entry point](https://github.com/dagimg-dot/gitsnip/blob/main/cmd/gitsnip/main.go): `cmd/gitsnip/main.go`
- [Command workflow](https://github.com/dagimg-dot/gitsnip/blob/main/internal/cli/root.go): `internal/cli/root.go`
- [Result formatting](https://github.com/dagimg-dot/gitsnip/blob/main/internal/cli/output.go): `internal/cli/output.go`
- [Terminal feedback](https://github.com/dagimg-dot/gitsnip/tree/main/internal/ui): `internal/ui`

### Request interpretation

- [Source parsing](https://github.com/dagimg-dot/gitsnip/blob/main/internal/source/source.go): `internal/source/source.go`
- [Path patterns](https://github.com/dagimg-dot/gitsnip/blob/main/internal/pathspec/pathspec.go): `internal/pathspec/pathspec.go`
- [Request and snapshot](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/model/types.go): `internal/app/model/types.go`

### Download methods

- [Download orchestration](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/app.go): `internal/app/app.go`
- [Method selection](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/factory.go): `internal/app/downloader/factory.go`
- [Sparse Git checkout](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/sparse_checkout.go): `internal/app/downloader/sparse_checkout.go`
- [GitHub API fetch](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/downloader/github_api.go): `internal/app/downloader/github_api.go`
- [Git command runner](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/gitutil/command.go): `internal/app/gitutil/command.go`

### Selection and writing

- [File selection and writing](https://github.com/dagimg-dot/gitsnip/blob/main/internal/app/files.go): `internal/app/files.go`
- [Safe file utilities](https://github.com/dagimg-dot/gitsnip/blob/main/internal/util/fs.go): `internal/util/fs.go`

### Other components

- **CLI user**
- **Git repository host**
- **GitHub API and raw content**
- **Local filesystem**

## Connections

- CLI user → Signal entry point: runs command (evidence: `README.md`)
- Signal entry point → Command workflow: starts (evidence: `cmd/gitsnip/main.go`)
- Command workflow → Source parsing: parses source (evidence: `internal/cli/root.go`)
- Command workflow → Path patterns: parses paths (evidence: `internal/cli/root.go`)
- Command workflow → Request and snapshot: builds request (evidence: `internal/cli/root.go`)
- Command workflow → Download orchestration: invokes download (evidence: `internal/cli/root.go`)
- Command workflow → Terminal feedback: reports progress (evidence: `internal/cli/root.go`)
- Download orchestration → Method selection: selects method (evidence: `internal/app/app.go`)
- Method selection → Sparse Git checkout: constructs (evidence: `internal/app/downloader/factory.go`)
- Method selection → GitHub API fetch: constructs (evidence: `internal/app/downloader/factory.go`)
- Method selection → Git command runner: uses runner (evidence: `internal/app/downloader/factory.go`)
- Sparse Git checkout → Git repository host: fetches repository (evidence: `README.md`)
- Sparse Git checkout → Git command runner: runs Git commands (evidence: `internal/app/downloader/sparse_checkout.go`)
- GitHub API fetch → GitHub API and raw content: requests trees and files (evidence: `internal/app/downloader/github_api.go`)
- Download orchestration → File selection and writing: selects and writes (evidence: `internal/app/app.go`)
- File selection and writing → Path patterns: matches patterns (evidence: `internal/app/files.go`)
- File selection and writing → Safe file utilities: copies files safely (evidence: `internal/app/files.go`)
- File selection and writing → Local filesystem: reads and writes (evidence: `internal/app/files.go`)
- Command workflow → Result formatting: formats result (evidence: `internal/cli/output.go`)
- Result formatting → Terminal feedback: builds summary (evidence: `internal/cli/output.go`)
