# simonerm/react-native-job-queue architecture

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

- Interactive diagram: https://gitdiagram.com/simonerm/react-native-job-queue
- Repository: https://github.com/simonerm/react-native-job-queue

## Overview

##### Project type and purpose
- This is a React Native library (“react-native-job-queue”) that provides a persistent job queue for RN apps.
- It exposes a JS/TypeScript API (Queue, Worker) and implements native modules on Android (Room/SQLite) and iOS (SQLite) to store and manage jobs persistently.

##### File structure
- Top-level “src” folder holds the TS code for the JS API: Queue.ts, Worker.ts, models, utils, and index.ts as the entrypoint.
- “android” folder holds the Android native module: Room-based entities (Job, JobDao, JobDatabase) plus RN module boilerplate (JobQueueModule, Package).
- “ios” folder holds the iOS native module: Swift/ObjC code wrapping SQLite database (JobQueue.swift, SQLiteDatabase.swift, SQLTable.swift) and the bridging header.
- “example” folder illustrates a full RN app using the library on both platforms.
- “docs” and “website” folders serve the API reference and website.
- Config files: podspec, Dockerfile/docker-compose (for website?), jest config and TS configs.

##### README for additional insights
- The README confirms: JS API + native persistence (SQLite) + Android Room.
- The library implements its own sqlite layers due to RN Pod constraints.
- No external network services; it’s embedded in the mobile app.

##### Main components and their interactions
a. JS Layer:
- Queue class: enqueue, dequeue, scheduling.
- Worker class: repeatedly polls Queue for jobs, runs handler functions.
- Models: Job, JobStore interface, utils (UUID, mocking).
b. React Native Bridge:
- JS <—> Native module boundary. Exposed methods like addJob, fetchJob, removeJob.
c. Android Native Module:
- Room database with Job entity, DAO, and JobDatabase.
- JobQueueModule exposes Room DAO calls to JS via ReactContextBaseJavaModule.
d. iOS Native Module:
- SQLiteDatabase that creates/checks tables (SQLTable).
- JobQueue.swift wraps insert/delete/query operations.
- Bridging header & Podspec exposes methods to RN.
e. Example App:
- Demonstrates instantiation of Queue and Worker in a real RN app.
f. Documentation Site:
- Static site generation (Docusaurus or similar, under “website”).
g. Testing:
- Jest tests for Queue and Worker in JS.
h. Build & Deployment:
- Android: gradlew, gradle scripts.
- iOS: Podspec, xcodeproj.
- CI: GitHub Actions (main.yml), Dockerfiles for website.

##### Architectural patterns and design principles
- Separation of concerns: JS API vs. native persistence.
- Bridge pattern: React Native bridge between layers.
- Repository/DAO pattern in Android (Room) and analogous wrapper in iOS.
- Event loop / polling pattern for the Worker.
- Modular design: core logic in “src”, platform-specific code in platform folders.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% JS API Layer
    subgraph "JS API Layer"
        Queue["Queue"]:::js
        Worker["Worker"]:::js
        Index["index.ts"]:::js
        JobModel["Job model"]:::js
        JobStore["JobStore interface"]:::js
        UtilsUuid["Uuid"]:::js
        UtilsMock["JobQueueMock"]:::js
    end

    %% React Native Bridge
    subgraph "React Native Bridge"
        subgraph "Android Bridge"
            JRModule["JobQueueModule"]:::android
            JRPackage["JobQueuePackage"]:::android
            ConvHelper["ConversionHelper"]:::android
        end
        subgraph "iOS Bridge"
            Bridging["Bridging Header"]:::ios
            ObjCWrapperH["JobQueue.h/.m"]:::ios
            SwiftWrapper["JobQueue.swift"]:::ios
        end
    end

    %% Android Native Module
    subgraph "Android Native Module"
        JobEntity["Job entity"]:::android
        JobDao["JobDao"]:::android
        JobDB["JobDatabase"]:::android
        Schema["Schema snapshots"]:::android
    end

    %% iOS Native Module
    subgraph "iOS Native Module"
        SQLiteDB["SQLiteDatabase"]:::ios
        SQLTable["SQLTable"]:::ios
        JobSwift["Job.swift"]:::ios
    end

    %% Consumers & Tooling
    Example["Example RN App"]:::js
    DocsSite["Documentation Site"]:::tool
    Tests["Testing (Jest)"]:::tool
    CI["CI/CD Pipeline"]:::tool

    %% Interactions
    Example -->|"uses enqueue()/start()"| Queue
    Queue -->|"addJob() / fetchNextJob()"| JRModule
    Worker -->|"poll fetchNextJob()"| JRModule
    JRModule -->|"addJob()/fetchJob()/removeJob()"| JobDB
    JRModule -->|"addJob()/fetchJob()/removeJob()"| JobEntity
    JRModule --> JobDao
    JRModule --> Schema

    Queue -->|"addJob() / fetchNextJob()"| Bridging
    Worker -->|"poll fetchNextJob()"| Bridging
    Bridging -->|"addJob()/fetchJob()/removeJob()"| SQLiteDB
    Bridging --> SQLTable
    Bridging --> JobSwift

    CI -->|"build/test/docs"| Queue
    CI --> Example
    CI --> DocsSite
    Tests --> Queue

    %% Click Events
    click Queue "https://github.com/simonerm/react-native-job-queue/blob/master/src/Queue.ts"
    click Worker "https://github.com/simonerm/react-native-job-queue/blob/master/src/Worker.ts"
    click Index "https://github.com/simonerm/react-native-job-queue/blob/master/src/index.ts"
    click JobModel "https://github.com/simonerm/react-native-job-queue/blob/master/src/models/Job.ts"
    click JobStore "https://github.com/simonerm/react-native-job-queue/blob/master/src/models/JobStore.ts"
    click UtilsUuid "https://github.com/simonerm/react-native-job-queue/blob/master/src/utils/Uuid.ts"
    click UtilsMock "https://github.com/simonerm/react-native-job-queue/blob/master/src/utils/JobQueueMock.ts"
    click JRModule "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/JobQueueModule.java"
    click JRPackage "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/JobQueuePackage.java"
    click ConvHelper "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/ConversionHelper.java"
    click JobEntity "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/Job.java"
    click JobDao "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/JobDao.java"
    click JobDB "https://github.com/simonerm/react-native-job-queue/blob/master/android/src/main/java/com/github/simonerm/JobDatabase.java"
    click Schema "https://github.com/simonerm/react-native-job-queue/blob/master/android/schemas/com.github.simonerm.JobDatabase/1.json"
    click Bridging "https://github.com/simonerm/react-native-job-queue/blob/master/ios/JobQueue-Bridging-Header.h"
    click ObjCWrapperH "https://github.com/simonerm/react-native-job-queue/blob/master/ios/JobQueue.h"
    click SwiftWrapper "https://github.com/simonerm/react-native-job-queue/blob/master/ios/JobQueue.swift"
    click SQLiteDB "https://github.com/simonerm/react-native-job-queue/blob/master/ios/SQLiteDatabase.swift"
    click SQLTable "https://github.com/simonerm/react-native-job-queue/blob/master/ios/SQLTable.swift"
    click JobSwift "https://github.com/simonerm/react-native-job-queue/blob/master/ios/Job.swift"
    click Example "https://github.com/simonerm/react-native-job-queue/blob/master/example/App.tsx"
    click DocsSite "https://github.com/simonerm/react-native-job-queue/blob/master/docs/index.md"
    click Tests "https://github.com/simonerm/react-native-job-queue/blob/master/src/__tests__/Queue.test.ts"
    click CI "https://github.com/simonerm/react-native-job-queue/blob/master/.github/workflows/main.yml"

    %% Styles
    classDef js fill:#D0E6FF,stroke:#000,stroke-width:1px
    classDef android fill:#D6F5D6,stroke:#000,stroke-width:1px
    classDef ios fill:#FFE5B4,stroke:#000,stroke-width:1px
    classDef tool fill:#E0E0E0,stroke:#000,stroke-width:1px
```
