# d4t4-dev/app_nasa_examen architecture

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

- Interactive diagram: https://gitdiagram.com/d4t4-dev/app_nasa_examen
- Repository: https://github.com/d4t4-dev/app_nasa_examen

## Overview

##### Project type and purpose
- This is a cross-platform (Android & Web) React Native + Expo application
- It consumes multiple NASA public APIs (APOD, Earth, EPIC, NeoWs, Rover)
- Architecture: CLEAN layered + MVVM, Redux Toolkit for global state, AsyncStorage fallback

##### File structure
- Top-level:
– App.tsx / index.ts (entry point)
– app.config.ts, babel.config.js, tsconfig.json, package.json
- Layers under src/:
– core/ (shared utilities, API client, fallbacks, themes, validators, interfaces)
– data/ (datasources, mappers, models, repository implementations)
– domain/ (entities, repository interfaces, use case implementations)
– presentation/ (UI screens, components, hooks, view-models)
– navigation/ (React Navigation stacks, tabs, drawers, linking)
– store/ (Redux slices, thunks, store configuration)
– di/ (dependency injection container & factories)
– services/ (local persistence via AsyncStorage)

##### README for additional insights
- Emphasis on CLEAN + MVVM, SOLID, DRY, KISS, YAGNI
- Required patterns: Observer (ViewModel subscriptions), Strategy (online/offline), Factory (DI/factories)
- Key tech: Redux Toolkit, React Navigation (Stack, Tabs, Drawer), Reanimated, Axios, AsyncStorage, react-hook-form

##### Main components & their interactions
a. Presentation Layer
– Components & Screens: UI controls, navigation flows (RootNavigator → Tabs/Drawer/Stacks)
– ViewModels: useApodViewModel, useEarthViewModel, etc. (implement Observer pattern to notify UI)
– Hooks: useConnectivity (Strategy for online/offline), useTheme
b. State Management
– Redux store: slices (apodSlice, earthSlice, etc.), thunks (apodThunks, earthThunk…)
– Presentation dispatches thunks / reacts to slice state
c. Domain Layer
– Entities: Apod, Earth, Epic, NeoWs, Rover
– Repository interfaces: ApodRepository, EarthRepository, GenericRepository, etc.
– UseCases: FetchDataApod, FetchDataEarthOffLine (encapsulate business logic)
d. Data Layer
– Datasources: ApodApi, EarthApi, … (Axios clients to NASA endpoints)
– Mappers: transform raw API models to domain entities
– Models: ApodNasa, EarthNasa, …
– RepositoriesImpl: ApodRepositoryImpl implements ApodRepository
– StorageService: AsyncStorage fallback via core/fallBacks.ts & services/storage.ts (Strategy)
e. Dependency Injection
– di/container.ts wires use cases → repositories → datasources
– factories create specific use case instances (Factory pattern)
f. External Services
– NASA REST APIs
– AsyncStorage (mobile) + fallback for web
– React Navigation

##### Architectural patterns & design principles
- CLEAN + MVVM: strict separation of UI, ViewModel, domain, data
- SOLID:
– Single Responsibility: each layer has one focus (e.g., mappers only map)
– Open/Closed: new APIs can be added via new datasource + mapper + use case without modifying existing code
– Liskov: repositories implement a common interface
– Interface Segregation: small interfaces per API/use case
– Dependency Inversion: high-level modules (use cases) depend on abstractions (repositories)
- Observer: ViewModels expose observables/state to UI
- Strategy: connectivity strategy chooses online vs offline data source
- Factory: DI factories for use cases

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Dependency Injection
    DI["DI Container"]:::di
    click DI "https://github.com/d4t4-dev/app_nasa_examen/blob/main/src/di/container.ts"

    %% Presentation Layer
    subgraph Presentation Layer
        PScreens["Screens"]:::presentation
        PComponents["Components"]:::presentation
        PViewModels["ViewModels"]:::presentation
        PHooks["Hooks"]:::presentation
        Navigator["RootNavigator / Drawer / Tabs"]:::presentation
    end
    click PScreens "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/presentation/screens"
    click PComponents "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/presentation/components"
    click PViewModels "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/presentation/viewmodels"
    click PHooks "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/presentation/hooks"
    click Navigator "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/navigation"

    %% State Management
    subgraph "State Management"
        Store["Store Configuration"]:::redux
        Slices["Redux Slices"]:::redux
        Thunks["Redux Thunks"]:::redux
    end
    click Store "https://github.com/d4t4-dev/app_nasa_examen/blob/main/src/store/store.ts"
    click Slices "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/store/slices"
    click Thunks "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/store/thunks"

    %% Domain Layer
    subgraph Domain Layer
        Entities["Entities"]:::domain
        RepoInterfaces["Repository Interfaces"]:::domain
        UseCases["Use Cases"]:::domain
    end
    click Entities "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/domain/entities"
    click RepoInterfaces "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/domain/repositories"
    click UseCases "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/domain/usecases"

    %% Data Layer
    subgraph Data Layer
        Datasources["API Datasources"]:::data
        Mappers["Mappers"]:::data
        Models["Models"]:::data
        RepoImpl["Repository Implementations"]:::data
    end
    click Datasources "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/data/datasource"
    click Mappers "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/data/mappers"
    click Models "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/data/models"
    click RepoImpl "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/data/repositories_impl"

    %% Core & Services
    Core["Core Utilities & Interfaces"]:::core
    click Core "https://github.com/d4t4-dev/app_nasa_examen/tree/main/src/core"
    Services["AsyncStorage Fallback"]:::external
    click Services "https://github.com/d4t4-dev/app_nasa_examen/blob/main/src/services/storage.ts"

    %% External Services
    NASAApis["NASA REST APIs"]:::external

    %% Connections
    PScreens -->|"bind/observe"| PViewModels
    PComponents -->|"use"| PViewModels
    PHooks -->|"provide hooks to"| PScreens
    Navigator -->|"navigates to"| PScreens

    PViewModels -->|"dispatch thunk"| Thunks
    PViewModels -->|"call use case"| UseCases

    Thunks -->|"invoke use case"| UseCases
    Store -->|"manages state for"| Slices
    PViewModels -->|"select state"| Store

    UseCases -->|"depends on"| RepoInterfaces

    RepoInterfaces -->|"implemented by"| RepoImpl
    RepoImpl -->|"fetch via"| Datasources
    Datasources -->|"HTTP"| NASAApis

    RepoImpl -.->|"fallback"| Services
    Services -->|"uses"| Core

    DI -->|"wires"| UseCases
    DI -->|"wires"| RepoImpl
    DI -->|"wires"| Datasources

    %% Class Definitions
    classDef presentation fill:#BBDEFB,stroke:#333,stroke-width:1px
    classDef redux fill:#FFE082,stroke:#333,stroke-width:1px
    classDef domain fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef data fill:#FFCC80,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef core fill:#FFF59D,stroke:#333,stroke-width:1px
    classDef di fill:#D1C4E9,stroke:#333,stroke-width:1px
```
