How akhilathuluri/allergy-guard works
Project Type and Purpose
• Type: Full-stack single-page web application.
• Purpose: Help users manage food allergies by scanning products/menus (via OCR and AI) and providing personalized, safe meal recommendations.
File Structure
• Top-level files (package.json, vite.config.ts, tsconfig.json, tailwind.config.js) configure build/tooling.
• src/
– components/: Reusable UI (Navbar, ProtectedRoute)
– pages/: Route-based views (Home, Dashboard, ScanProduct, etc.)
– context/: React Context for global state (AuthContext)
– lib/: Service wrappers (Supabase client, Gemini AI wrapper)
– types/: Shared TypeScript types
– App.tsx & main.tsx: Bootstrapping & routing
• supabase/: Database schema migrations
• index.html & public/ (implied) serve the SPA shell
README for Additional Insights
• Frontend: React 18 + TS, React Router v6, Tailwind CSS, Context API, React Toastify
• Backend: Supabase (Auth, Database), migrations in supabase/
• AI: Google Generative AI via custom gemini.ts lib
• OCR: Tesseract.js integrated in scanning pages
• Env/config: .env for Supabase & Google API keys
Main Components and Their Relationships
A. Client (Browser)
– UI Layer (React pages & components)
– Routing (React Router)
– State Management (AuthContext for user & allergy state)
– Styling/Assets (Tailwind + index.css)
B. API Layer
– Supabase REST/Realtime endpoints (Auth, CRUD on allergies, scan history)
– Custom wrapper lib/supabase.ts for calls
C. AI & OCR Services
– Tesseract.js (runs in browser to extract text from images)
– Google Generative AI (via gemini.ts) for ingredient analysis & meal recommendations
D. Database
– Supabase PostgreSQL (tables for users, allergies, scans, recommendations)
– Migrations in supabase/migrations
E. External Services
– Supabase Auth service
– Google AI Platform
F. Build & Deployment
– Vite dev server & build pipeline
– ESLint, TypeScript check
Architectural Patterns & Design Principles
• Client-Server Separation: The SPA handles UI and orchestrates API calls to Supabase and AI endpoints.
• Context API as lightweight state container, minimizing prop-drilling.
• Service Abstraction: lib/ folders wrap low-level API calls (Supabase, Gemini AI).
• Feature-Based Routing: One route per page under src/pages.
• Secure Routes: ProtectedRoute component ensures authentication guard.