# fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll architecture

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

- Interactive diagram: https://gitdiagram.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll
- Repository: https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll

## Overview

##### Project Type & Purpose
- This is a React Native mobile application (iOS & Android) following Clean Architecture with an MVVM pattern, using React Query for data fetching and an infinite-scroll hook.
- It surfaces three key data domains: Users (from a REST endpoint), Pokémon, and Rick & Morty Characters.

##### File Structure Analysis
Top-level:
- android/ & ios/ – native project code (Kotlin/Java + Swift/Obj-C).
- src/ – JavaScript/TypeScript code organized into four layers:
– presentation/ (pages + ViewModels)
– infrastructure/ (network clients, hooks, ReactQuery provider)
– application/ (services, repositories)
– domain/ (entities, use cases)
- index.js & App.tsx – the JS entrypoints & Metro bundler configuration.
- config files (.babelrc, tsconfig, jest, eslint, metro.config.js).

##### Key README Insights
- Bootstrapped with React Native CLI.
- No built-in backend; it consumes external public APIs.
- Uses Yarn, Metro, React Query, TypeScript, and Jest for testing.

##### Main Components
a. Mobile Client (React Native JS runtime)
- UI Layer (presentation): Screens & navigation
- ViewModels (MVVM)
- ReactQuery Provider & infinite-scroll hook
b. Domain Layer
- Entities (User, Character, Pokémon)
- Use Cases (GetUserUseCase, GetCharactersUseCase, GetPokemonsUseCase)
c. Application Layer
- Repositories (UserRepository, CharacterRepository, PokemonRepository)
- Services (Pokemon.service.ts, RickAndMorty.service.ts, etc.)
d. Infrastructure Layer
- Network Stack (ApiClient + axiosInterceptor)
- ReactQuery integration, custom hooks
e. Platform Native Modules
- Android (MainActivity.kt, Gradle modules)
- iOS (AppDelegate.mm, Xcode project)
f. External APIs
- Pokémon API
- Rick & Morty API
- Users REST endpoint

##### Relationships & Data Flow
- UI screens invoke methods on their ViewModels.
- ViewModels use React Query hooks that call Use Cases.
- Use Cases orchestrate domain logic and delegate data access to Repositories.
- Repositories call Services, which use ApiClient to communicate with External APIs.
- ApiClient applies global axios interceptors for auth, error handling, logging.
- Results flow back up: API → ApiClient → Service → Repository → Use Case → React Query → ViewModel → UI.

##### Architectural Patterns & Principles
- Clean Architecture (separation into layers, dependency rule: outer → inner)
- MVVM (presentation with ViewModels bound to views)
- Dependency Injection (pass ApiClient into services/repositories)
- Single Responsibility (each layer has distinct concerns)
- React Query for caching, deduplication, polling.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        UI["Screens & Navigation"]:::presentation
        VM["ViewModels"]:::presentation
    end

    %% React Query & Hooks
    subgraph "React Query & Hooks"
        direction TB
        RQ["QueryProvider"]:::reactquery
        H["useInfiniteScroll"]:::reactquery
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        UEnt["Entities"]:::domain
        GU["GetUserUseCase"]:::domain
        GCh["GetCharactersUseCase"]:::domain
        GP["GetPokemonsUseCase"]:::domain
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        UR["UserRepository"]:::application
        CR["CharacterRepository"]:::application
        PR["PokemonRepository"]:::application
        SRV1["Pokemon.service.ts"]:::application
        SRV2["RickAndMorty.service copy.ts"]:::application
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        Api["ApiClient"]:::infrastructure
        Int["axiosInterceptor"]:::infrastructure
    end

    %% External APIs
    subgraph "External APIs"
        direction TB
        PokeAPI["Pokémon API"]:::external
        RMAPI["Rick & Morty API"]:::external
        UsersAPI["Users REST"]:::external
    end

    %% Native Modules
    subgraph "Native Modules"
        direction TB
        MA["MainActivity.kt"]:::native
        MAP["MainApplication.kt"]:::native
        AD["AppDelegate.mm"]:::native
        MAINIOS["main.m"]:::native
    end

    %% Connections - Request Flow
    UI -->|invokes| VM
    VM -->|uses| RQ
    VM -->|uses| H
    RQ -->|calls| GU
    RQ -->|calls| GCh
    RQ -->|calls| GP
    H -->|triggers| GU
    H -->|triggers| GCh
    H -->|triggers| GP
    GU -->|depends on| UR
    GCh -->|depends on| CR
    GP -->|depends on| PR
    UR -->|calls| Api
    CR -->|calls| SRV2
    PR -->|calls| SRV1
    SRV1 -->|uses| Api
    SRV2 -->|uses| Api
    Int -->|applies to| Api
    Api -->|requests| PokeAPI
    Api -->|requests| RMAPI
    Api -->|requests| UsersAPI

    %% Click Events
    click UI "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/tree/main/src/presentation/pages"
    click VM "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/tree/main/src/presentation/viewModels"
    click RQ "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/infrastructure/reactQuery/QueryProvider.tsx"
    click H "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/infrastructure/hooks/useInfinitiScroll.ts"
    click UEnt "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/tree/main/src/domain/entities"
    click GU "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/domain/usecases/GetUserUseCase.ts"
    click GCh "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/domain/usecases/GetCharactersUseCase.ts"
    click GP "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/domain/usecases/GetPokemonsUseCase.ts"
    click UR "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/application/repositories/UserRepository.ts"
    click CR "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/application/repositories/CharacterRepository.ts"
    click PR "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/application/repositories/PokemonRepository.ts"
    click SRV1 "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/application/services/Pokemon.service.ts"
    click SRV2 "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/application/services/RickAndMorty.service copy.ts"
    click Api "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/infrastructure/network/ApiClient.ts"
    click Int "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/src/infrastructure/network/axiosInterceptor.ts"
    click MA "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/android/app/src/main/java/com/cleanarc/MainActivity.kt"
    click MAP "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/android/app/src/main/java/com/cleanarc/MainApplication.kt"
    click AD "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/ios/CleanArc/AppDelegate.mm"
    click MAINIOS "https://github.com/fturkyilmaz/react-native-clean-architecture-mvvm-react-query--infinite-scroll/blob/main/ios/CleanArc/main.m"

    %% Styles
    classDef presentation fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef reactquery fill:#F0E6FF,stroke:#6F42C1,color:#6F42C1;
    classDef domain fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef application fill:#FFEFD0,stroke:#D29922,color:#D29922;
    classDef infrastructure fill:#E6F7FF,stroke:#17A2B8,color:#17A2B8;
    classDef external fill:#F2F2F2,stroke:#6C757D,color:#6C757D;
    classDef native fill:#FFF5E6,stroke:#BD5D38,color:#BD5D38;
```
