# nandorojo/galeria architecture

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

- Interactive diagram: https://gitdiagram.com/nandorojo/galeria
- Repository: https://github.com/nandorojo/galeria

## Overview

##### Project Type and Purpose
- This is a UI component library for image viewing that works with any image component. It is built to support React, React Native (both iOS and Android), and also plain web usage.
- The README highlights features like shared element transitions, pinch/double-tap zoom, multi-image support, and integration with various image components (including 3rd-party ones like FastImage and SolitoImage).

##### File Structure for Components
- Native Code:
- The “android” directory contains Kotlin source code (modules and native support via Android modules, e.g., GaleriaModule.kt, GaleriaView.kt, and native UI fragments).
- The “ios” directory includes native iOS implementations using Swift (e.g., GaleriaModule.swift, GaleriaView.swift, and the podspec file).
- Shared/JavaScript Code:
- The “src” folder houses the TypeScript definitions and platform-specific implementations of GaleriaView (with separate files for Android, iOS, and common logic).
- The package’s root-level files (package.json, tsconfig.json, etc.) form the cross-platform JS/TS layer.
- Example/Demo Integration:
- The “example” folder demonstrates different usage scenarios, integration with various technologies (e.g., FlashList, Next.js, Expo) and provides a live demo of the library in action.
- Configuration and Build Files:
- Files like expo-module.config.json, babel.config.js, metro.config.js, webpack.config.js, and various yarn files indicate multi-platform build and bundling support.

a. Main Components to Include:
- React/JS Layer: Core Galeria component code (found in src/ and package.json) that provides the API and common logic.
- Platform-Specific Native Modules:
- Android Module (in the android folder): Implements native image viewing features using Kotlin.
- iOS Module (in the ios folder): Implements native image viewing features using Swift.
- Example/Demo Applications:
- Example folder that illustrates integration scenarios with different frameworks (React Native, Next.js, etc.).
- Web Support: Highlight that the web version uses Framer Motion for transitions and simplified image viewing.

b. Data Flow and Interaction:
- The React component (Galeria) serves as a façade. It abstracts over the various native implementations:
- On Android and iOS, it bridges to their respective native modules when running on mobile.
- On web, it uses a fully JavaScript-based approach.
- The component accepts props and children (custom image components) and delegates behaviors (e.g., pinch, zoom) to either the native or web layer.

##### Architectural Patterns to Note
- Portability and Abstraction: The separation between platform-agnostic React/JS code and native platform implementations.
- Modularity: Clean API design that allows “bringing your own image component” (BYOIC) enhances flexibility.
- Cross-Platform Design: Conditional code branches and separate files (e.g., GaleriaView.android.tsx vs. GaleriaView.ios.tsx) using platform-specific file naming conventions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation/UI Layer"
        RC1["React Core Component (src)"]:::react
        RC2["Package Config (package.json)"]:::react
    end

    subgraph "Native Integration Layer"
        Android["Android Native Module"]:::android
        IOS["iOS Native Module"]:::ios
    end

    subgraph "External Integrations"
        External["External Integrations (FlashList, next/image, expo-image, Framer Motion)"]:::external
    end

    subgraph "Demo & Build Tools"
        Demo["Demo Application"]:::demo
        RootConfig["Root Build Config"]:::build
        ExampleConfig["Example Config Files"]:::build
    end

    RC1 -->|"bridge-to"| Android
    RC1 -->|"bridge-to"| IOS
    RC1 -->|"web-transition"| External
    Demo -->|"demonstrates"| RC1
    RootConfig -->|"configures"| RC1
    ExampleConfig -->|"configures"| RC1

    click RC1 "https://github.com/nandorojo/galeria/tree/master/src"
    click RC2 "https://github.com/nandorojo/galeria/blob/master/package.json"
    click Android "https://github.com/nandorojo/galeria/tree/master/android/src/main/java/nandorojo/modules/galeria"
    click IOS "https://github.com/nandorojo/galeria/tree/master/ios"
    click Demo "https://github.com/nandorojo/galeria/tree/master/example"
    click RootConfig "https://github.com/nandorojo/galeria/blob/master/expo-module.config.json"
    click ExampleConfig "https://github.com/nandorojo/galeria/blob/master/example/webpack.config.js"

    classDef react fill:#f9c,stroke:#333,stroke-width:2px;
    classDef android fill:#bbf,stroke:#333,stroke-width:2px;
    classDef ios fill:#bfb,stroke:#333,stroke-width:2px;
    classDef demo fill:#ffb,stroke:#333,stroke-width:2px;
    classDef build fill:#fbb,stroke:#333,stroke-width:2px;
    classDef external fill:#cff,stroke:#333,stroke-width:2px;
```
