# evanbacon/expo-ai architecture

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

- Interactive diagram: https://gitdiagram.com/evanbacon/expo-ai
- Repository: https://github.com/evanbacon/expo-ai

## Overview

##### Main Components
- Client UI Layer – Represented largely by the contents of the “app” directory and “components” folder. This is where the routed pages (e.g., _layout.tsx, index.tsx) and various UI pieces (e.g., chat components, movie cards, maps components) are defined.
- Server Actions and Rendering Logic – The “actions” folder contains server action files (e.g., render-actor.tsx, render-movie.tsx), which encapsulate calls that render parts of the UI on the server using React Server Components.
- Expo Router and RSC Mechanism – The project is built on Expo Router and uses streaming responses from the server, meaning that the router’s deep linking, navigation, and server functions are core architectural elements.
- External API Integrations – Based on environment variables listed in the README, you have connections to several external services: OpenAI for AI responses, Weather API, TMDB for movie data, and Google/Apple Maps for location data.
- Configuration/Build Infrastructure – Include files like app.json, package.json, metro.config.js, eas.json, and various patch files that configure how the app is built, deployed, and how certain modules are patched for compatibility (e.g., react-server-dom-webpack).

##### Relationships and Interactions
- The Client UI invokes navigation through the Expo Router that internally requests the appropriate server-rendered components (the pages within “app/…”). Display components from “components” provide layout, interaction, and presentation.
- Server actions (in the “actions” folder) are called by the routing logic or UI events. They are responsible for fetching data and streaming server responses that get rendered on the client.
- Environment-dependent configuration ties together the UI/server components with external API calls, where tokens and keys (set via environment variables) enable secure communication with OpenAI, TMDB, Weather API, Google Maps, and Apple Maps.
- The build configuration and deployment flow (using Expo CLI, EAS, and patch files) ensure that the app renders both accurately in development (Expo Go, web) and in production (iOS builds).

##### Architectural Patterns and Principles
- Universal (isomorphic) Rendering – The project uses React Server Components to render on the server and stream down pre-rendered HTML/JS for both web and native, emphasizing code reuse across platforms.
- Modular Organization – Clear separation of routes (app folder), server actions (actions folder), shared UI components (components folder), and configuration (root-level files) indicate a well-modularized approach.
- API Integration Pattern – A design that abstracts access to external APIs via environment variables and server functions, fostering a clean separation between data fetching and UI rendering.

##### Final Recommendations
- User interactions trigger navigation and server calls.
- Server actions call out to external APIs.
- Server streams response data back to the client.
- Annotations for architectural decisions such as the use of Universal RSC, Expo Router, deployment via EAS, and any patching requirements for compatibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client UI Layer
    subgraph "Client UI Layer"
        routes("Routes (app)"):::client
        components("Components (components)"):::client
    end

    %% Expo Router & Server
    subgraph "Expo Router & Server"
        router("Expo Router & Server"):::router
    end

    %% Server Actions
    subgraph "Server Actions"
        actions("Server Actions (actions)"):::server
    end

    %% External APIs
    subgraph "External APIs"
        ext("External APIs"):::external
        openai("OpenAI"):::external
        weather("Weather API"):::external
        tmdb("TMDB"):::external
        google("Google Maps"):::external
        apple("Apple Maps"):::external
        env("Env Config (.env.example)"):::config
    end

    %% Configuration & Build
    subgraph "Configuration & Build"
        appjson("App Config (app.json)"):::config
        eas("EAS Config (eas.json)"):::config
        package("Package (package.json)"):::config
        metro("Metro Config (metro.config.js)"):::config
        patches("Patches (patches)"):::config
        patchscript("Patch Script (patch-ai.js)"):::config
    end

    %% Data Flow Connections
    routes -->|"navigates"| router
    components -->|"rendersUI"| router
    router -->|"callsServerActions"| actions
    actions -->|"fetchesData"| ext
    ext -->|"returnsData"| actions
    actions -->|"streamsResponse"| router
    router -->|"updatesUI"| routes

    %% Configuration influence
    appjson ---|"buildConfig"| router
    eas ---|"deployConfig"| router
    package ---|"moduleDeps"| router
    metro ---|"bundleConfig"| router
    patches ---|"patchesModule"| router
    patchscript ---|"executesPatches"| router

    %% External APIs internal relationships
    openai --- ext
    weather --- ext
    tmdb --- ext
    google --- ext
    apple --- ext

    %% Click Events
    click routes "https://github.com/evanbacon/expo-ai/blob/main/app/_layout.tsx"
    click components "https://github.com/evanbacon/expo-ai/blob/main/components/chat-container.tsx"
    click actions "https://github.com/evanbacon/expo-ai/blob/main/actions/render-root.tsx"
    click appjson "https://github.com/evanbacon/expo-ai/blob/main/app.json"
    click eas "https://github.com/evanbacon/expo-ai/blob/main/eas.json"
    click package "https://github.com/evanbacon/expo-ai/blob/main/package.json"
    click metro "https://github.com/evanbacon/expo-ai/blob/main/metro.config.js"
    click patches "https://github.com/evanbacon/expo-ai/blob/main/patches/react-server-dom-webpack+19.0.0-rc-6230622a1a-20240610.patch"
    click patchscript "https://github.com/evanbacon/expo-ai/blob/main/patch-ai.js"
    click env "https://github.com/evanbacon/expo-ai/blob/main/.env.example"

    %% Class Definitions for Colors
    classDef client fill:#9fdf9f,stroke:#333,stroke-width:2px;
    classDef router fill:#dfc39f,stroke:#333,stroke-width:2px;
    classDef server fill:#9fc3df,stroke:#333,stroke-width:2px;
    classDef external fill:#f9df9f,stroke:#333,stroke-width:2px;
    classDef config fill:#df9fdf,stroke:#333,stroke-width:2px;
```
