How devxniv/redex works
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: schema.prisma Prisma schema · layout.js Main shell · function.js Inngest jobs · TransactionDeduplicator.kt Deduplicator
Components 22
Android app
Offline-first capture, normalization, and retry pipeline on device.
- Main screen · Shows app status and permission entry points.
android/app/src/main/java/com/example/redex_expensetracker/MainActivity.kt - Settings · Manages allowed source apps and whitelist controls.
android/app/src/main/java/com/example/redex_expensetracker/SettingsActivity.kt - Share intake · Receives shared screenshots for manual transaction capture.
android/app/src/main/java/com/example/redex_expensetracker/ShareReceiverActivity.kt - Notification listener · Listens to payment notifications as an ingestion edge.
android/app/src/main/java/com/example/redex_expensetracker/RedexNotificationListener.kt - Gemini parser · Extracts structured transaction fields from screenshots and notification text.
android/app/src/main/java/com/example/redex_expensetracker/GeminiParser.kt - Deduplicator · Suppresses duplicate transaction submissions on device.
android/app/src/main/java/com/example/redex_expensetracker/TransactionDeduplicator.kt - Share guard · Limits repeated share-triggered ingestion attempts.
android/app/src/main/java/com/example/redex_expensetracker/ShareGuard.kt - Local queue · Room database for pending transactions and retry state.
android/app/src/main/java/com/example/redex_expensetracker/AppDatabase.kt - Retry worker · Drains queued payloads and retries delivery when network returns.
android/app/src/main/java/com/example/redex_expensetracker/TransactionWorker.kt - HTTP sender · Posts structured transactions to the web backend using the shared secret.
android/app/src/main/java/com/example/redex_expensetracker/HttpSender.kt - Whitelist manager · 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 · Public sign-in and sign-up flows under the auth segment.
web/app/(auth)/layout.jsx - Main shell · Protected application routes guarded by middleware.
web/app/(main)/layout.js - Dashboard · Aggregates balances, budgets, and transaction trends.
web/app/(main)/dashboard/page.jsx - Account view · Shows account-specific history and charts.
web/app/(main)/account/[id]/page.jsx - Create transaction · Manual transaction entry and receipt scanning.
web/app/(main)/transaction/create/page.jsx - Transactions API · Validates the shared secret and persists Android-sent payloads.
web/app/api/transactions/route.js - Prisma schema · Authoritative financial data model for users, accounts, transactions, and budgets.
web/prisma/schema.prisma - Inngest jobs · Scheduled recurring transactions, reports, and budget checks.
web/lib/inngest/function.js - Report AI · Generates monthly report insights on the server side.
web/actions/dashboard.js - Email templates · Renders monthly reports and budget alert emails.
web/emails/template.jsx - API protection · Arcjet-backed protection around the web surface.
web/lib/arcjet.js
Connections 24
- 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.