# devxniv/redex architecture

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

- Interactive diagram: https://gitdiagram.com/devxniv/redex
- Repository: https://github.com/devxniv/redex

## Overview

1. This repository is split into two major products: an Android companion app in `android/` and a Next.js web platform in `web/`. The Android app is the ingestion edge for real-world expense events; the web app is the system of record, dashboard, and automation backend.

2. The Android app’s core responsibility is capture and normalize transaction evidence. It listens to payment notifications (`RedexNotificationListener`), accepts shared screenshots from the Android share sheet (`ShareReceiverActivity`), and applies AI extraction through `GeminiParser` to turn unstructured text/images into structured transaction fields.

3. On-device processing is intentionally offline-first. Before sending, transactions are deduplicated (`TransactionDeduplicator`) and rate-limited (`ShareGuard`). If network delivery fails, the app stores the payload in a local Room database (`AppDatabase`, `PendingTransaction`) and retries later through `TransactionWorker` using WorkManager.

4. The Android-to-server boundary is a single HTTP write path implemented by `HttpSender`. It POSTs transactions to the web backend and includes a shared secret header (`X-Redex-Api-Secret`). This is the main integration seam between the mobile capture layer and the cloud data layer.

5. The Android app also has a small control plane: `MainActivity` surfaces status and permissions, `SettingsActivity` manages a whitelist of allowed source apps via `WhitelistManager` and `WhitelistAdapter`, and `ShareReceiverActivity` acts as a user-facing intake path for manual screenshot sharing.

6. The web app is built with Next.js App Router and divides into public auth routes and protected application routes. Clerk middleware guards the main experience under `/(main)`, while `/(auth)` handles sign-in and sign-up flows.

7. The primary product UI lives in the dashboard and account views. `/dashboard` aggregates account balances, budgets, and transaction trends; `/account/[id]` shows account-specific history and charts; `/transaction/create` supports manual entry and receipt scanning. These screens are mostly consumers of database state rather than orchestration points.

8. All persistent financial data is modeled in PostgreSQL through Prisma (`web/prisma/schema.prisma`). The key domain entities are `User`, `Account`, `Transaction`, and `Budget`, with the web app acting as the authoritative write/read layer for everything except the Android ingestion queue.

9. Server-side transaction ingestion is centered on `/api/transactions`. That endpoint validates the shared secret, accepts Android-sent transaction payloads, and persists them through Prisma. The web side does not redo the mobile app’s categorization work; it trusts the structured output produced on-device.

10. Background automation is handled through Inngest functions in `lib/inngest/function.js` and exposed via the Inngest API route. These jobs cover recurring transaction creation, daily recurring-transaction discovery, monthly report generation, and budget alert checks. This is the second major async boundary after Android retry processing.

11. AI is used in two distinct places with different scopes: Android uses Gemini for screenshot and notification extraction at capture time, while the web backend uses Gemini server-side only for generating monthly report insights. That keeps extraction close to the source and reserves server AI for higher-level narrative generation.

12. Notifications and external delivery are handled through email templates in `emails/template.jsx`, rendered for monthly financial reports and budget alerts. Resend is the delivery provider, while Arcjet adds API protection/rate limiting around the web surface.

13. Overall, the architecture is a two-tier event pipeline: mobile devices capture expense events, normalize and queue them locally, then push them to a central web backend; the backend stores state in Postgres and fans out to scheduled jobs, dashboards, and email notifications. The key diagram boundaries are Android capture/offline queue, HTTP ingestion API, PostgreSQL/Prisma persistence, and Inngest-driven automation.

Main entry points: [`web/prisma/schema.prisma`](https://github.com/devxniv/redex/blob/main/web/prisma/schema.prisma) (Prisma schema), [`web/app/(main)/layout.js`](https://github.com/devxniv/redex/blob/main/web/app/(main)/layout.js) (Main shell), [`web/lib/inngest/function.js`](https://github.com/devxniv/redex/blob/main/web/lib/inngest/function.js) (Inngest jobs), [`android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt`](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt) (Deduplicator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android["Android app"]
  node_android_main["Main screen<br/>ui/status-perms<br/>[MainActivity.kt]"]
  node_android_settings["Settings<br/>ui/whitelist"]
  node_android_share["Share intake<br/>activity/intake"]
  node_android_notify["Notification listener<br/>listener/capture"]
  node_android_gemini["Gemini parser<br/>ai/extraction<br/>[GeminiParser.kt]"]
  node_android_dedupe["Deduplicator<br/>validation/dedupe"]
  node_android_guard["Share guard<br/>rate-limit<br/>[ShareGuard.kt]"]
  node_android_db[("Local queue<br/>room/offline-store<br/>[AppDatabase.kt]")]
  node_android_worker["Retry worker<br/>workmanager/retry"]
  node_android_sender["HTTP sender<br/>http/write-path<br/>[HttpSender.kt]"]
  node_android_whitelist["Whitelist manager<br/>policy/source-filter"]
end

subgraph group_web["Web platform"]
  node_web_auth["Auth routes<br/>nextjs/auth<br/>[layout.jsx]"]
  node_web_shell["Main shell<br/>nextjs/protected<br/>[layout.js]"]
  node_web_dashboard["Dashboard<br/>ui/overview<br/>[page.jsx]"]
  node_web_account["Account view<br/>ui/details<br/>[page.jsx]"]
  node_web_tx_create["Create transaction<br/>ui/entry<br/>[page.jsx]"]
  node_web_api_tx["Transactions API<br/>api/ingestion<br/>[route.js]"]
  node_web_prisma[("Prisma schema<br/>postgres/domain-model<br/>[schema.prisma]")]
  node_web_inngest["Inngest jobs<br/>automation/async<br/>[function.js]"]
  node_web_ai["Report AI<br/>ai/narrative<br/>[dashboard.js]"]
  node_web_email["Email templates<br/>notifications/email<br/>[template.jsx]"]
  node_web_protect["API protection<br/>security/rate-limit<br/>[arcjet.js]"]
end

node_android_main -->|"configure"| node_android_notify
node_android_main -->|"open"| node_android_settings
node_android_settings -->|"manage"| node_android_whitelist
node_android_notify -->|"extract"| node_android_gemini
node_android_share -->|"extract"| node_android_gemini
node_android_gemini -->|"normalize"| node_android_dedupe
node_android_dedupe -->|"gate"| node_android_guard
node_android_guard -->|"enqueue"| node_android_db
node_android_dedupe -->|"send"| node_android_sender
node_android_sender -->|"POST"| node_web_api_tx
node_android_worker -->|"drain"| node_android_db
node_android_worker -->|"retry"| node_android_sender
node_web_auth -->|"enter"| node_web_shell
node_web_shell -->|"route"| node_web_dashboard
node_web_shell -->|"route"| node_web_account
node_web_shell -->|"route"| node_web_tx_create
node_web_api_tx -->|"persist"| node_web_prisma
node_web_dashboard -->|"read"| node_web_prisma
node_web_account -->|"read"| node_web_prisma
node_web_tx_create -->|"write"| node_web_prisma
node_web_inngest -->|"query"| node_web_prisma
node_web_inngest -->|"generate"| node_web_ai
node_web_inngest -->|"notify"| node_web_email
node_web_api_tx -->|"guard"| node_web_protect

click node_android_main "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/MainActivity.kt"
click node_android_settings "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/SettingsActivity.kt"
click node_android_share "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/ShareReceiverActivity.kt"
click node_android_notify "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/RedexNotificationListener.kt"
click node_android_gemini "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/GeminiParser.kt"
click node_android_dedupe "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt"
click node_android_guard "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/ShareGuard.kt"
click node_android_db "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/AppDatabase.kt"
click node_android_worker "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/TransactionWorker.kt"
click node_android_sender "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/HttpSender.kt"
click node_android_whitelist "https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/WhitelistManager.kt"
click node_web_auth "https://github.com/devxniv/redex/blob/main/web/app/(auth)/layout.jsx"
click node_web_shell "https://github.com/devxniv/redex/blob/main/web/app/(main)/layout.js"
click node_web_dashboard "https://github.com/devxniv/redex/blob/main/web/app/(main)/dashboard/page.jsx"
click node_web_account "https://github.com/devxniv/redex/blob/main/web/app/(main)/account/[id]/page.jsx"
click node_web_tx_create "https://github.com/devxniv/redex/blob/main/web/app/(main)/transaction/create/page.jsx"
click node_web_api_tx "https://github.com/devxniv/redex/blob/main/web/app/api/transactions/route.js"
click node_web_prisma "https://github.com/devxniv/redex/blob/main/web/prisma/schema.prisma"
click node_web_inngest "https://github.com/devxniv/redex/blob/main/web/lib/inngest/function.js"
click node_web_ai "https://github.com/devxniv/redex/blob/main/web/actions/dashboard.js"
click node_web_email "https://github.com/devxniv/redex/blob/main/web/emails/template.jsx"
click node_web_protect "https://github.com/devxniv/redex/blob/main/web/lib/arcjet.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_android_main,node_android_settings,node_android_share,node_android_notify,node_android_gemini,node_android_dedupe,node_android_guard,node_android_db,node_android_worker,node_android_sender,node_android_whitelist toneBlue
class node_web_auth,node_web_shell,node_web_dashboard,node_web_account,node_web_tx_create,node_web_api_tx,node_web_prisma,node_web_inngest,node_web_ai,node_web_email,node_web_protect toneAmber
```

## Components

### Android app

Offline-first capture, normalization, and retry pipeline on device.

- [Main screen](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/MainActivity.kt): ui/status-perms · Shows app status and permission entry points. · `android/app/src/main/java/com/example/redex_expensetracker/MainActivity.kt`
- [Settings](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/SettingsActivity.kt): ui/whitelist · Manages allowed source apps and whitelist controls. · `android/app/src/main/java/com/example/redex_expensetracker/SettingsActivity.kt`
- [Share intake](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/ShareReceiverActivity.kt): activity/intake · Receives shared screenshots for manual transaction capture. · `android/app/src/main/java/com/example/redex_expensetracker/ShareReceiverActivity.kt`
- [Notification listener](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/RedexNotificationListener.kt): listener/capture · Listens to payment notifications as an ingestion edge. · `android/app/src/main/java/com/example/redex_expensetracker/RedexNotificationListener.kt`
- [Gemini parser](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/GeminiParser.kt): ai/extraction · Extracts structured transaction fields from screenshots and notification text. · `android/app/src/main/java/com/example/redex_expensetracker/GeminiParser.kt`
- [Deduplicator](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt): validation/dedupe · Suppresses duplicate transaction submissions on device. · `android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt`
- [Share guard](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/ShareGuard.kt): rate-limit · Limits repeated share-triggered ingestion attempts. · `android/app/src/main/java/com/example/redex_expensetracker/ShareGuard.kt`
- [Local queue](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/AppDatabase.kt): room/offline-store · Room database for pending transactions and retry state. · `android/app/src/main/java/com/example/redex_expensetracker/AppDatabase.kt`
- [Retry worker](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/TransactionWorker.kt): workmanager/retry · Drains queued payloads and retries delivery when network returns. · `android/app/src/main/java/com/example/redex_expensetracker/TransactionWorker.kt`
- [HTTP sender](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/HttpSender.kt): http/write-path · Posts structured transactions to the web backend using the shared secret. · `android/app/src/main/java/com/example/redex_expensetracker/HttpSender.kt`
- [Whitelist manager](https://github.com/devxniv/redex/blob/main/android/app/src/main/java/com/example/redex_expensetracker/WhitelistManager.kt): policy/source-filter · Stores and applies allowed app sources for capture. · `android/app/src/main/java/com/example/redex_expensetracker/WhitelistManager.kt`

### Web platform

Next.js app, API, persistence, and automation backend.

- [Auth routes](https://github.com/devxniv/redex/blob/main/web/app/(auth)/layout.jsx): nextjs/auth · Public sign-in and sign-up flows under the auth segment. · `web/app/(auth)/layout.jsx`
- [Main shell](https://github.com/devxniv/redex/blob/main/web/app/(main)/layout.js): nextjs/protected · Protected application routes guarded by middleware. · `web/app/(main)/layout.js`
- [Dashboard](https://github.com/devxniv/redex/blob/main/web/app/(main)/dashboard/page.jsx): ui/overview · Aggregates balances, budgets, and transaction trends. · `web/app/(main)/dashboard/page.jsx`
- [Account view](https://github.com/devxniv/redex/blob/main/web/app/(main)/account/[id]/page.jsx): ui/details · Shows account-specific history and charts. · `web/app/(main)/account/[id]/page.jsx`
- [Create transaction](https://github.com/devxniv/redex/blob/main/web/app/(main)/transaction/create/page.jsx): ui/entry · Manual transaction entry and receipt scanning. · `web/app/(main)/transaction/create/page.jsx`
- [Transactions API](https://github.com/devxniv/redex/blob/main/web/app/api/transactions/route.js): api/ingestion · Validates the shared secret and persists Android-sent payloads. · `web/app/api/transactions/route.js`
- [Prisma schema](https://github.com/devxniv/redex/blob/main/web/prisma/schema.prisma): postgres/domain-model · Authoritative financial data model for users, accounts, transactions, and budgets. · `web/prisma/schema.prisma`
- [Inngest jobs](https://github.com/devxniv/redex/blob/main/web/lib/inngest/function.js): automation/async · Scheduled recurring transactions, reports, and budget checks. · `web/lib/inngest/function.js`
- [Report AI](https://github.com/devxniv/redex/blob/main/web/actions/dashboard.js): ai/narrative · Generates monthly report insights on the server side. · `web/actions/dashboard.js`
- [Email templates](https://github.com/devxniv/redex/blob/main/web/emails/template.jsx): notifications/email · Renders monthly reports and budget alert emails. · `web/emails/template.jsx`
- [API protection](https://github.com/devxniv/redex/blob/main/web/lib/arcjet.js): security/rate-limit · Arcjet-backed protection around the web surface. · `web/lib/arcjet.js`

## Connections

- Main screen → Notification listener: configure · Exposes notification capture as a core app capability.
- Main screen → Settings: open · Navigates to whitelist and control settings.
- Settings → Whitelist manager: manage · Reads and updates allowed source apps.
- Notification listener → Gemini parser: extract · Turns notification content into structured transaction fields.
- Share intake → Gemini parser: extract · Processes shared screenshots into structured fields.
- Gemini parser → Deduplicator: normalize · Produces candidate transactions for duplicate checking.
- Deduplicator → Share guard: gate · Applies replay suppression and share throttling.
- Share guard → Local queue: enqueue · Stores failed or deferred payloads locally.
- Deduplicator → HTTP sender: send · Writes accepted transactions toward the server path.
- HTTP sender → Transactions API: POST · Single HTTP integration seam from device to backend.
- Retry worker → Local queue: drain · Reads queued transactions for retry.
- Retry worker → HTTP sender: retry · Attempts delivery of stored payloads when connectivity returns.
- Auth routes → Main shell: enter · Authenticated users move into the protected app shell.
- Main shell → Dashboard: route · Primary landing experience inside the protected area.
- Main shell → Account view: route · Drills into account-level views and charts.
- Main shell → Create transaction: route · Supports manual entry and receipt scanning.
- Transactions API → Prisma schema: persist · Stores Android-sent transactions in Postgres through Prisma.
- Dashboard → Prisma schema: read · Consumes balances, budgets, and trends from the database.
- Account view → Prisma schema: read · Loads account history and related transactions.
- Create transaction → Prisma schema: write · Creates or updates transaction records.
- Inngest jobs → Prisma schema: query · Uses persisted financial state for scheduled jobs.
- Inngest jobs → Report AI: generate · Produces narrative insights for monthly reports.
- Inngest jobs → Email templates: notify · Sends report and budget alert emails.
- Transactions API → API protection: guard · API surface is protected by rate limiting and security checks.
