# hamid-faridafshar/worktree architecture

> Architecture diagram of the GitHub repository hamid-faridafshar/worktree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hamid-faridafshar/worktree
- Repository: https://github.com/hamid-faridafshar/worktree

## Overview

Worktree is a terminal UI for finding repositories, managing Git worktrees, and opening a selected worktree in an editor. The main flow starts with the CLI entry point, scans repository directories, presents worktree actions, then creates/removes worktrees or launches Cursor. README also describes configurable IDE preferences and workspace-file handling; workspace copying is visible in the sampled utility code, but no settings implementation appears in the supplied tree. The graph omits that unsupported subsystem and shows only evidenced wiring.

Main entry points: [`internal/utils/utils.go`](https://github.com/hamid-faridafshar/worktree/blob/main/internal/utils/utils.go) (Filesystem and Git helpers), [`main.go`](https://github.com/hamid-faridafshar/worktree/blob/main/main.go) (CLI entry), [`internal/layout/layout.go`](https://github.com/hamid-faridafshar/worktree/blob/main/internal/layout/layout.go) (Terminal UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and UI"]
  node_main["CLI entry<br/>[main.go]"]
  node_layout["Terminal UI<br/>[layout.go]"]
end

subgraph group_worktrees["Repository operations"]
  node_utils["Filesystem and Git helpers<br/>[utils.go]"]
end

subgraph group_integrations["External tools"]
  node_git["Git"]
  node_cursor["Cursor"]
end

node_user(("Terminal user"))
node_repo_dirs[("Repository directories")]
node_worktree_dirs[("Worktree directories")]
node_workspace_file["Workspace file"]

node_user -->|"launches"| node_main
node_main -->|"creates UI"| node_layout
node_layout -->|"scans and acts"| node_utils
node_utils -->|"lists and checks"| node_repo_dirs
node_utils -->|"creates and removes"| node_worktree_dirs
node_utils -->|"copies"| node_workspace_file
node_utils -->|"runs worktree commands"| node_git
node_utils -->|"launches"| node_cursor

click node_main "https://github.com/hamid-faridafshar/worktree/blob/main/main.go"
click node_layout "https://github.com/hamid-faridafshar/worktree/blob/main/internal/layout/layout.go"
click node_utils "https://github.com/hamid-faridafshar/worktree/blob/main/internal/utils/utils.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_main,node_layout,node_user toneBlue
class node_utils,node_repo_dirs,node_worktree_dirs toneAmber
class node_git,node_cursor toneMint
class node_workspace_file toneIndigo
```

## Components

### Entry and UI

- [CLI entry](https://github.com/hamid-faridafshar/worktree/blob/main/main.go): `main.go`
- [Terminal UI](https://github.com/hamid-faridafshar/worktree/blob/main/internal/layout/layout.go): `internal/layout/layout.go`

### Repository operations

- [Filesystem and Git helpers](https://github.com/hamid-faridafshar/worktree/blob/main/internal/utils/utils.go): `internal/utils/utils.go`

### External tools

- **Git**
- **Cursor**

### Other components

- **Terminal user**
- **Repository directories**
- **Worktree directories**
- **Workspace file**

## Connections

- Terminal user → CLI entry: launches
- CLI entry → Terminal UI: creates UI
- Terminal UI → Filesystem and Git helpers: scans and acts
- Filesystem and Git helpers → Repository directories: lists and checks
- Filesystem and Git helpers → Worktree directories: creates and removes
- Filesystem and Git helpers → Workspace file: copies
- Filesystem and Git helpers → Git: runs worktree commands
- Filesystem and Git helpers → Cursor: launches
