# getsavvyinc/savvy-cli architecture

> Architecture diagram of the GitHub repository getsavvyinc/savvy-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/getsavvyinc/savvy-cli
- Repository: https://github.com/getsavvyinc/savvy-cli

## Overview

##### Main Components

a) Core CLI Application
- Command Handler (cmd/ directory)
- Shell Integration Layer (shell/ directory)
- Configuration Management (config/ directory)
- Storage System (storage/ directory)

b) External Services Integration
- LLM Service Integration (llm/ directory)
- Authentication System (authz/ directory)
- API Client (client/ directory)

c) Workflow Management
- Recording System
- Sync Mechanism
- Local Storage
- Parameter Management (param/ directory)

##### Component Relationships

**┌─────────────────────────────────────────────────────────────┐**
- Savvy CLI System                       │

- ┌──────────────┐        ┌───────────────┐                 │
- Shell Layer  │◄─────►│  Command Hub   │                 │
- ┘        └───────┬───────┘                 │
- ▲                        │                         │
- ▼                         │
- ┌──────┴───────┐        ┌───────────────┐    ┌─────────┐ │
- Terminal   │        │  Core Logic   │◄──►│ Storage │ │
- ┘        └───────┬───────┘    └─────────┘ │

- ┬───────┴────────────────────────┘

- ▼
- ┌─────────────────────┐
- External Services │
- LLM API        │
- Auth Service   │
- Sync Service   │
- ┘

##### Important Details to Highlight

a) Command Processing Flow:
- How commands flow from user input through the shell layer
- Command expansion and parameter substitution
- Workflow recording mechanism

b) Authentication Flow:
- Login process
- How authentication is maintained
- Token management

c) Workflow Sync:
- Bi-directional sync mechanism
- Local cache storage
- Offline capability

##### Key Technical Elements

- Shell Integration: Highlight support for bash, zsh, and fish
- LLM Integration: Show AI-powered workflow generation
- Local/Remote Storage: Display hybrid storage architecture
- Parameter System: Show parameter management flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["Savvy CLI System"]
        Terminal["Terminal Interface"]
        
        subgraph ShellLayer["Shell Integration Layer"]
            Bash["Bash Shell"]:::shell
            Zsh["Zsh Shell"]:::shell
            Fish["Fish Shell"]:::shell
        end

        subgraph CommandHub["Command Processing"]
            CmdHandler["Command Handler"]:::cmd
            ParamMgr["Parameter Manager"]:::param
            RecordSystem["Recording System"]:::record
        end

        subgraph CoreLogic["Core Logic"]
            Config["Configuration Manager"]:::config
            Storage["Storage System"]:::storage
            APIClient["API Client"]:::client
        end

        subgraph Display["Display Layer"]
            ErrorDisplay["Error Display"]:::display
            InfoDisplay["Info Display"]:::display
            SuccessDisplay["Success Display"]:::display
        end
    end

    subgraph External["External Services"]
        LLMService["LLM Service"]:::llm
        AuthService["Auth Service"]:::auth
        SyncService["Sync Service"]:::sync
    end

    Terminal --> ShellLayer
    ShellLayer --> CmdHandler
    CmdHandler --> CoreLogic
    CoreLogic --> External
    CoreLogic --> Display
    
    %% Component relationships
    ParamMgr --> CoreLogic
    RecordSystem --> Storage
    APIClient --> External
    Config --> Storage

    %% Click events
    click CmdHandler "https://github.com/getsavvyinc/savvy-cli/blob/main/cmd/root.go"
    click Bash "https://github.com/getsavvyinc/savvy-cli/blob/main/shell/bash.go"
    click Zsh "https://github.com/getsavvyinc/savvy-cli/blob/main/shell/zsh.go"
    click Fish "https://github.com/getsavvyinc/savvy-cli/blob/main/shell/fish.go"
    click Config "https://github.com/getsavvyinc/savvy-cli/blob/main/config/config.go"
    click Storage "https://github.com/getsavvyinc/savvy-cli/blob/main/storage/storage.go"
    click LLMService "https://github.com/getsavvyinc/savvy-cli/blob/main/llm/llm.go"
    click AuthService "https://github.com/getsavvyinc/savvy-cli/blob/main/authz/roundtripper.go"
    click APIClient "https://github.com/getsavvyinc/savvy-cli/blob/main/client/client.go"
    click ParamMgr "https://github.com/getsavvyinc/savvy-cli/blob/main/param/param.go"
    click RecordSystem "https://github.com/getsavvyinc/savvy-cli/blob/main/cmd/record.go"
    click ErrorDisplay "https://github.com/getsavvyinc/savvy-cli/blob/main/display/error.go"
    click InfoDisplay "https://github.com/getsavvyinc/savvy-cli/blob/main/display/info.go"
    click SuccessDisplay "https://github.com/getsavvyinc/savvy-cli/blob/main/display/success.go"

    %% Styling
    classDef shell fill:#FFA07A
    classDef cmd fill:#4169E1
    classDef config fill:#9370DB
    classDef storage fill:#8B008B
    classDef llm fill:#32CD32
    classDef auth fill:#228B22
    classDef sync fill:#006400
    classDef client fill:#4682B4
    classDef param fill:#DDA0DD
    classDef record fill:#FF69B4
    classDef display fill:#FFD700

    %% Legend
    subgraph Legend
        L1["Shell Components"]:::shell
        L2["Command Components"]:::cmd
        L3["Storage Components"]:::storage
        L4["External Services"]:::llm
        L5["Display Components"]:::display
    end
```
