# kesavgopan10/ai-prompt-artisan architecture

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

- Interactive diagram: https://gitdiagram.com/kesavgopan10/ai-prompt-artisan
- Repository: https://github.com/kesavgopan10/ai-prompt-artisan

## Overview

##### Project type and purpose
- This is a single-page frontend application built with React (TypeScript) and Vite.
- Purpose: Let users enter ideas via text, voice, or drawings, call Google Gemini’s API to refine those ideas into optimized prompts (generic/chatbot/image), and display/save the results.

##### File structure
- Top-level entries:
- App.tsx / index.tsx / index.html: root of the React SPA
- components/: all presentational and container React components
- hooks/: custom React hooks (speech recognition)
- services/: API interaction layer (geminiService.ts)
- types.ts / metadata.json: shared data definitions
- config files: package.json, tsconfig.json, vite.config.ts
- No separate backend—everything runs client-side and calls the external Gemini API
- Settings, Favorites, and Input/Output areas are modularized into their own components

##### README for additional insights
- Multi-modal input (text, Web Speech API, canvas drawing)
- Uses Google Gemini API (gemini-2.5-flash preview)
- Two modes of API use: direct text vs. multi-modal for drawings
- Persists API key in local storage (encrypted) or via .env
- UI styling: Tailwind CSS; animations: Framer Motion

a. Main components:
- Browser / React SPA
- Presentation Layer (React components: InputArea, DrawingCanvas, OutputArea, Favorites, SettingsModal)
- Hooks Layer (useSpeechRecognition)
- Service Layer (geminiService)
- Data Storage (Local Storage for favorites & API key)
- External Service (Google Gemini API)
- Build Tool (Vite)
b. Relationships & interactions:
1. User enters input in the UI (text, voice, drawing).
2. If voice → useSpeechRecognition hook converts speech to text.
3. If drawing → DrawingCanvas exports JPEG blob → geminiService sends to Gemini multimodal endpoint → receives descriptive text.
4. Text (direct or converted) → geminiService sends to Gemini chat endpoint with a system prompt → receives JSON with three prompt variations.
5. UI parses JSON and displays in OutputArea; user may save to Favorites (writes to Local Storage).
6. SettingsModal reads/writes API key to Local Storage; geminiService reads key before API calls.
c. Architectural patterns & principles:
- Layered architecture (Presentation → Hooks → Service → External API)
- Single responsibility: each component/hook/service has a clear role
- Separation of concerns: UI vs. business logic vs. data access
d. Technologies/frameworks:
- React 19 + TypeScript for UI
- Vite for bundling and dev server
- Web Speech API for voice input
- Canvas API (via React) for drawing
- Google Gemini API for AI processing
- Tailwind CSS for styling, Framer Motion for animations
- Browser Local Storage for persistence

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Bootstrapping
    subgraph "Client Bootstrapping"
        direction TB
        HTML["index.html"]:::frontend
        DOM["index.tsx"]:::frontend
        App["App.tsx"]:::frontend
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        InputArea["InputArea Component"]:::frontend
        DrawingCanvas["DrawingCanvas Component"]:::frontend
        OutputArea["OutputArea Component"]:::frontend
        Favorites["Favorites Component"]:::frontend
        SettingsModal["SettingsModal Component"]:::frontend
        Icons["Shared Icons"]:::frontend
    end

    %% Hooks Layer
    subgraph "Hooks Layer"
        direction TB
        SpeechHook["useSpeechRecognition Hook"]:::logic
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        GeminiService["geminiService"]:::logic
        Types["types.ts"]:::logic
        Metadata["metadata.json"]:::logic
    end

    %% Configuration
    subgraph "Configuration"
        direction TB
        ViteCfg["vite.config.ts"]:::logic
        TSConfig["tsconfig.json"]:::logic
        Package["package.json"]:::logic
    end

    %% Storage Layer
    subgraph "Storage"
        direction TB
        LocalStorage[(Local Storage)]:::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GeminiAPI["Google Gemini API"]:::external
    end

    %% User Interaction
    User((User)):::external

    %% Flow Connections
    User -->|"clicks UI"| InputArea
    User -->|"draws"| DrawingCanvas
    User -->|"opens Settings"| SettingsModal

    InputArea -->|"text input"| GeminiService
    DrawingCanvas -->|"JPEG blob"| GeminiService
    SettingsModal -->|"read/write API key"| LocalStorage

    InputArea -->|uses shared icons| Icons
    Favorites -->|"save prompt"| LocalStorage
    Favorites -->|"display saved"| OutputArea

    DrawingCanvas -->|"optionally uses Web Speech API"| SpeechHook
    SpeechHook -->|"audio → text"| InputArea

    GeminiService -->|"fetches key"| LocalStorage
    GeminiService -->|"sends request"| GeminiAPI
    GeminiAPI -->|"returns response"| GeminiService
    GeminiService -->|"JSON with prompt variations"| OutputArea

    %% Bootstrapping Flow
    HTML --> DOM
    DOM --> App
    App --> InputArea
    App --> DrawingCanvas
    App --> OutputArea
    App --> Favorites
    App --> SettingsModal

    %% Configuration references
    App --> ViteCfg
    App --> TSConfig
    App --> Package

    %% Click Events
    click App "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/App.tsx"
    click DOM "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/index.tsx"
    click HTML "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/index.html"
    click InputArea "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/InputArea.tsx"
    click DrawingCanvas "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/DrawingCanvas.tsx"
    click OutputArea "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/OutputArea.tsx"
    click Favorites "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/Favorites.tsx"
    click SettingsModal "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/SettingsModal.tsx"
    click Icons "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/components/icons.tsx"
    click SpeechHook "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/hooks/useSpeechRecognition.ts"
    click GeminiService "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/services/geminiService.ts"
    click Types "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/types.ts"
    click Metadata "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/metadata.json"
    click ViteCfg "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/vite.config.ts"
    click TSConfig "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/tsconfig.json"
    click Package "https://github.com/kesavgopan10/ai-prompt-artisan/blob/main/package.json"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0d6efd,color:#084298
    classDef logic fill:#d1e7dd,stroke:#198754,color:#0f5132
    classDef storage fill:#fff3cd,stroke:#ffc107,color:#664d03
    classDef external fill:#f8d7da,stroke:#dc3545,color:#842029
```
