# advantys/react-native-react-query-demo architecture

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

- Interactive diagram: https://gitdiagram.com/advantys/react-native-react-query-demo
- Repository: https://github.com/advantys/react-native-react-query-demo

## Overview

##### Project Type & Purpose
- This is a full-stack demo application showcasing how to wire up a React Native (Expo) frontend with a Hasura-powered GraphQL backend. It highlights React Query features (caching, infinite queries, subscriptions, optimistic updates), GraphQL code generation, and local cache persistence.

##### High-Level File Structure Analysis
- Top-level “hasura/” folder: Docker Compose setup, metadata, and SQL migrations for Hasura + Postgres.
- App root: Expo config (`app.json`/`app.config.ts`), `App.tsx`.
- `src/`: split into `components/`, `screens/`, `navigation/`, `hooks/`, `providers/`, `services/`, `styles/`.
- Testing infra under `__tests__`, `src/**/*/__tests__`, and `src/test/`.
- Config files: `.graphqlrc.yml`, `babel.config.js`, `jest.config.js`, TypeScript config.

##### Key README Insights
- Frontend: Expo + TypeScript, React Query + graphql-request + GraphQL code generator, React Native Paper UI, React Navigation, Suspense/Error boundaries.
- Backend: Hasura + Postgres, run via Docker Compose, with metadata & migrations auto-applied.
- Demonstrates queries, infinite scrolling, subscriptions, cache persistence (AsyncStorage), optimistic updates, and various auto-refetch triggers.

##### Main Components & Interactions
a. Frontend Layers
- UI Layer: React Native screens (`MoviesList`, `MovieDetails`), shared `components/`.
- Navigation Layer: React Navigation (`src/navigation/MainStack`).
- State & Data Layer:
- React Query client (in `providers/GraphQLClientProvider.tsx`) handles queries, mutations, subscriptions.
- Persistence: React Query’s AsyncStorage persister (`services/persister`).
- Network & Theme Contexts: `NetworkStatusProvider`, `ThemeModeProvider`.
- GraphQL Codegen: generates hooks/types under `src/graphql` + custom hooks in `src/hooks/`.
b. Backend
- Hasura GraphQL Engine container, exposes HTTP & WebSocket endpoints (`/v1/graphql`).
- Postgres container storing `movies` tables.
- Migrations & Metadata: define tables, seed data, actions, cron triggers, allow-list, subscriptions config.

c. Data Flow
1. User taps UI → React Query hook calls `graphql-request` client
2. HTTP request to Hasura → Postgres → JSON response
3. React Query caches result → UI renders, persists to AsyncStorage
4. On subscriptions, WebSocket connection kept open → real-time updates flow back into React Query cache

##### Architectural Patterns & Principles
- Single Responsibility: UI vs data-fetching vs persistence vs context providers.
- Hook-first: Custom hooks (`useInfiniteMovies`, `useMovieDetails`, etc.) encapsulate queries/mutations.
- Context Providers: centralize client, network, theme state.
- Code Generation: ensures type safety between frontend and GraphQL schema.
- Containerization: backend stacks run in isolated Docker services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Expo App Container
    subgraph "Expo App (Frontend)"
        direction TB
        App["App.tsx"]:::frontend
        Config["app.json / app.config.ts"]:::frontend
        subgraph "Navigation"
            direction TB
            MainStack["MainStack/index.tsx"]:::frontend
            NavTypes["types.ts"]:::frontend
        end
        subgraph "Screens"
            direction TB
            MoviesList["MoviesList.tsx"]:::frontend
            MovieDetails["MovieDetails.tsx"]:::frontend
        end
        subgraph "Shared UI Components"
            direction TB
            Components["components/"]:::frontend
        end
        subgraph "Context Providers"
            direction TB
            GraphQLProvider["GraphQLClientProvider.tsx"]:::service
            NetworkProvider["NetworkStatusProvider.tsx"]:::service
            ThemeProvider["ThemeModeProvider.tsx"]:::service
        end
    end

    %% React Query Client + Persistence Container
    subgraph "React Query & Persistence" 
        direction TB
        QueryClientCfg["queryClient/index.ts"]:::service
        PersisterSvc["persister/index.ts"]:::service
        GraphQLRequest["graphql/index.ts"]:::service
        AsyncStorage["AsyncStorage"]:::storage
    end

    %% Hasura Backend Container
    subgraph "Hasura Engine"
        direction TB
        DockerCompose["docker-compose.yml"]:::backend
        Metadata["metadata/"]:::backend
        Migrations["migrations/"]:::backend
    end

    %% Postgres Database
    Postgres[(Postgres DB)]:::storage

    %% Data Flow Arrows
    MoviesList -->|"useInfiniteMovies hook"| GraphQLProvider
    MovieDetails -->|"useMovieDetails hook"| GraphQLProvider
    GraphQLProvider -->|"uses QueryClient"| QueryClientCfg
    QueryClientCfg -->|"uses persister"| PersisterSvc
    PersisterSvc -->|"reads/writes"| AsyncStorage
    QueryClientCfg -->|"uses request client"| GraphQLRequest
    GraphQLRequest -->|"HTTP"/Hasura| DockerCompose
    QueryClientCfg -->|"WebSocket"/Hasura| DockerCompose
    DockerCompose -->|"queries"| Postgres

    %% Click Events
    click App "https://github.com/advantys/react-native-react-query-demo/blob/main/App.tsx"
    click Config "https://github.com/advantys/react-native-react-query-demo/blob/main/app.json"
    click Config "https://github.com/advantys/react-native-react-query-demo/blob/main/app.config.ts"
    click MainStack "https://github.com/advantys/react-native-react-query-demo/blob/main/src/navigation/MainStack/index.tsx"
    click NavTypes "https://github.com/advantys/react-native-react-query-demo/blob/main/src/navigation/types.ts"
    click MoviesList "https://github.com/advantys/react-native-react-query-demo/blob/main/src/screens/MoviesList/MoviesList.tsx"
    click MovieDetails "https://github.com/advantys/react-native-react-query-demo/blob/main/src/screens/MovieDetails/MovieDetails.tsx"
    click Components "https://github.com/advantys/react-native-react-query-demo/tree/main/src/components/"
    click QueryClientCfg "https://github.com/advantys/react-native-react-query-demo/blob/main/src/services/queryClient/index.ts"
    click PersisterSvc "https://github.com/advantys/react-native-react-query-demo/blob/main/src/services/persister/index.ts"
    click GraphQLRequest "https://github.com/advantys/react-native-react-query-demo/blob/main/src/services/graphql/index.ts"
    click GraphQLProvider "https://github.com/advantys/react-native-react-query-demo/blob/main/src/providers/GraphQLClientProvider.tsx"
    click NetworkProvider "https://github.com/advantys/react-native-react-query-demo/blob/main/src/providers/NetworkStatusProvider.tsx"
    click ThemeProvider "https://github.com/advantys/react-native-react-query-demo/blob/main/src/providers/ThemeModeProvider.tsx"
    click DockerCompose "https://github.com/advantys/react-native-react-query-demo/blob/main/hasura/docker-compose.yml"
    click Metadata "https://github.com/advantys/react-native-react-query-demo/tree/main/hasura/metadata/"
    click Migrations "https://github.com/advantys/react-native-react-query-demo/tree/main/hasura/migrations/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#000
    classDef backend fill:#DFFFE0,stroke:#000
    classDef service fill:#FFE8A0,stroke:#000
    classDef storage fill:#FFC0CB,stroke:#000
```
