# lordpax/aicli architecture

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

- Interactive diagram: https://gitdiagram.com/lordpax/aicli
- Repository: https://github.com/lordpax/aicli

## Overview

##### Main Components

A. Core Application Layer:
- Entry point (main.go)
- Command handlers (commands/)
- Configuration management (config/)
- Localization system (lang/)

B. SDK Layer:
- Multiple AI service integrations
- Service-specific implementations
- Common interfaces and types

C. Service Layer:
- Business logic for each feature
- Integration coordination

##### A top-level view showing three main layers
**┌─────────────────────────────────────┐**
- CLI Interface             │
- ┤
- Service Layer             │
- ┤
- SDK Layer                │
- ┘

##### Expand each layer with specific components

CLI Interface Layer:
- Command handlers (text, image, translate)
- Config management
- Localization system

Service Layer:
- Text service
- Image service
- Translation service

SDK Layer:
- OpenAI (text & image)
- Claude
- Mistral
- DeepL

- User input → Command handlers
- Command handlers → Service layer
- Service layer → SDK implementations
- SDK → External APIs

##### Important configurations
- Config file location (~/.config/aicli/config.ini)
- API key management
- Model selections

Key Architectural Patterns to Highlight:

##### Command Pattern
- How each command (text, image, translate) is implemented separately
- Demonstrate the base command structure

##### Strategy Pattern
- How different AI providers can be switched (OpenAI, Claude, Mistral)
- Configuration-based provider selection

##### SDK Abstraction
- Common interfaces for each feature type
- Provider-specific implementations

Additional Elements to Include:

##### External Dependencies
- OpenAI API
- Claude API
- Mistral API
- DeepL API

##### Configuration Flow
- Config file reading
- Environment variables
- Command-line arguments

##### Error Handling & Logging
- Error propagation paths
- Logging system integration

Use these symbols:
- 📦 For packages/modules
- 🔌 For external API connections
- ⚙️ For configuration components
- 🔄 For data flow
- 🔑 For API key management

This architecture emphasizes the project's modular design, making it easy to add new AI services or features while maintaining a consistent interface for users.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI
        EP[Entry Point]
        CH[Command Handlers]
        CFG[Configuration Management]
        LOC[Localization System]
        
        subgraph Commands
            TC[Text Commands]
            IC[Image Commands]
            TRC[Translate Commands]
            BC[Base Command]
        end
        
        subgraph Localization
            EN[English]
            FR[French]
            LC[Localization Core]
        end
    end
    
    subgraph Service
        TS[Text Service]
        IS[Image Service]
        TLS[Translation Service]
    end
    
    subgraph SDK
        SI[SDK Interfaces]
        HM[History Management]
        
        subgraph Providers
            OT[OpenAI Text]
            OI[OpenAI Image]
            CI[Claude Integration]
            MI[Mistral Integration]
            DI[DeepL Integration]
        end
    end
    
    subgraph External_APIs
        OAPI[OpenAI API]:::external
        CAPI[Claude API]:::external
        MAPI[Mistral API]:::external
        DAPI[DeepL API]:::external
    end
    
    EP --> CH
    CH --> TC & IC & TRC
    TC & IC & TRC --> BC
    
    CH --> CFG
    CH --> LOC
    LOC --> EN & FR & LC
    
    TC --> TS
    IC --> IS
    TRC --> TLS
    
    TS & IS & TLS --> SI
    SI --> HM
    
    SI --> OT & OI & CI & MI & DI
    
    OT & OI --> OAPI
    CI --> CAPI
    MI --> MAPI
    DI --> DAPI
    
    %% Click Events
    click EP "https://github.com/LordPax/aicli/blob/master/main.go"
    click TC "https://github.com/LordPax/aicli/blob/master/commands/text.go"
    click IC "https://github.com/LordPax/aicli/blob/master/commands/image.go"
    click TRC "https://github.com/LordPax/aicli/blob/master/commands/translate.go"
    click BC "https://github.com/LordPax/aicli/blob/master/commands/base.go"
    click CH "https://github.com/LordPax/aicli/tree/master/commands/"
    click CFG "https://github.com/LordPax/aicli/blob/master/config/config.go"
    click LOC "https://github.com/LordPax/aicli/tree/master/lang/"
    click EN "https://github.com/LordPax/aicli/blob/master/lang/en.go"
    click FR "https://github.com/LordPax/aicli/blob/master/lang/fr.go"
    click LC "https://github.com/LordPax/aicli/blob/master/lang/localize.go"
    click OT "https://github.com/LordPax/aicli/blob/master/sdk/openai-text.go"
    click OI "https://github.com/LordPax/aicli/blob/master/sdk/openai-image.go"
    click CI "https://github.com/LordPax/aicli/blob/master/sdk/claude.go"
    click MI "https://github.com/LordPax/aicli/blob/master/sdk/mistral.go"
    click DI "https://github.com/LordPax/aicli/blob/master/sdk/deepl.go"
    click SI "https://github.com/LordPax/aicli/blob/master/sdk/sdk.go"
    click HM "https://github.com/LordPax/aicli/blob/master/sdk/history.go"
    click TS "https://github.com/LordPax/aicli/blob/master/service/text.go"
    click IS "https://github.com/LordPax/aicli/blob/master/service/image.go"
    click TLS "https://github.com/LordPax/aicli/blob/master/service/translate.go"
    
    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef external fill:#ff9999,stroke:#333,stroke-width:2px
    classDef service fill:#99ff99,stroke:#333,stroke-width:2px
    classDef sdk fill:#9999ff,stroke:#333,stroke-width:2px
    
    %% Legend
    subgraph Legend
        L1[CLI Components]
        L2[Service Layer]:::service
        L3[SDK Layer]:::sdk
        L4[External APIs]:::external
    end
```
