# balaji-sb/rtk-query-with-react-native architecture

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

- Interactive diagram: https://gitdiagram.com/balaji-sb/rtk-query-with-react-native
- Repository: https://github.com/balaji-sb/rtk-query-with-react-native

## Overview

##### Project type and purpose
- This is a React Native mobile application (iOS & Android) using Redux Toolkit Query for data fetching.
- Purpose: display and manage a Todo list via a remote REST API.

##### File structure
- Top-level “android” and “ios” folders: native platform projects with Gradle and Xcode configurations.
- “App.tsx” & “index.js”: entry point into the JavaScript app.
- “src/” contains all JS/TS code, divided into:
- “ui/” – React components (TodoListUi)
- “redux/” – store setup, RTK logger, provider wrappers
- “services/” – API definitions (TodoApi, api.ts), service constants
- “model/” – TypeScript types for API responses
- “hooks/” – custom selectors
- Config files: babel.config.js, metro.config.js, jest.config.js, tsconfig.json.

##### README for additional insights
- Bootstrapped with React Native CLI.
- Standard Metro bundler → JavaScript bundle → native runtime.
- No custom backend: the app consumes external Todo API endpoints via RTK Query.

##### Main components
a. Mobile device (iOS Simulator / Android Emulator / Physical Device)
b. Metro Bundler & Packager (development only)
c. JavaScript runtime & React Native Bridge
d. React components (UI layer)
e. Redux store & middleware (RTK Logger)
f. RTK Query “Api slice” service layer (TodoApi + baseApi)
g. Network layer (fetch/XHR)
h. External REST API (TodoList service)
i. Native modules (Android / iOS code for device capabilities)

##### Relationships and interactions
- On app launch, Metro serves the bundle → JS runtime loaded onto device → React Native Bridge initializes native modules.
- UI components dispatch Redux actions or RTK Query hooks.
- Redux store updates state; RTK Query middleware intercepts data-fetching actions.
- RTK Query issues network requests to External API.
- Responses flow back through RTK Query → Redux store → trigger UI re-render.
- Native modules invoked indirectly by React Native Bridge for device-specific features (if any).

##### Architectural patterns & design principles
- Unidirectional data flow (React → Redux → RTK Query → API → Redux → React).
- Separation of concerns:
- UI layer (stateless components)
- State management layer (Redux store + middleware)
- Data fetching layer (RTK Query slices)
- Networking layer (fetch wrapper in services)
- Strong typing via TypeScript models for API contracts.

##### Relevant technologies/frameworks
- React Native (JS UI + Native Bridge)
- Redux Toolkit (store.ts, ProviderList, StoreProvider)
- RTK Query (TodoApi, api.ts)
- TypeScript (tsconfig.json, *.ts/.tsx)
- Metro bundler (metro.config.js)
- Native toolchains (Gradle for Android, Xcode for iOS)

##### Elements
- User → UI → Redux Dispatch
- Redux → RTK Query → Network → API
- API → RTK Query → Redux → UI
- Orange cloud for External API
- Gray for development tools (Metro)

##### Detailed layer breakdown (suggested grouping)
[User Device]
└── React Native Bridge
├── UI Layer (src/ui/*.tsx)
├── State Layer (src/redux/*.tsx, store.ts)
│      └── RTK Logger middleware
├── Data Layer (src/services/api.ts, TodoApi.ts)
│      └── ServiceConstants.ts
└── Models & Hooks (src/model, src/hooks)
[Network]
↔ fetch / axios wrapper
[External]
└── Todo REST API

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Dev Tools (Development Only)"
        direction TB
        Metro["Metro Bundler & Packager"]:::dev
        Entry["JS Entry Point\n(App.tsx, index.js)"]:::js
        Metro --> Entry
        Entry --> RNBridge
    end

    subgraph "Mobile Device"
        direction TB
        RNBridge["React Native Bridge"]:::native

        subgraph "JS Layers"
            direction TB
            UI["UI Layer\n(src/ui/TodoListUi.tsx)"]:::js
            State["Redux Store & Middleware\n(src/redux)"]:::js
            Data["RTK Query API Slice\n(src/services)"]:::js
            ModelsHooks["Models & Hooks\n(src/model, src/hooks)"]:::js
        end

        RNBridge --> UI
        UI -->|dispatch| State
        State -->|RTK Query| Data
        Data -->|network| Network
        Data --> State
        State --> UI
    end

    subgraph "Native Modules"
        direction TB
        AndroidNative["Android Native Modules"]:::native
        IOSNative["iOS Native Modules"]:::native
        RNBridge --> AndroidNative
        RNBridge --> IOSNative
    end

    Network["Networking Layer\n(fetch/XHR)"]:::js
    External["External Todo REST API"]:::external

    Network --> External
    External --> Network

    classDef js fill:#bfdbfe,stroke:#1e40af,color:#1e3a8a;
    classDef native fill:#bbf7d0,stroke:#15803d,color:#065f46;
    classDef external fill:#fed7aa,stroke:#c2410c,color:#7c2d12;
    classDef dev fill:#e5e7eb,stroke:#6b7280,color:#374151;

    click AndroidNative "https://github.com/balaji-sb/rtk-query-with-react-native/tree/main/android/app/src/main/java/com/rtkquerysample"
    click IOSNative "https://github.com/balaji-sb/rtk-query-with-react-native/tree/main/ios/RTKQuerySample"
    click Metro "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/metro.config.js"
    click Metro "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/babel.config.js"
    click Entry "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/App.tsx"
    click Entry "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/index.js"
    click UI "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/ui/TodoListUi.tsx"
    click State "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/redux/store.ts"
    click State "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/redux/RTKLogger.ts"
    click State "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/redux/ProviderList.tsx"
    click State "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/redux/StoreProvier.tsx"
    click Data "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/services/api.ts"
    click Data "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/services/TodoApi.ts"
    click Data "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/services/ServiceConstants.ts"
    click ModelsHooks "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/model/TodoListResponse.ts"
    click ModelsHooks "https://github.com/balaji-sb/rtk-query-with-react-native/blob/main/src/hooks/useAppSelector.ts"
```
