# roy-rc/react-native-wallet architecture

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

- Interactive diagram: https://gitdiagram.com/roy-rc/react-native-wallet
- Repository: https://github.com/roy-rc/react-native-wallet

## Overview

##### Project Type and Purpose
- This is a full-stack cross-platform mobile wallet app.
- Frontend (mobile): React Native with Expo, Clerk-backed authentication, React Navigation, custom theming, real-time updates.
- Backend: Express.js REST API, PostgreSQL (Neon), Upstash for rate-limiting, scheduled tasks via cron.

##### File‐Structure Analysis
A. Top-Level
– /mobile: React Native app
– /backend: Express.js server
B. /mobile
– app/ (Expo Router pages, nested by auth vs root flows)
– assets/ (fonts, images, styles)
– components/ (UI building blocks)
– hooks/, lib/ (custom hooks & utilities)
C. /backend/src
– config/ (db.js for Neon Postgres, upstash.js, cron.js)
– middleware/ (rateLimiter.js using Upstash)
– routes/ (transactionsRoute.js) → controllers/ (transactionsController.js)
– server.js (entry point)

##### Key Architectural Insights from README
- Client uses Clerk for authentication → issues tokens.
- Mobile → HTTP calls to backend REST endpoints (/transactions).
- Backend enforces rate-limits (Upstash), connects to Neon Postgres, and runs scheduled jobs (cron.js).
- Data flow is unidirectional: Mobile ↔ Backend ↔ Database/Cache/External Services.

a. Main Components
1. Mobile App
- Expo/React Native, Clerk SDK, React Navigation
2. Authentication Service
- External: Clerk (OAuth/JWT issuer)
3. API Gateway / Express Server
- Routes → Controllers → DB
- Middleware: rateLimiter
- Scheduled Task Runner (cron.js)
4. Database
- PostgreSQL (Neon)
5. Cache/Rate Limit Store
- Upstash (Redis)
b. Component Relationships
- Mobile App authenticates via Clerk → receives JWT → calls Express API.
- Express Middleware validates JWT, checks rate limit in Upstash.
- Controller logic reads/writes transactions in PostgreSQL.
- Cron jobs (cron.js) trigger periodic summaries or cleanup in DB.
c. Architectural Patterns & Principles
- Layered REST API: Router → Controller → Config/DB
- Single-page mobile flows with nested routing (Expo Router pattern)
- Modular separation of concerns: authentication, rate limiting, business logic, persistence.
- Externalized config for DB & cache.
d. Technologies
- Frontend: React Native, Expo, Clerk, React Navigation, Reanimated
- Backend: Node.js, Express.js, PostgreSQL (Neon), Upstash, Node‐cron

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Mobile Client"
        direction TB
        MobileApp["Mobile App"]:::client
        ClerkAuth["Clerk Auth Service"]:::external
        AuthScreens["Authentication Flow"]:::client
        RootFlow["Root Flow"]:::client
        ExpoRouterLayout["Global Expo Router Layout"]:::client
        UIComponents["UI Components"]:::client
        Hooks["Custom Hooks"]:::client
        Utils["Utilities"]:::client
        ConstantsEndpoints["API Endpoints"]:::client
        ConstantsColors["Theme Colors"]:::client
        MobileApp -->|"Authenticate"| ClerkAuth
        MobileApp -->|"GET /transactions"| ExpressAPI
    end

    subgraph "Backend Infrastructure"
        direction TB
        ExpressAPI["Express API Gateway"]:::service
        RateLimiter["Rate Limiting Middleware"]:::service
        TransactionsRoute["Transactions Route"]:::service
        TransactionsController["Transactions Controller"]:::service
        DBConfig["Database Config"]:::service
        UpstashConfig["Rate Limit Store Config"]:::service
        Cron["Scheduled Task Runner"]:::service
        ExpressAPI -->|"Validate JWT"| RateLimiter
        RateLimiter -->|"Route Calls"| TransactionsRoute
        TransactionsRoute -->|"Invoke"| TransactionsController
        TransactionsController -->|"Connect"| DBConfig
        RateLimiter -->|"Check Quota"| UpstashConfig
        DBConfig -->|"Query/Update"| Postgres
        UpstashConfig -->|"Read/Write"| Upstash
        Cron -->|"Scheduled Jobs"| DBConfig
        Cron -->|"Scheduled Jobs"| TransactionsController
    end

    subgraph "Data Stores"
        direction TB
        Postgres["PostgreSQL (Neon)"]:::data
        Upstash["Upstash Redis"]:::data
    end

    subgraph "External Services"
        direction TB
        ClerkAuth
    end

    %% Click Events
    click MobileApp "https://github.com/roy-rc/react-native-wallet/tree/main/mobile/"
    click AuthScreens "https://github.com/roy-rc/react-native-wallet/tree/main/mobile/app/(auth)/"
    click RootFlow "https://github.com/roy-rc/react-native-wallet/tree/main/mobile/app/(root)/"
    click ExpoRouterLayout "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/app/_layout.jsx"
    click UIComponents "https://github.com/roy-rc/react-native-wallet/tree/main/mobile/components/"
    click Hooks "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/hooks/useTransactions.jsx"
    click Utils "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/lib/utils.js"
    click ConstantsEndpoints "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/constants/api.js"
    click ConstantsColors "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/constants/colors.js"
    click ExpressAPI "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/server.js"
    click RateLimiter "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/middleware/rateLimiter.js"
    click TransactionsRoute "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/routes/transactionsRoute.js"
    click TransactionsController "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/controllers/transactionsController.js"
    click DBConfig "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/config/db.js"
    click UpstashConfig "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/config/upstash.js"
    click Cron "https://github.com/roy-rc/react-native-wallet/blob/main/backend/src/config/cron.js"
    click backendPackage "https://github.com/roy-rc/react-native-wallet/blob/main/backend/package.json"
    click mobilePackage "https://github.com/roy-rc/react-native-wallet/blob/main/mobile/package.json"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#036;border:1px solid #036
    classDef service fill:#90EE90,stroke:#036;border:1px solid #036
    classDef data fill:#FFA500,stroke:#036;border:1px solid #036
    classDef external fill:#DDA0DD,stroke:#036;border:1px solid #036
```
