How hugeletters/recallio works
Project type and purpose
• This is a full‑stack PWA built with Next.js (T3 Stack template):
• Frontend: React pages/components under src/pages, src/interface, src/layout, etc.
• Backend: Next.js API Routes and tRPC endpoints under src/pages/api and src/server/api.
• Database: SQLite hosted on Turso, accessed via Drizzle (migrations in database/).
• Cache/Queue: Redis via Upstash.
• File uploads: Uploadthing.
• Cron jobs: scheduled scripts in scripts/cron and src/server/cron.
• Service Worker for offline features in src/sw.
File structure
• Top‑level separation:
• public/ – static assets and manifest.
• src/pages/ – Next.js page components (including /api routes).
• src/server/ – server‑side logic: API, auth, database layers, cron, Redis, uploadthing, validation.
• scripts/ – dev/build/run scripts, DB migration generators, cron triggers.
• database/migrations/ – SQL migrations and snapshot history.
• src/sw/ – service worker code.
• Notice use of:
• NextAuth for user sessions (src/auth, src/pages/api/auth/[...nextauth].ts).
• tRPC for type‑safe RPC (trpc/, src/pages/api/trpc/[trpc].ts).
• Drizzle ORM config (drizzle.config.ts).
• Redis caching modules (src/server/redis/).
• Uploadthing integration (src/server/uploadthing/ and src/uploadthing/).
README for additional insights
• Purpose: scan grocery‑store barcodes, view or leave reviews, mark private, tag, search.
• Services: Turso (DB), Upstash (Redis & MQ), Uploadthing (file storage), Vercel (hosting).
• PWA considerations: camera capture in secure context; uses service worker.
Main components and their interactions
a. Frontend (Browser/PWA)
– Next.js pages (React UI): scan page, product/review pages, search, auth pages.
– React Contexts/providers: Auth provider, Toast provider, state store.
– tRPC client: issues queries/mutations to backend.
– Service Worker: caches assets, intercepts fetch, handles offline TRPC queries.
– Barcode‑scanner module (src/scan/).
b. Backend (Serverless functions on Vercel)
– Next.js API Routes:
• Auth (/api/auth/[...nextauth] using NextAuth, DB adapter).
• Cron endpoints (/api/file‑cleanup, /api/logs‑cleanup).
• Uploadthing (/api/uploadthing).
– tRPC router (/api/trpc/[trpc]): routes to src/server/api/*.
– Server modules: DB client (Drizzle), cache utils, product scrapers, validation, logging.
– Cron workers: triggered by Upstash MQ or schedule, run cleanup & seed scripts.
c. Data stores & external services
– Turso (SQLite): persistent data (users, reviews, products, logs).
– Upstash Redis: caching layer, message queue for cron.
– Uploadthing: file storage for review images.
– External barcode scanning via navigator.mediaDevices.
Architectural patterns & design principles
• Monorepo‑style layering: clear separation between frontend (src/pages, UI modules) and backend (src/server).
• Serverless microservices: each API route acts as an isolated function.
• tRPC for type‑safe RPC replaces REST.
• Drizzle ORM centralizes schema/migrations.
• React Context & Zustand‑style store (src/state, src/layout/store).
• PWA best practices: service worker caching, offline support.
• Cron jobs decoupled via message queue.