How supthunder/snaptab works
Project type and purpose
• SnapTab is a full-stack, mobile-first Progressive Web App (PWA) built with Next.js 14 (App Router).
• Purpose: Enable group travel expense tracking by snapping receipt photos, AI-extracting data, auto-splitting costs, and offering live balance and settlement features.
File structure
• Top-level “app” folder: Next.js App Router pages and layouts.
• app/page.tsx, app/layout.tsx – Core shell and root layout.
• app/api/scan-receipt/route.ts – Serverless API endpoint for receipt scanning.
• app/(feature) – Routes for add-expense, create-trip, trips, expenses, scan, settlement.
• “components” folder: UI primitives (buttons, dialogs, tables, charts) and theme provider.
• “hooks” and “lib” – Shared React hooks (use-mobile, use-toast) and utility functions.
• Config files (next.config.mjs, tailwind.config.ts, postcss.config.mjs, tsconfig.json) – Build and deployment scripts.
• “public” – Static assets and PWA manifest.
README for additional insights
• Frontend: Next.js (Server & Client Components), Tailwind CSS, PWA + offline caching.
• Backend: Vercel serverless functions, Prisma ORM + Vercel Postgres, NextAuth.js for authentication.
• AI & Storage: OpenAI GPT-4 Vision for receipt parsing; Vercel Blob for image storage.
• Data models in Prisma schema define Users, Trips, Expenses, ExpenseSplits.
a. Main components
• Client (Browser/PWA) – React pages & components running in mobile or desktop.
• Next.js Server – SSR, Server Components, API routes, and Server Actions.
• Authentication Service – NextAuth.js backed by OAuth (Google/Apple/email).
• Database – Vercel Postgres accessed via Prisma.
• AI Service – OpenAI GPT-4 Vision API for receipt analysis.
• Blob Storage – Vercel Blob for receipt image storage.
• External Services – OAuth providers; Vercel Hosting.
b. Relationships & interactions
1. User interacts with the PWA → HTTP(S) requests to Next.js server.
2. NextAuth.js handles sign-in/out and session management.
3. On “Snap Receipt”:
• Client uploads image to Vercel Blob.
• Next.js API route (/api/scan-receipt) calls OpenAI Vision with image URL.
• OpenAI returns JSON → Next.js populates form.
4. Saving an expense:
• Client submits through Server Component or Action → Prisma writes to Postgres.
• ExpenseSplits table generated to record per-user owed amounts.
5. Real-time updates:
• Next.js streaming Server Components or client polling fetch latest balances & feeds.
6. Settlement:
• Backend computes optimized payment graph using splits → updates database.
c. Architectural patterns/design principles
• App Router & mixed Server/Client Components for SEO and performance.
• Serverless micro-endpoints (API routes + Server Actions) – no monolithic backend.
• Layered separation: UI layer → API/Server Actions → ORM → Database.
• Progressive enhancement: offline caching (Workbox or Next.js PWA plugin).
• Single-page experience with nested layouts.
d. Key technologies/frameworks
• Next.js 14 (App Router), React, PWA API
• Tailwind CSS for UI
• Prisma ORM → PostgreSQL
• NextAuth.js → OAuth
• OpenAI GPT-4 Vision
• Vercel Blob storage
• Vercel serverless functions