# ttkindboy/gdocs-ai-fancifier architecture

> Architecture diagram of the GitHub repository ttkindboy/gdocs-ai-fancifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ttkindboy/gdocs-ai-fancifier
- Repository: https://github.com/ttkindboy/gdocs-ai-fancifier

## Overview

##### Main Components

a) Client-Side Components:
- Google Docs Interface
- Google Apps Script Runtime
- Document Processing Module
- OpenAI Integration Module

b) External Services:
- OpenAI API Service

##### Component Relationships

1. User → Google Docs UI
2. Google Docs UI → Code.gs (main function)
3. Code.gs → Document Processing (readDocument, processText, replaceText)
4. openai.gs → OpenAI API

##### Specific Implementation Details

**[Google Docs UI] → [Code.gs (main)]**
- ↓
**[Document Processing]**
- ↓ readDocument()
- ↓ processText()
- ↓ replaceText()
- ↓
**[OpenAI Integration]**
- ↓ callOpenAI()
- ↓
**[OpenAI API]**

##### Technical Details

Notes for:
- API endpoint (/v1/chat/completions)
- Model used (gpt-3.5-turbo)
- Authentication method (Bearer token)
- Response handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User
        UI[Google Docs UI]:::google
    end

    subgraph "Google Apps Script Runtime"
        Main[Code.gs - Main Function]:::google
        click Main "https://github.com/TTkindboy/gdocs-ai-fancifier/blob/main/Code.gs"
        
        subgraph "Document Processing"
            DP[Document Handler]:::process
            click DP "https://github.com/TTkindboy/gdocs-ai-fancifier/blob/main/Code.gs"
            Read[readDocument]:::function
            Process[processText]:::function
            Replace[replaceText]:::function
        end

        subgraph "OpenAI Integration"
            OAI[OpenAI Handler]:::process
            click OAI "https://github.com/TTkindboy/gdocs-ai-fancifier/blob/main/openai.gs"
            APICall[callOpenAI]:::function
            Auth[API Authentication]:::security
        end
    end

    subgraph "External Services"
        OpenAI["OpenAI API
        /v1/chat/completions
        gpt-3.5-turbo"]:::external
    end

    %% Connections
    UI --> Main
    Main --> DP
    DP --> Read
    Read --> Process
    Process --> Replace
    Process --> OAI
    OAI --> Auth
    OAI --> APICall
    APICall --> OpenAI
    OpenAI --> APICall
    APICall --> Process
    Replace --> UI

    %% Styles
    classDef google fill:#4285F4,color:white
    classDef process fill:#34A853,color:white
    classDef function fill:#FBBC05,color:black
    classDef security fill:#EA4335,color:white
    classDef external fill:#9C27B0,color:white

    %% Legend
    subgraph Legend
        L1[Google Services]:::google
        L2[Process Modules]:::process
        L3[Functions]:::function
        L4[Security]:::security
        L5[External Services]:::external
    end
```
