# shobhits7/gemini_craft architecture

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

- Interactive diagram: https://gitdiagram.com/shobhits7/gemini_craft
- Repository: https://github.com/shobhits7/gemini_craft

## Overview

##### Main components
- GeminiCraft Core: Represented by the central module (lib/gemini_craft.rb) that ties all subcomponents together.
- Configuration Module: (lib/gemini_craft/configuration.rb) Handles setting API keys, model selection, caching options, timeout configurations, and retry attempts.
- Client Module: (lib/gemini_craft/client.rb) The main interface that the user interacts with. It accepts prompts and optional system instructions along with additional options, and it orchestrates generating content.
- Cache Module: (lib/gemini_craft/cache.rb) Manages caching logic when enabled.
- Error Handling: (lib/gemini_craft/error.rb) Captures and defines custom errors related to API calls or configuration issues.
- Versioning: (lib/gemini_craft/version.rb) Manages gem versioning.
- External Service: Google’s Gemini API – note that although it isn’t part of the gem’s file structure, it is the external endpoint/service that the Client interacts with.

##### Relationships and interactions
- A user application configures GeminiCraft using the Configuration Module. This sets up parameters like API keys and caching preferences.
- The Client module (GeminiCraft.client) is then used to call the generate_content method. This call internally utilizes the configuration settings.
- The Client sends requests to the external Gemini API. If caching is enabled, requests/responses flow through the Cache Module, which may store and retrieve responses to optimize performance.
- Any issues encountered during API calls are managed by the Error Handling Module.
- Overall, the core module (gemini_craft.rb) acts as the entry point and integrates these various submodules cohesively.

##### Architectural patterns and design principles
- Modularity: The gem is designed in clearly separated modules (configuration, client, caching, error) which are independently managed and tested.
- Separation of concerns: Each module is responsible for a specific task, enabling easier maintenance and extensibility.
- Configurability: The use of a configuration block to adjust behaviors shows that the design focuses on flexible and customizable usage.

##### Final checklist
- Component (GeminiCraft core, Configuration, Client, Cache, External API, Error Handling).

## Diagram (Mermaid)

```mermaid
flowchart TD
    UA("User Application"):::external
    Core("GeminiCraft Core"):::internal
    Config("Configuration Module"):::internal
    Client("Client Module"):::internal
    Cache("Cache Module"):::internal
    Error("Error Handling"):::internal
    Version("Versioning"):::internal
    External("Google's Gemini API"):::external

    UA -->|"setParameters"| Config
    UA -->|"invokeGenerateContent"| Client

    %% GeminiCraft Core integrations
    Core -->|"integrates"| Config
    Core -->|"integrates"| Client
    Core -->|"integrates"| Cache
    Core -->|"integrates"| Error
    Core -->|"integrates"| Version

    %% Client interactions
    Client -->|"usesConfig"| Config
    Client -->|"calls"| External
    Client -->|"cacheLookup"| Cache
    Cache -->|"returnsData"| Client
    Client -->|"errorsTo"| Error

    %% Click Events for mapped components
    click Core "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft.rb"
    click Config "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft/configuration.rb"
    click Client "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft/client.rb"
    click Cache "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft/cache.rb"
    click Error "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft/error.rb"
    click Version "https://github.com/shobhits7/gemini_craft/blob/main/lib/gemini_craft/version.rb"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1F618D,stroke-width:2px
    classDef external fill:#F9E79F,stroke:#BA4A00,stroke-width:2px
```
