# ddworken/hishtory architecture

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

- Interactive diagram: https://gitdiagram.com/ddworken/hishtory
- Repository: https://github.com/ddworken/hishtory

## Overview

##### Main Components

a. Client-side Components:
- Shell Integration Layer (bash/zsh/fish)
- Local SQLite Database
- Command-line Interface (CLI)
- Terminal User Interface (TUI)
- Web User Interface
- Encryption/Decryption Module
- Configuration Management
- AI Integration (ChatGPT)

b. Server-side Components:
- Backend Server
- Database (PostgreSQL/SQLite)
- Web Landing Page
- Caddy Web Server

**[Shell Integration] → [hiSHtory Client]**
- ↓
**[Local SQLite DB] ←→ [Core Components] ←→ [E2E Encryption]**
- ↓                     ↓
- [User Interfaces]    [Sync Protocol]
- /     |      \            ↓
- TUI   CLI    WebUI    [hiSHtory Server]
- ↓
- [Server Database]

##### Component Details to Highlight

a. Client Core:
- Command processing pipeline
- Data flow from shell to storage
- Encryption/decryption process
- Configuration management

b. Syncing System:
- Demonstrate end-to-end encryption flow
- Offline capability
- Multi-device syncing

c. User Interfaces:
- Relationship between TUI, CLI, and WebUI
- Control+R integration
- AI assistance integration

##### Integration Points

- Shell hooks
- AI API integration
- Backend API endpoints
- Database connections

##### Implementation Details

- Go-based implementation
- GORM database interaction
- SQLite/PostgreSQL support
- Docker deployment option

##### Additional Elements

- Version information
- Configuration options
- Security boundaries

##### Offline-first architecture

This system design should provide a clear understanding of hiSHtory's architecture while highlighting its security-focused, distributed nature and flexibility in deployment options.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Shell Integration"
        SI["Shell Integration Layer"]
        SI_FISH["Fish Config"]
        SI_BASH["Bash Config"]
        SI_ZSH["Zsh Config"]
        SI --> SI_FISH & SI_BASH & SI_ZSH
    end

    subgraph "Client Core"
        CC["Core Components"]:::core
        DB[("Local SQLite DB")]:::database
        ENC["E2E Encryption"]:::security
        CONF["Configuration Manager"]:::config
        AI["AI Integration"]:::ai
    end

    subgraph "User Interfaces"
        CLI["Command Line Interface"]:::ui
        TUI["Terminal UI"]:::ui
        WUI["Web UI"]:::ui
    end

    subgraph "Server Components"
        BS["Backend Server"]:::server
        SDB[("Server Database")]:::database
        WLP["Web Landing Page"]:::web
        CWS["Caddy Web Server"]:::web
    end

    SI --> CC
    CC <--> DB
    CC <--> ENC
    CC --> CONF
    CC --> AI

    CC --> CLI & TUI & WUI
    ENC <--> BS
    BS <--> SDB
    BS --> WLP
    CWS --> WLP

    %% Click events for component mapping
    click SI "https://github.com/ddworken/hishtory/tree/master/client/lib/"
    click DB "https://github.com/ddworken/hishtory/blob/master/client/data/data.go"
    click CLI "https://github.com/ddworken/hishtory/tree/master/client/cmd/"
    click TUI "https://github.com/ddworken/hishtory/tree/master/client/tui/"
    click WUI "https://github.com/ddworken/hishtory/tree/master/client/webui/"
    click AI "https://github.com/ddworken/hishtory/blob/master/client/ai/ai.go"
    click BS "https://github.com/ddworken/hishtory/tree/master/backend/server/internal/server/"
    click WLP "https://github.com/ddworken/hishtory/tree/master/backend/web/landing/"
    click CWS "https://github.com/ddworken/hishtory/tree/master/backend/web/caddy/"
    click CONF "https://github.com/ddworken/hishtory/tree/master/client/cmd/"
    click SI_FISH "https://github.com/ddworken/hishtory/blob/master/client/lib/config.fish"
    click SI_BASH "https://github.com/ddworken/hishtory/blob/master/client/lib/config.sh"
    click SI_ZSH "https://github.com/ddworken/hishtory/blob/master/client/lib/config.zsh"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef database fill:#4CAF50,stroke:#2E7D32,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef ui fill:#FFC107,stroke:#FFA000,color:black
    classDef server fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef web fill:#795548,stroke:#4E342E,color:white
    classDef config fill:#00BCD4,stroke:#00838F,color:white
    classDef ai fill:#FF9800,stroke:#EF6C00,color:white
```
