# echowaves/expo-cached-image architecture

> Architecture diagram of the GitHub repository echowaves/expo-cached-image, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/echowaves/expo-cached-image
- Repository: https://github.com/echowaves/expo-cached-image

## Overview

##### Project type and purpose
- This is an open-source React Native component library (expo-cached-image) built for Expo apps.
- Its purpose is to provide a drop-in <CachedImage> component that transparently handles remote image downloading, local caching, cache expiration, cleanup, and secure key sanitization.

##### File structure
- Top-level files: package.json, Babel and Metro configs, ESLint, TypeScript config → a published npm package.
- src/
- consts.ts → likely holds constants (e.g. default cache paths, expiration values).
- index.tsx → entry point exporting the <CachedImage> component and the CacheManager API.
- No “frontend” or “backend” directories—instead a single library module.

##### README for additional insights
- Describes two main APIs:
a) The <CachedImage> React component (props: source, cacheKey, placeholderContent, etc.)
b) The static CacheManager (methods: addToCache, getCachedUri, downloadAsync, getMetadata).
- Mentions Expo FileSystem under the hood for disk storage, network calls with optional headers, key sanitization for security.

a. Main components
- Consumer App (your screen or UI layer)
- CachedImage Component
- CacheManager Module
- Expo FileSystem (local disk storage)
- Network / HTTP Server (image host)
- Optional: React Native’s Image component (for actual rendering)
b. Relationships and interactions
1. Consumer renders <CachedImage> → passes uri + cacheKey
2. <CachedImage> invokes CacheManager.getCachedUri(key)
- If cache hit: read file from local FS → pass local uri to RN Image
- If miss or expired: call CacheManager.downloadAsync(uri, key, headers) → network request → write to FS → return local uri
3. While waiting: <CachedImage> displays placeholderContent
4. CacheManager.getMetadata and cleanup routines run periodically or on demand
c. Architectural patterns & principles
- Single responsibility: <CachedImage> handles UI; CacheManager handles persistence + networking.
- Abstraction of platform APIs (Expo FileSystem) behind CacheManager.
- Secure key handling (sanitization before FS interaction).
- Asynchronous I/O / Promise-based flows.
d. Key technologies
- React Native / Expo
- TypeScript
- Expo FileSystem API
- React Native Image component
- Standard Node/npm packaging

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Layer
    Consumer["Consumer App"]:::external

    %% Library Module
    subgraph "Library Module"
        CachedImage["CachedImage Component"]:::library
        CacheManager["CacheManager Module"]:::library
        Consts["Default Constants"]:::library
    end

    %% Platform / External
    subgraph "Platform / External"
        ExpoFS["Expo FileSystem API"]:::platform
        Network["Network HTTP Server"]:::external
        RNImage["React Native Image Component"]:::platform
    end

    %% Configurations
    subgraph "Project Configurations"
        Entry["package.json"]:::config
        TSConfig["tsconfig.json"]:::config
        BabelConfig["babel.config.js"]:::config
        MetroConfig["metro.config.js"]:::config
        ESLint[".eslintrc.json"]:::config
        Readme["README.md"]:::config
    end

    %% Relationships
    Consumer -->|"renders <CachedImage>"| CachedImage
    CachedImage -->|"invokes getCachedUri() / downloadAsync()"| CacheManager
    CachedImage -->|"renders on UI"| RNImage
    CacheManager -->|"read/write files"| ExpoFS
    CacheManager -->|"download from host"| Network
    CacheManager -->|"uses constants"| Consts
    CacheManager -->|"cleanup & metadata"| ExpoFS

    %% Click Events
    click CachedImage "https://github.com/echowaves/expo-cached-image/blob/main/src/index.tsx"
    click CacheManager "https://github.com/echowaves/expo-cached-image/blob/main/src/index.tsx"
    click Consts "https://github.com/echowaves/expo-cached-image/blob/main/src/consts.ts"
    click Entry "https://github.com/echowaves/expo-cached-image/blob/main/package.json"
    click TSConfig "https://github.com/echowaves/expo-cached-image/blob/main/tsconfig.json"
    click BabelConfig "https://github.com/echowaves/expo-cached-image/blob/main/babel.config.js"
    click MetroConfig "https://github.com/echowaves/expo-cached-image/blob/main/metro.config.js"
    click ESLint "https://github.com/echowaves/expo-cached-image/blob/main/.eslintrc.json"
    click Readme "https://github.com/echowaves/expo-cached-image/blob/main/README.md"

    %% Styles
    classDef library fill:#D6EAF8,stroke:#3498DB,color:#1B4F72
    classDef external fill:#A9DFBF,stroke:#27AE60,color:#145A32
    classDef platform fill:#F9E79F,stroke:#D68910,color:#7E5109
    classDef config fill:#F5B7B1,stroke:#C0392B,color:#641E16
```
