# galaxies-dev/chatgpt-clone-react-native architecture

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

- Interactive diagram: https://gitdiagram.com/galaxies-dev/chatgpt-clone-react-native
- Repository: https://github.com/galaxies-dev/chatgpt-clone-react-native

## Overview

Based on your project’s file tree and README content, the project is a React Native mobile app that mimics ChatGPT and leverages multiple external services. It uses Expo’s file‐based routing to organize various screens and flows (authentication, drawer navigation for chat and additional functionalities, and modals for settings, purchases, and image handling). Additionally, the project integrates Clerk for user authentication and RevenueCat for in-app purchase management, along with using external APIs from OpenAI for GPT chat and image generation.

##### Main Components
- Mobile Client (React Native App): Represent the core user interface built with React Native. Split this into areas using Expo Router – notably:
- Authentication flow (login, and screens under app/(auth))
- Drawer-based navigation (screens under app/(auth)/(drawer) including chat, explore, and DALL·E image generation)
- Modal screens (under app/(auth)/(modal) for image, purchase, and settings)
- Main landing screen (app/index.tsx and app/login.tsx)
- Reusable UI Components: Group components found in the “components” directory (e.g., ChatMessage, ChatPage, AnimatedIntro, BottomLoginSheet, etc.) which support the core screens.
- Providers: Highlight the integration point for RevenueCat (providers/RevenueCat.tsx), which is used for managing in-app purchase flows.
- Assets: Indicate the “assets” folder containing fonts and images used across the UX.
- External APIs & Services:
- Clerk for user authentication (login flow)
- RevenueCat for in-app purchase management
- OpenAI API for chat completions and image generation
- Other libraries (Reanimated, Gesture Handler, Redash, Zeego, RN MMKV, Expo SQLite, Bottom Sheet, FlashList, etc.)

##### Relationships & Data Flow
- Mobile Client Components interact with UI Components (from the “components” folder) to render the screens.
- The Navigation Hierarchy (defined by the app file tree) communicates with the Authentication submodule when a user logs in or signs up with Clerk.
- Once authenticated, the Drawer and Modal navigators allow users to access chat and media functionalities.
- RevenueCat Provider is used in the central purchase flow – connect this component with both the UI (purchase screens) and with the External RevenueCat service.
- Utility modules like Database (using Expo SQLite) and Storage (using RN MMKV) handle local data storage for chat history, user settings, etc.

##### Architectural Patterns & Design Principles
- Separation of concerns is evident: Navigation and screens are clearly separated from business logic (utilities and providers) and external services.
- Modularity by grouping similar functionalities (e.g., chat features, modal flows, navigation flows) into distinct nodes.

##### Elements to Incorporate
- From the login screen to Clerk’s authentication service.
- From chat components to the OpenAI service.
- From purchase modals to the RevenueCat provider.
- From UI events to utility functions and local storage updates.
- Notes or annotations highlighting architectural patterns (e.g., “File-based routing with Expo Router”, “Modular component-based design”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Mobile Client (React Native UI) Subgraph
    subgraph "Mobile Client (React Native UI)"
        direction TB
        ML["Main Landing Screen"]:::mobile
        LS["Login Screen"]:::mobile
        subgraph "Authentication Flow"
            direction TB
            AL["Auth Layout"]:::mobile
        end
        subgraph "Drawer Navigation"
            direction TB
            DLayout["Drawer Layout"]:::mobile
            ChatId["Chat Screen ([id].tsx)"]:::mobile
            NewChat["New Chat (new.tsx)"]:::mobile
            Explore["Explore Screen"]:::mobile
            Dalle["DALL·E Screen"]:::mobile
        end
        subgraph "Modal Components"
            direction TB
            ImageModal["Image Modal"]:::mobile
            PurchaseModal["Purchase Modal"]:::mobile
            SettingsModal["Settings Modal"]:::mobile
        end
    end

    %% Reusable UI Components Subgraph
    subgraph "Reusable UI Components"
        direction TB
        ChatMessage["ChatMessage"]:::ui
        ChatPage["ChatPage"]:::ui
        AnimatedIntro["AnimatedIntro"]:::ui
        BottomLoginSheet["BottomLoginSheet"]:::ui
        DropDownMenu["DropDownMenu"]:::ui
        HeaderDropDown["HeaderDropDown"]:::ui
        MessageIdeas["MessageIdeas"]:::ui
        MessageInput["MessageInput"]:::ui
    end

    %% Providers, Utilities, Assets and External Services
    Providers["RevenueCat Provider"]:::provider
    Utilities["Utilities & Constants"]:::util
    Assets["Assets"]:::asset
    Clerk["Clerk (Authentication)"]:::external
    OpenAI["OpenAI API (Chat/Image)"]:::external
    RevenueCatExt["RevenueCat Service"]:::external

    %% Data Flow and Relationships
    LS -->|"navigates"| AL
    AL -->|"routes to"| DLayout
    ML -->|"displays"| LS

    DLayout -->|"shows"| ChatId
    DLayout -->|"shows"| NewChat
    DLayout -->|"shows"| Explore
    DLayout -->|"shows"| Dalle

    LS -->|"authenticatesVia"| Clerk
    Clerk -->|"returnsAuthTo"| AL

    ChatMessage -->|"rendersIn"| ChatPage
    ChatPage -->|"savesChatTo"| Utilities
    MessageInput -->|"sendsDataTo"| OpenAI

    PurchaseModal -->|"triggersPurchaseVia"| Providers
    Providers -->|"communicatesWith"| RevenueCatExt

    ImageModal -->|"requestsImageFrom"| OpenAI

    ChatPage -->|"uses"| Utilities
    AnimatedIntro -->|"uses"| Utilities

    ML -->|"loads"| Assets

    LS -->|"composedOf"| ChatMessage
    LS -->|"composedOf"| MessageInput

    %% Click Events Mapping
    click ML "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/index.tsx"
    click LS "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/login.tsx"
    click AL "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/_layout.tsx"
    click DLayout "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(drawer)/_layout.tsx"
    click ChatId "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(drawer)/(chat)/[id].tsx"
    click NewChat "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(drawer)/(chat)/new.tsx"
    click Explore "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(drawer)/explore.tsx"
    click Dalle "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(drawer)/dalle.tsx"
    click ImageModal "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(modal)/image/[url].tsx"
    click PurchaseModal "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(modal)/purchase.tsx"
    click SettingsModal "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/app/(auth)/(modal)/settings.tsx"

    click ChatMessage "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/ChatMessage.tsx"
    click ChatPage "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/ChatPage.tsx"
    click AnimatedIntro "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/AnimatedIntro.tsx"
    click BottomLoginSheet "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/BottomLoginSheet.tsx"
    click DropDownMenu "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/DropDownMenu.tsx"
    click HeaderDropDown "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/HeaderDropDown.tsx"
    click MessageIdeas "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/MessageIdeas.tsx"
    click MessageInput "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/components/MessageInput.tsx"

    click Providers "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/providers/RevenueCat.tsx"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/constants/Colors.ts"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/constants/Styles.ts"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/utils/Database.ts"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/utils/Image.ts"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/utils/Interfaces.ts"
    click Utilities "https://github.com/galaxies-dev/chatgpt-clone-react-native/blob/main/utils/Storage.ts"
    click Assets "https://github.com/galaxies-dev/chatgpt-clone-react-native/tree/main/assets/"

    %% Class Definitions for Colors and Styles
    classDef mobile fill:#AEDFF7,stroke:#333,stroke-width:1px;
    classDef ui fill:#D1F2A5,stroke:#333,stroke-width:1px;
    classDef provider fill:#F9E79F,stroke:#333,stroke-width:1px;
    classDef util fill:#FADBD8,stroke:#333,stroke-width:1px;
    classDef asset fill:#D6EAF8,stroke:#333,stroke-width:1px;
    classDef external fill:#F5B7B1,stroke:#333,stroke-width:1px;
```
