# udemy3/chatgpt architecture

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

- Interactive diagram: https://gitdiagram.com/udemy3/chatgpt
- Repository: https://github.com/udemy3/chatgpt

## Overview

##### Main components
- Front-end (Renderer)
- Built with React/TypeScript, Vite-bundled, lives in `/src` + `/src/components` + `/src/view`
- Renders UI, captures user input, displays chat history, file-export dialogs, settings screens
- Back-end (Tauri/Rust)
- CLI core in `src-tauri/src` (modules: `gpt.rs`, `fs_extra.rs`, `cmd.rs`, `script.rs`, etc.)
- Manages IPC commands (`tauri::invoke`), orchestrates ChatGPT API calls, file I/O, templating, menus, windows
- IPC Bridge
- Tauri’s built-in channel that sends JSON RPC–style calls between the WebView and Rust code
- External Services
- OpenAI ChatGPT REST API (network)
- Optional sync sources for slash commands (local files, external repos)
- Local Persistence
- Exports (PNG, PDF, Markdown) via `fs_extra.rs`
- User settings, prompts config (`.json` under user data dir)
- Packaging & Distribution
- Build pipeline: Vite build → embed assets into Tauri bundle → Rust compile → OS-specific installers (`.msi`, `.dmg`, `.deb`, AppImage)
- CI/CD: GitHub Actions workflows (`.github/workflows/release.yml`) generating release artifacts, Homebrew casks (`casks/chatgpt.rb`)

##### Relationships & data flows
- User interacts with UI -> React event handlers -> `tauri.invoke("...")` -> Rust command handlers in corresponding `.rs` modules
- Rust handlers call ChatGPT API or perform FS operations -> return results via IPC -> React updates state & re-renders
- File exports: UI triggers ‘export’ -> Rust streams file to user’s disk
- Settings sync: UI fetches/saves config in Rust, which reads/writes user data paths
- Build chain: source code → front-end build → Rust build → packagers → installers

##### Architectural patterns
- Layered architecture: Presentation Layer (React), Application Layer (Tauri/Rust commands), Infrastructure Layer (network, file system)
- MV* in UI: React components + custom hooks (`useChatPrompt`, `useData`, etc.) manage state & effect side-effects
- Single binary host with embedded WebView
- Event-driven IPC

##### Key technologies & frameworks
- Tauri (Rust + WebView2 / WebKit)
- React + TypeScript + Vite
- Rust (edition 2021, Cargo)
- Node.js scripts (under `/scripts`) for build-time tasks (manifest generation, export helpers)
- CI/CD (GitHub Actions), Homebrew Cask, winget, AppImage

- Component blocks with labels (UI, IPC layer, Rust modules, ChatGPT API, File System, CI/CD)
- Notes on where hooks and scripts live (optional sub-components)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Renderer Process
    subgraph "Renderer Process"
        direction TB
        UI["WebView UI"]:::frontend
        HTML["index.html"]:::frontend
        MainTS["main.tsx"]:::frontend
        Routes["routes.tsx"]:::frontend
        Components["src/components"]:::frontend
        Views["src/view"]:::frontend
        Hooks["src/hooks"]:::frontend
        ViteConfig["vite.config.ts"]:::frontend
    end

    %% IPC Bridge
    subgraph "IPC Bridge"
        direction TB
        IPC["tauri.invoke<br/>(JSON RPC)"]:::ipc
        Wrapper["src/utils.ts"]:::ipc
    end

    %% Main Process
    subgraph "Main Process"
        direction TB
        TauriHost["Tauri Host"]:::backend
        Conf["conf.rs"]:::persistence
        UtilsRust["utils.rs"]:::backend
        MainRust["main.rs"]:::backend
        TauriConf["tauri.conf.json"]:::backend

        subgraph "Command Modules"
            direction TB
            GPT["gpt.rs"]:::backend
            FSExtra["fs_extra.rs"]:::persistence
            CMD["cmd.rs"]:::backend
            Script["script.rs"]:::backend
            Template["template.rs"]:::backend
            Menu["menu.rs"]:::backend
            Window["window.rs"]:::backend
            Setup["setup.rs"]:::backend
            Mod["mod.rs"]:::backend
        end
    end

    %% External Services & Persistence
    subgraph "External & Persistence"
        direction TB
        ChatAPI["OpenAI ChatGPT API"]:::external
        FileSystem["Local File System"]:::persistence
    end

    %% Packaging & CI/CD
    subgraph "Packaging & CI/CD"
        direction TB
        CI[".github/workflows/release.yml"]:::packaging
        Cask["casks/chatgpt.rb"]:::packaging
        Scripts["scripts/*.js<br/>scripts/manifest.json"]:::packaging
    end

    %% Data Flows
    UI -->|renders & events| IPC
    IPC -->|invoke commands| GPT
    IPC -->|invoke commands| FSExtra
    IPC -->|invoke commands| CMD
    IPC -->|invoke commands| Script
    IPC -->|invoke commands| Template
    IPC -->|invoke commands| Menu
    IPC -->|invoke commands| Window
    IPC -->|invoke commands| Setup

    GPT -->|HTTP POST| ChatAPI
    FSExtra -->|file I/O| FileSystem
    Conf -->|read/write config| FileSystem

    GPT -->|response| IPC
    FSExtra -->|response| IPC

    IPC -->|update state| UI

    %% Packaging Flow
    UI -.->|source| CI
    MainRust -.->|source| CI
    CI -->|build & bundle| Scripts
    Scripts -->|generate installers| Cask

    %% Click Events
    click HTML "https://github.com/udemy3/chatgpt/blob/main/index.html"
    click MainTS "https://github.com/udemy3/chatgpt/blob/main/src/main.tsx"
    click Routes "https://github.com/udemy3/chatgpt/blob/main/src/routes.tsx"
    click Components "https://github.com/udemy3/chatgpt/tree/main/src/components"
    click Views "https://github.com/udemy3/chatgpt/tree/main/src/view"
    click Hooks "https://github.com/udemy3/chatgpt/tree/main/src/hooks"
    click ViteConfig "https://github.com/udemy3/chatgpt/blob/main/vite.config.ts"
    click Wrapper "https://github.com/udemy3/chatgpt/blob/main/src/utils.ts"

    click MainRust "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/main.rs"
    click Conf "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/conf.rs"
    click UtilsRust "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/utils.rs"
    click TauriConf "https://github.com/udemy3/chatgpt/blob/main/src-tauri/tauri.conf.json"

    click GPT "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/gpt.rs"
    click FSExtra "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/fs_extra.rs"
    click CMD "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/cmd.rs"
    click Script "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/script.rs"
    click Template "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/template.rs"
    click Menu "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/menu.rs"
    click Window "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/window.rs"
    click Setup "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/setup.rs"
    click Mod "https://github.com/udemy3/chatgpt/blob/main/src-tauri/src/app/mod.rs"

    click CI "https://github.com/udemy3/chatgpt/blob/main/.github/workflows/release.yml"
    click Cask "https://github.com/udemy3/chatgpt/blob/main/casks/chatgpt.rb"
    click Scripts "https://github.com/udemy3/chatgpt/blob/main/scripts/manifest.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#DFFFE0,stroke:#28a745,color:#22863a
    classDef ipc fill:#FFF5CC,stroke:#dbab09,color:#735c0f
    classDef external fill:#EDEDED,stroke:#6a737d,color:#586069
    classDef persistence fill:#FFF0E0,stroke:#d15704,color:#6f4100
    classDef packaging fill:#F3E5FF,stroke:#6f42c1,color:#5a32a3
```
