# x-motemen/ghq architecture

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

- Interactive diagram: https://gitdiagram.com/x-motemen/ghq
- Repository: https://github.com/x-motemen/ghq

## Overview

##### Main Components

a. Core Components:
- Command Handler Layer (represented by cmd_*.go files)
- Repository Management Layer (local_repository.go, remote_repository.go)
- VCS Integration Layer (vcs.go)
- URL Parser/Handler (url.go)
- Configuration Manager (uses git-config)

b. Supporting Components:
- Logger System (logger package)
- Command Utilities (cmdutil package)
- Shell Completion Support (misc/bash, misc/fish, misc/zsh)

**┌─ CLI Interface Layer ─────────────────┐**
- (cmd_*.go files)                      │
- ┬─┤
- Repository Management Layer         │L│
- Local Repository Handler         │o│
- Remote Repository Handler        │g│
- ┤g│
- VCS Integration Layer              │e│
- Git, Mercurial, etc. handlers    │r│
- ┤ │
- URL & Path Management Layer        │ │
- ┴─┘

##### Component Relationships

- User input → Command Handler
- Command Handler → Repository Management
- Repository Management → VCS Integration
- All components → Logger

b. External integrations:
- Git Configuration System
- Various VCS Systems (Git, Mercurial, Subversion, etc.)
- File System (for local repository management)

##### Implementation Details to Highlight

- Command Pattern implementation (shown in commands.go)
- VCS abstraction layer
- URL parsing and manipulation
- Local/Remote repository separation

##### The logging system's pervasive presence throughout the application

Remember to include a note about the test coverage, as the project maintains extensive test files (indicated by *_test.go files) throughout the codebase, showing a test-driven development approach.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI
        CMD["Command Handler Layer"]
        CMD_CREATE["Create Command"]
        CMD_GET["Get Command"]
        CMD_LIST["List Command"]
        CMD_RM["Remove Command"]
        CMD_ROOT["Root Command"]
        CMD_MAIN["Commands Handler"]
        
        CMD --> CMD_CREATE
        CMD --> CMD_GET
        CMD --> CMD_LIST
        CMD --> CMD_RM
        CMD --> CMD_ROOT
        CMD --> CMD_MAIN
    end

    subgraph RepoManagement
        LOCAL["Local Repository Handler"]
        REMOTE["Remote Repository Handler"]
        GETTER["Repository Getter"]
        
        LOCAL --> GETTER
        REMOTE --> GETTER
    end

    subgraph VCSLayer
        VCS["VCS Integration"]
        GIT["Git"]
        HG["Mercurial"]
        SVN["Subversion"]
        
        VCS --> GIT
        VCS --> HG
        VCS --> SVN
    end

    subgraph URLManagement
        URL["URL Parser"]
        GOIMPORT["Go Import Handler"]
        
        URL --> GOIMPORT
    end

    subgraph Support
        LOGGER["Logger System"]
        CMDUTIL["Command Utilities"]
        SHELL["Shell Completion"]
        HELPERS["Platform Helpers"]
        
        SHELL --> BASH["Bash"]
        SHELL --> FISH["Fish"]
        SHELL --> ZSH["Zsh"]
    end

    MAIN["Main Application"]

    CMD --> RepoManagement
    RepoManagement --> VCSLayer
    RepoManagement --> URLManagement
    CMD --> LOGGER
    RepoManagement --> LOGGER
    VCSLayer --> LOGGER
    URLManagement --> LOGGER
    CMD --> CMDUTIL
    MAIN --> CMD

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef cli fill:#b3e0ff,stroke:#333
    classDef repo fill:#b3ffb3,stroke:#333
    classDef vcs fill:#ffcc99,stroke:#333
    classDef support fill:#e6b3ff,stroke:#333
    classDef external fill:#gray,stroke:#333

    class CMD,CMD_CREATE,CMD_GET,CMD_LIST,CMD_RM,CMD_ROOT,CMD_MAIN cli
    class LOCAL,REMOTE,GETTER repo
    class VCS,GIT,HG,SVN vcs
    class LOGGER,CMDUTIL,SHELL,HELPERS,BASH,FISH,ZSH support
    class URL,GOIMPORT default

    click CMD_CREATE "https://github.com/x-motemen/ghq/blob/master/cmd_create.go"
    click CMD_GET "https://github.com/x-motemen/ghq/blob/master/cmd_get.go"
    click CMD_LIST "https://github.com/x-motemen/ghq/blob/master/cmd_list.go"
    click CMD_RM "https://github.com/x-motemen/ghq/blob/master/cmd_rm.go"
    click CMD_ROOT "https://github.com/x-motemen/ghq/blob/master/cmd_root.go"
    click CMD_MAIN "https://github.com/x-motemen/ghq/blob/master/commands.go"
    click LOCAL "https://github.com/x-motemen/ghq/blob/master/local_repository.go"
    click REMOTE "https://github.com/x-motemen/ghq/blob/master/remote_repository.go"
    click GETTER "https://github.com/x-motemen/ghq/blob/master/getter.go"
    click VCS "https://github.com/x-motemen/ghq/blob/master/vcs.go"
    click URL "https://github.com/x-motemen/ghq/blob/master/url.go"
    click GOIMPORT "https://github.com/x-motemen/ghq/blob/master/go_import.go"
    click LOGGER "https://github.com/x-motemen/ghq/blob/master/logger/log.go"
    click CMDUTIL "https://github.com/x-motemen/ghq/blob/master/cmdutil/run.go"
    click BASH "https://github.com/x-motemen/ghq/tree/master/misc/bash/_ghq"
    click FISH "https://github.com/x-motemen/ghq/blob/master/misc/fish/ghq.fish"
    click ZSH "https://github.com/x-motemen/ghq/tree/master/misc/zsh/_ghq"
    click MAIN "https://github.com/x-motemen/ghq/blob/master/main.go"
    click HELPERS "https://github.com/x-motemen/ghq/blob/master/helpers_unix.go"
```
