# jj-h/gitee_cli architecture

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

- Interactive diagram: https://gitdiagram.com/jj-h/gitee_cli
- Repository: https://github.com/jj-h/gitee_cli

## Overview

##### Main Components Identification

The system should be represented with these key components:

a. Command Layer (cmd/)
- Root command handler
- Feature-specific commands (PR, Issues, SSH Keys, etc.)
- Authentication and configuration handlers

b. Internal API Layer (internal/api/)
- API clients for different Gitee services
- Data models and service interfaces

c. Utility Layer (utils/)
- HTTP client utilities
- Git utilities
- Terminal UI components

d. Configuration Management (config/)
- Configuration handling
- YAML configuration storage

e. External Systems
- Gitee API (V5)
- Gitee Enterprise API
- Local Git repository
- User's filesystem (for SSH keys and config)

**┌─────────────────────────────────────────────────────────────┐**
- Gitee CLI Application                    │
- ┬─────────────────────────┬──────────────────┤
- Command Layer │    Internal API Layer    │   Utility Layer  │
- (cmd/)      │    (internal/api/)      │    (utils/)      │
- ┴─────────────────────────┴──────────────────┤
- Configuration Layer                        │
- (config/)                               │
- ┤
- External Systems & Services                   │
- ┘

##### Component Relationships

- Command Layer → Internal API Layer (command execution flow)
- Internal API Layer → External Gitee APIs (API calls)
- Utility Layer ↔ All Other Layers (utility functions used throughout)
- Configuration Layer ↔ All Other Layers (config access)

##### Important Details

a. Command Structure:
- Main command groups (PR, Issue, SSH-Key, etc.)
- Subcommand relationships

b. API Integration:
- Separation between V5 API and Enterprise API calls
- Authentication flow

c. Local System Integration:
- Filesystem interactions (config, SSH keys)
- Git repository interactions

##### Specific Implementation Notes

- Notes for important configuration requirements
- Authentication flow with special emphasis

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["Gitee CLI Application"]
        subgraph CmdLayer["Command Layer"]
            Root["Root Command"]:::cmd
            PR["Pull Request Commands"]:::cmd
            Issue["Issue Commands"]:::cmd
            SSHKey["SSH Key Commands"]:::cmd
            Auth["Authentication Commands"]:::cmd
            Enterprise["Enterprise Commands"]:::cmd
        end

        subgraph APILayer["Internal API Layer"]
            PRAPI["PR API Client"]:::api
            IssueAPI["Issue API Client"]:::api
            SSHKeyAPI["SSH Key API Client"]:::api
            EnterpriseAPI["Enterprise API Client"]:::api
            UserAPI["User API Client"]:::api
        end

        subgraph UtilLayer["Utility Layer"]
            HTTPUtils["HTTP Client"]:::util
            GitUtils["Git Utilities"]:::util
            TUI["Terminal UI"]:::util
            ColorUtils["Color Utilities"]:::util
            EditorUtils["Editor Utilities"]:::util
        end

        subgraph ConfigLayer["Configuration Layer"]
            Config["Configuration Manager"]:::config
            ConfigTemplate["Config Template"]:::config
        end
    end

    subgraph External["External Systems"]
        GiteeV5["Gitee API V5"]:::external
        GiteeEnterprise["Gitee Enterprise API"]:::external
        LocalGit["Local Git Repository"]:::external
        FileSystem["User Filesystem"]:::external
    end

    %% Command Layer Relationships
    Root --> PR
    Root --> Issue
    Root --> SSHKey
    Root --> Auth
    Root --> Enterprise

    %% API Layer Relationships
    PR --> PRAPI
    Issue --> IssueAPI
    SSHKey --> SSHKeyAPI
    Enterprise --> EnterpriseAPI
    Auth --> UserAPI

    %% External System Relationships
    PRAPI --> GiteeV5
    IssueAPI --> GiteeV5
    SSHKeyAPI --> GiteeV5
    EnterpriseAPI --> GiteeEnterprise
    UserAPI --> GiteeV5

    %% Utility Layer Relationships
    HTTPUtils --> GiteeV5
    HTTPUtils --> GiteeEnterprise
    GitUtils --> LocalGit
    Config --> FileSystem

    %% Click Events
    click Root "https://github.com/JJ-H/gitee_cli/blob/main/cmd/root.go"
    click PR "https://github.com/JJ-H/gitee_cli/blob/main/cmd/pull_request/pr.go"
    click Issue "https://github.com/JJ-H/gitee_cli/blob/main/cmd/issue/issue.go"
    click SSHKey "https://github.com/JJ-H/gitee_cli/blob/main/cmd/ssh-key/ssh_key.go"
    click Auth "https://github.com/JJ-H/gitee_cli/blob/main/cmd/auth/auth.go"
    click Enterprise "https://github.com/JJ-H/gitee_cli/blob/main/cmd/enterprise/enterprise.go"
    click PRAPI "https://github.com/JJ-H/gitee_cli/blob/main/internal/api/pull_request/pull_request.go"
    click IssueAPI "https://github.com/JJ-H/gitee_cli/blob/main/internal/api/issue/issue.go"
    click SSHKeyAPI "https://github.com/JJ-H/gitee_cli/blob/main/internal/api/ssh_key/ssh_key.go"
    click EnterpriseAPI "https://github.com/JJ-H/gitee_cli/blob/main/internal/api/enterprises/enterprises.go"
    click UserAPI "https://github.com/JJ-H/gitee_cli/blob/main/internal/api/user/user.go"
    click HTTPUtils "https://github.com/JJ-H/gitee_cli/blob/main/utils/http_utils/gitee_client.go"
    click GitUtils "https://github.com/JJ-H/gitee_cli/blob/main/utils/git_utils/git.go"
    click TUI "https://github.com/JJ-H/gitee_cli/tree/main/utils/tui/"
    click ColorUtils "https://github.com/JJ-H/gitee_cli/blob/main/utils/color.go"
    click EditorUtils "https://github.com/JJ-H/gitee_cli/blob/main/utils/editor.go"
    click Config "https://github.com/JJ-H/gitee_cli/blob/main/config/config.go"
    click ConfigTemplate "https://github.com/JJ-H/gitee_cli/blob/main/config/config.yml.example"

    %% Styling
    classDef cmd fill:#2374e1,color:#fff
    classDef api fill:#4caf50,color:#fff
    classDef util fill:#ff9800,color:#fff
    classDef config fill:#9c27b0,color:#fff
    classDef external fill:#757575,color:#fff

    %% Legend
    subgraph Legend
        CMD["Command Component"]:::cmd
        API["API Component"]:::api
        UTIL["Utility Component"]:::util
        CONF["Configuration Component"]:::config
        EXT["External System"]:::external
    end
```
