# andyhoang/athena-cli architecture

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

- Interactive diagram: https://gitdiagram.com/andyhoang/athena-cli
- Repository: https://github.com/andyhoang/athena-cli

## Overview

##### Main Components
- CLI Entry Point: Represent the main executable (src/main.rs) which initializes the application.
- Configuration Manager: Show the configuration handling (src/config.rs and usage of config.example.toml copied to ~/.config/athena-cli/config.toml) that sets up AWS credentials, default workgroup, and output settings.
- Command Dispatcher: Indicate that the app uses a modular command pattern. Highlight the CLI parser (src/cli.rs) and the “commands” modules (located in src/commands). Each subdirectory (e.g., database, history, inspect) represents a group of commands.
- AWS Integration Module: Include the AWS-related interactions from src/aws.rs that handle communication with AWS Athena.
- Commands and Utilities: Represent the specialized command modules (e.g., query execution, database listing/description, workgroup management, query history, and inspect/download functionality). Also include supporting utilities (e.g., src/utils) that help with filtering or displaying results.
- Internal Context/Data Model: Show the role of src/context.rs and src/lib.rs which likely maintain application state or common data structures across commands.
- External Interaction: Emphasize that the CLI interacts with AWS Athena as an external service (also hint at the use of Polars for DataFrame handling, as noted in the README).

##### Relationships and Interactions
- From the CLI Parser, branch out to the appropriate command module (database, query, history, inspect, or workgroup).
- Each command module processes its logic and may invoke functionality from:
- The AWS Interaction Module for executing queries or retrieving metadata from AWS Athena.
- The Configuration Manager to access user settings.
- The Context component to share state/information across commands.
- Utility modules to handle formatting and output tasks.

##### Architectural Patterns and Principles
- Modular Command Pattern: The project neatly divides different functionalities into sub-commands (database, history, inspect, etc.), each encapsulated in its own module.
- Separation of Concerns: The design separates user interface (CLI parsing), business logic (commands and AWS interactions), and configuration management.

##### Detailed Elements to Add
- Flow from the CLI command execution to the actual call to AWS Athena and demonstrate how results are processed and returned.
- Hexagons for command modules.
- Rectangles for core logic components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core CLI Components
    CLIEntry["CLI Entry (main.rs)"]:::cli
    CLIParser["CLI Parser (cli.rs)"]:::cli
    ConfigManager["Configuration Manager (config.rs)"]:::config

    %% Command Modules
    subgraph "Command Modules"
        DB["Database Commands"]:::command
        QC["Query Commands"]:::command
        HC["History Commands"]:::command
        IC["Inspect Commands"]:::command
        WC["Workgroup Commands"]:::command
    end

    %% Aggregator for Command Modules interactions
    CMD_AGG["Commands Aggregator"]:::aggregator

    %% AWS Integration & External Service
    AWSInt["AWS Integration Module (aws.rs)"]:::aws
    AWSCloud["AWS Athena Cloud"]:::external

    %% Utilities
    Utils["Utilities (utils)"]:::utility

    %% Internal Context and Data Model
    subgraph "Internal Context/Data Model"
        Context["Context (context.rs)"]:::internal
        Lib["Library (lib.rs)"]:::internal
    end

    %% Flow Connections
    CLIEntry -->|"initializes"| CLIParser
    CLIParser -->|"parses commands"| DB
    CLIParser --> QC
    CLIParser --> HC
    CLIParser --> IC
    CLIParser --> WC

    %% Each command module sends its output to the aggregator
    DB --> CMD_AGG
    QC --> CMD_AGG
    HC --> CMD_AGG
    IC --> CMD_AGG
    WC --> CMD_AGG

    %% Aggregator directs calls to shared components
    CMD_AGG -->|"uses"| AWSInt
    CMD_AGG -->|"accesses"| ConfigManager
    CMD_AGG -->|"formats output"| Utils
    CMD_AGG -->|"shares state with"| Context
    CMD_AGG -->|"shares state with"| Lib

    %% AWS Integration communicates with AWS Athena Cloud
    AWSInt -->|"calls Athena"| AWSCloud
    AWSCloud -->|"returns data"| AWSInt

    %% Styling Classes
    classDef cli fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef config fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef command fill:#F9E79F,stroke:#B7950B,stroke-width:2px,shape:hexagon;
    classDef aggregator fill:#E5E7E9,stroke:#566573,stroke-width:2px,stroke-dasharray: 5 5;
    classDef aws fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#922B21,stroke-width:2px,stroke-dasharray: 2 2,shape:cloud;
    classDef utility fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef internal fill:#F5CBA7,stroke:#7D6608,stroke-width:2px;

    %% Click Events
    click CLIEntry "https://github.com/andyhoang/athena-cli/blob/main/src/main.rs"
    click CLIParser "https://github.com/andyhoang/athena-cli/blob/main/src/cli.rs"
    click ConfigManager "https://github.com/andyhoang/athena-cli/blob/main/src/config.rs"
    click DB "https://github.com/andyhoang/athena-cli/tree/main/src/commands/database"
    click QC "https://github.com/andyhoang/athena-cli/blob/main/src/commands/query.rs"
    click HC "https://github.com/andyhoang/athena-cli/tree/main/src/commands/history"
    click IC "https://github.com/andyhoang/athena-cli/tree/main/src/commands/inspect"
    click WC "https://github.com/andyhoang/athena-cli/blob/main/src/commands/workgroup.rs"
    click AWSInt "https://github.com/andyhoang/athena-cli/blob/main/src/aws.rs"
    click Utils "https://github.com/andyhoang/athena-cli/blob/main/src/utils/filter.rs"
    click Context "https://github.com/andyhoang/athena-cli/blob/main/src/context.rs"
    click Lib "https://github.com/andyhoang/athena-cli/blob/main/src/lib.rs"
```
