# adriantache/gptassistantdesktop architecture

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

- Interactive diagram: https://gitdiagram.com/adriantache/gptassistantdesktop
- Repository: https://github.com/adriantache/gptassistantdesktop

## Overview

##### Project type and purpose
- This is a Kotlin Multiplatform Compose UI application targeting Android and Desktop (Windows, macOS, Linux).
- Its purpose is to provide a GUI for interacting with the OpenAI ChatGPT API (text and image generation), with local persistence (conversation history, personas, settings) via DataStore and optional encryption on Android.

##### File structure
- Top-level:
- build.gradle.kts, settings.gradle.kts, gradle/ – build scripts & version catalog
- composeApp/ – the multiplatform module
- composeApp/src:
- commonMain/ – shared code: domain layer (use cases, entities, data/repo interfaces, mappers), data layer (repositories, data sources, network & DataStore helpers), presentation layer (Compose screens, presenters, state machines), theme & utilities.
- androidMain/ – Android entry point (MainActivity), AndroidManifest, platformSpecific implementations (DataStorePreferences, TtsHelper.android, BackHandler, scrollbar), Android resources.
- desktopMain/ – Desktop entry (main.kt), platformSpecific implementations for JVM/Desktop equivalents.
- Supporting files:
- .github/workflows – CI for Android, desktop releases, PR tests
- gradle.properties, module packaging config (composeApp/build.gradle.kts)

##### README for additional insights
- Confirms Compose UI, Kotlin Serialization + Ktor for networking, DataStore for local storage, personas feature, conversation history, packaging via Gradle (MSI/DMG).
- Mentions pending work (AACA architecture, DI), but core layers already separated following Clean Architecture principles.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Common Main Module
    subgraph "commonMain Module"
        %% Presentation Layer
        subgraph "Presentation Layer"
            App["App.kt"]:::presentation
            Screens["Screens\n(Conversation, Home, ...)"]:::presentation
            Presenters["Presenters &\nStateMachines"]:::presentation
        end

        %% Domain Layer
        subgraph "Domain Layer"
            UseCases["UseCases\n(Conversation, Persona,\nImageGeneration)"]:::domain
            Entities["Entities & Models"]:::domain
        end

        %% Data Layer
        subgraph "Data Layer"
            Repos["Repositories\n(impls)"]:::data
            subgraph "DataSources"
                NetworkDS["Network DataSource\n(StreamingApiCaller,\nApiCaller)"]:::data
                LocalDS["Local DataStore DataSource"]:::data
            end
            Mappers["Mappers\n(DTO↔Domain↔UI)"]:::data
        end

        %% Platform Abstraction
        subgraph "Platform Abstraction"
            PlatformInterfaces["PlatformSpecific\nInterfaces\n(BackHandler, TtsHelper,\nDataStorePreferences)"]:::platform
        end
    end

    %% Platform Implementations
    subgraph "Android"
        MainActivity["MainActivity.kt"]:::platform
        AndroidPlatform["Android PlatformSpecific\nImplementations"]:::platform
    end

    subgraph "Desktop"
        DesktopMain["main.kt"]:::platform
        DesktopPlatform["Desktop PlatformSpecific\nImplementations"]:::platform
    end

    %% External Services
    OpenAI["OpenAI REST API"]:::external
    DataStoreLocal(("Local DataStore")):::external

    %% Edges: Data Flow
    App -->|UI events| Presenters
    Presenters -->|invoke| UseCases
    UseCases -->|call| Repos
    Repos -->|fetch from| NetworkDS
    Repos -->|fetch from| LocalDS
    NetworkDS -->|HTTP requests| OpenAI
    LocalDS -->|read/write| DataStoreLocal
    NetworkDS -->|stream responses| Mappers
    LocalDS -->|persist data| Mappers
    Mappers -->|map to domain| Entities
    Entities -->|used by| UseCases
    UseCases -->|update UI state| Presenters
    Presenters -->|render| Screens
    Screens -->|display| App

    %% Platform connections
    App -->|calls| PlatformInterfaces
    PlatformInterfaces --> AndroidPlatform
    PlatformInterfaces --> DesktopPlatform
    AndroidPlatform -->|Android-specific| MainActivity
    DesktopPlatform -->|Desktop-specific| DesktopMain

    %% CI & Packaging Workflows
    subgraph "CI & Packaging"
        CI1["android_release.yml"]:::external
        CI2["desktop_release.yml"]:::external
        CI3["pr_tests.yml"]:::external
    end
    CI1 -->|runs on PRs/releases| App
    CI2 --> App
    CI3 --> App

    %% Click Events
    click App "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/presentation/App.kt"
    click Screens "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/presentation"
    click Presenters "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/presentation"
    click UseCases "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/domain"
    click Entities "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/domain"
    click Repos "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/data"
    click NetworkDS "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/data/conversation/dataSource/service/StreamingApiCaller.kt"
    click NetworkDS "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/data/conversation/dataSource/service/StreamingApiCallerImpl.kt"
    click NetworkDS "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/data/imageGeneration/service/ApiCaller.kt"
    click LocalDS "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/data/dataStore/DataStoreHelper.kt"
    click LocalDS "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/commonMain/kotlin/data/settings/dataSource/SettingsDataSourceImpl.kt"
    click PlatformInterfaces "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/commonMain/kotlin/platformSpecific"
    click MainActivity "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/androidMain/kotlin/com/adriantache/MainActivity.kt"
    click AndroidPlatform "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/androidMain/kotlin/platformSpecific"
    click DesktopMain "https://github.com/adriantache/gptassistantdesktop/blob/master/composeApp/src/desktopMain/kotlin/main.kt"
    click DesktopPlatform "https://github.com/adriantache/gptassistantdesktop/tree/master/composeApp/src/desktopMain/kotlin/platformSpecific"
    click CI1 "https://github.com/adriantache/gptassistantdesktop/blob/master/.github/workflows/android_release.yml"
    click CI2 "https://github.com/adriantache/gptassistantdesktop/blob/master/.github/workflows/desktop_release.yml"
    click CI3 "https://github.com/adriantache/gptassistantdesktop/blob/master/.github/workflows/pr_tests.yml"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef domain fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef data fill:#FFE8C0,stroke:#333,stroke-width:1px
    classDef platform fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px
```
