# marcgirbaub/marvelapp architecture

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

- Interactive diagram: https://gitdiagram.com/marcgirbaub/marvelapp
- Repository: https://github.com/marcgirbaub/marvelapp

## Overview

##### Project type and purpose
- This is a React Native mobile app (“Marvel App”) built in TypeScript.
- It serves as an interactive guide to the Marvel universe: users log in, browse paginated lists of heroes and comics, get detail screens, and data is fetched from the external Marvel API.

##### File structure
- Top‐level native shells: /android and /ios directories containing platform projects, Gradle and Xcode configurations, native entry points (MainActivity.java, AppDelegate.m).
- JS entrypoints: index.js and App.tsx.
- src folder organized by layers:
- components/ (presentational UI)
- screens/ (pages wired to navigation)
- navigation/ (React Navigation stack, routes, wrappers)
- hooks/ (custom hooks encapsulating data‐loading and business logic)
- store/ (React Context + Redux Toolkit slices, providers, store setup)
- utils/, constants/, types/, styles/
- Config files for build, linting, testing (.eslintrc.js, babel.config.js, metro.config.js, jest.setup.ts).

##### README for additional insights
- Tech stack: React Native, TypeScript, React Context, Redux Toolkit, Apisauce (HTTP client), React Navigation.
- Architectural patterns: adapter pattern for separating logic (hooks) from components, caching via proxy object, Clean Code / SOLID.

##### Main components
a. Native Shells
- Android and iOS platform projects launch the React Native runtime and load the JS bundle.
b. JS Runtime & Bundler
- Metro Bundler → delivers JS bundle to device, runs in JSCore/V8.
c. Presentation Layer
- Screens (HomeScreen, HeroDetailScreen, LoginScreen), Components (HeroCard, ComicsList, Header, etc.)
- React Navigation StackNavigator routes and wrappers.
d. Domain Layer (Business Logic)
- Custom Hooks (useLoadData, useLoadCurrentHero, useUser, useStorage) implementing the adapter pattern.
e. State & Data Layer
- React Context providers (ApiRequestContext, CachedRequestsProvider)
- Redux store (slices for hero and user), dispatchers exposed via hooks (store/redux/hooks.ts)
f. API Layer
- Apisauce clients configured to call Marvel API endpoints
- Caching proxy object intercepting identical requests and serving cached responses
g. External Services
- Marvel REST API over HTTPS
h. Local Persistence
- AsyncStorage (invoked via useStorage hook) for user/session tokens
i. Testing & CI (optional)
- Jest + React Native Testing Library suites under src/**/*.test.tsx
- GitHub Actions workflows (testing.yaml, sonar.yaml, audit.yaml)

##### Relationships and interactions
- User taps UI → triggers component callback → calls custom hook or dispatches Redux action.
- Hooks/Redux middleware → call ApiRequestContext → Apisauce client → caching layer → network → external Marvel API.
- Response travels back: cache proxy → context or Redux store → components re-render with new data.
- Navigation layer sits between screens; on press events it pushes new routes.
- useStorage hook interacts with AsyncStorage for persisting tokens or cache.

##### Architectural patterns & design principles
- Layered architecture (presentation → domain → data → external).
- Adapter pattern: components are “dumb” and receive props; hooks/adapters encapsulate logic.
- Caching proxy: performance optimization, reduces redundant API calls.
- SOLID and Clean Code: clear separation of concerns, single‐responsibility components.

##### How to capture essential elements without overthinking
- Break the system into as many discrete components as needed, but maintain clarity by placing them into logical lanes or layers.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User((User)):::user

    %% Native Shell
    subgraph "Native Shell"
        Android["Android Native Shell"]:::native
        iOS["iOS Native Shell"]:::native
    end

    %% JS Runtime & Bundler
    subgraph "JS Runtime & Bundler"
        Metro["Metro Bundler"]:::runtime
        JSBundle["JS Bundle\n(index.js, App.tsx)"]:::runtime
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        LoginScreen["LoginScreen"]:::frontend
        HomeScreen["HomeScreen"]:::frontend
        HeroDetailScreen["HeroDetailScreen"]:::frontend
        HeroCard["HeroCard"]:::frontend
        ComicsList["ComicsList"]:::frontend
        Header["Header"]:::frontend
        HeroesList["HeroesList"]:::frontend
        LoginForm["LoginForm"]:::frontend
        StackNavigator["StackNavigator"]:::frontend
        Routes["Routes"]:::frontend
        Wrappers["Home & Detail Wrappers"]:::frontend
    end

    %% Domain Layer
    subgraph "Domain Layer"
        useLoadData["useLoadData"]:::domain
        useLoadCurrentHero["useLoadCurrentHero"]:::domain
        useUser["useUser"]:::domain
        useStorage["useStorage"]:::domain
    end

    %% Data Layer
    subgraph "State & Data Layer"
        ApiContext["ApiRequestContext"]:::data
        CacheProvider["CachedRequestsProvider"]:::data
        StoreSetup["Store (Redux)"]:::data
        ReduxHooks["Redux Hooks"]:::data
        HeroSlice["Hero Slice"]:::data
        UserSlice["User Slice"]:::data
    end

    %% API Layer
    subgraph "API & Caching"
        ApiConfig["API Client\n(Apisauce)"]:::data
        CachingProxy["Caching Proxy"]:::data
    end

    %% Local Persistence
    AsyncStorage["AsyncStorage"]:::storage

    %% External Service
    External[("Marvel REST API")]:::external

    %% Connections
    User -->|"taps"| LoginScreen
    User -->|"taps"| HomeScreen
    User -->|"taps"| HeroDetailScreen

    Android --> JSBundle
    iOS --> JSBundle
    Metro --> JSBundle

    JSBundle --> LoginScreen
    JSBundle --> HomeScreen
    JSBundle --> HeroDetailScreen

    LoginScreen --> LoginForm
    LoginScreen --> Header
    HomeScreen --> HeroesList
    HomeScreen --> ComicsList
    HomeScreen --> Header
    HeroDetailScreen --> HeroCard
    HeroDetailScreen --> Header

    LoginScreen --> StackNavigator
    HomeScreen --> StackNavigator
    HeroDetailScreen --> StackNavigator
    StackNavigator --> Routes
    Routes --> Wrappers

    LoginScreen --> useLoadData
    HomeScreen --> useLoadData
    HeroDetailScreen --> useLoadCurrentHero
    LoginScreen --> useUser

    useLoadData --> ApiContext
    useLoadCurrentHero --> ApiContext
    useUser --> ApiContext
    useStorage -.-> AsyncStorage

    ApiContext --> CacheProvider
    CacheProvider --> ApiConfig
    ApiConfig --> CachingProxy
    CachingProxy --> External

    useLoadData --> ReduxHooks
    useLoadCurrentHero --> ReduxHooks
    useUser --> ReduxHooks
    ReduxHooks --> StoreSetup
    StoreSetup --> HeroSlice
    StoreSetup --> UserSlice

    %% Click Events
    click Android "https://github.com/marcgirbaub/marvelapp/blob/main/android/app/src/main/java/com/marvelapp/MainActivity.java"
    click Android "https://github.com/marcgirbaub/marvelapp/blob/main/android/app/src/main/java/com/marvelapp/MainApplication.java"
    click iOS "https://github.com/marcgirbaub/marvelapp/blob/main/ios/marvelapp/AppDelegate.m"
    click iOS "https://github.com/marcgirbaub/marvelapp/blob/main/ios/marvelapp/main.m"
    click JSBundle "https://github.com/marcgirbaub/marvelapp/blob/main/index.js"
    click JSBundle "https://github.com/marcgirbaub/marvelapp/blob/main/App.tsx"
    click Metro "https://github.com/marcgirbaub/marvelapp/blob/main/metro.config.js"
    click JSBundle "https://github.com/marcgirbaub/marvelapp/blob/main/babel.config.js"
    click LoginScreen "https://github.com/marcgirbaub/marvelapp/blob/main/src/screens/LoginScreen/LoginScreen.tsx"
    click HomeScreen "https://github.com/marcgirbaub/marvelapp/blob/main/src/screens/HomeScreen/HomeScreen.tsx"
    click HeroDetailScreen "https://github.com/marcgirbaub/marvelapp/blob/main/src/screens/HeroDetailScreen/HeroDetailScreen.tsx"
    click HeroCard "https://github.com/marcgirbaub/marvelapp/blob/main/src/components/HeroCard/HeroCard.tsx"
    click ComicsList "https://github.com/marcgirbaub/marvelapp/blob/main/src/components/ComicsList/ComicsList.tsx"
    click Header "https://github.com/marcgirbaub/marvelapp/blob/main/src/components/Header/Header.tsx"
    click HeroesList "https://github.com/marcgirbaub/marvelapp/blob/main/src/components/HeroesList/HeroesList.tsx"
    click LoginForm "https://github.com/marcgirbaub/marvelapp/blob/main/src/components/LoginForm/LoginForm.tsx"
    click StackNavigator "https://github.com/marcgirbaub/marvelapp/blob/main/src/navigation/StackNavigator/StackNavigator.tsx"
    click Routes "https://github.com/marcgirbaub/marvelapp/blob/main/src/navigation/routes.ts"
    click Wrappers "https://github.com/marcgirbaub/marvelapp/blob/main/src/navigation/wrappers/HomeScreenWrapper.tsx"
    click Wrappers "https://github.com/marcgirbaub/marvelapp/blob/main/src/navigation/wrappers/DetailScreenWrapper.tsx"
    click useLoadData "https://github.com/marcgirbaub/marvelapp/blob/main/src/hooks/useLoadData/useLoadData.ts"
    click useLoadCurrentHero "https://github.com/marcgirbaub/marvelapp/blob/main/src/hooks/useLoadCurrentHero/useLoadCurrentHero.ts"
    click useUser "https://github.com/marcgirbaub/marvelapp/blob/main/src/hooks/useUser/useUser.ts"
    click useStorage "https://github.com/marcgirbaub/marvelapp/blob/main/src/hooks/useStorage/useStorage.ts"
    click ApiContext "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/contexts/ApiRequestContext.ts"
    click CacheProvider "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/contexts/CachedRequestsProvider.tsx"
    click StoreSetup "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/redux/store.ts"
    click ReduxHooks "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/redux/hooks.ts"
    click HeroSlice "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/redux/features/hero/heroSlice.ts"
    click UserSlice "https://github.com/marcgirbaub/marvelapp/blob/main/src/store/redux/features/user/userSlice.ts"
    click ApiConfig "https://github.com/marcgirbaub/marvelapp/blob/main/src/constants/apiConstants.ts"

    %% Styles
    classDef user fill:#f9f,stroke:#333,color:#333;
    classDef native fill:#ece,stroke:#556,color:#556;
    classDef runtime fill:#ffe082,stroke:#e65100,color:#e65100;
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef domain fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20;
    classDef data fill:#ffe0b2,stroke:#e65100,color:#e65100;
    classDef storage fill:#d7ccc8,stroke:#4e342e,color:#4e342e;
    classDef external fill:#eceff1,stroke:#607d8b,color:#607d8b;
```
