# akhilathuluri/allergy-guard architecture

> Architecture diagram of the GitHub repository akhilathuluri/allergy-guard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akhilathuluri/allergy-guard
- Repository: https://github.com/akhilathuluri/allergy-guard

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        UI["React UI<br/>(Pages & Components)<br/>React 18 + TS"]:::ui
        Router["React Router v6"]:::ui
        ContextAPI["AuthContext<br/>(Context API)"]:::ui
        OCR["Tesseract.js OCR Module"]:::external
    end

    %% API Gateway
    APIGW["Supabase Client Wrapper<br/>(REST/Realtime)"]:::backend

    %% Services Layer
    subgraph "Supabase Backend"
        direction TB
        AuthService["Auth Service"]:::backend
        Database["PostgreSQL Database"]:::backend
        Migrations["Migrations<br/>(supabase/migrations)"]:::backend
    end

    AIService["Google Generative AI<br/>(Gemini)"]:::external

    %% Build & Tooling
    subgraph "Build & Tooling"
        direction TB
        Vite["Vite Dev Server & Build"]:::config
        ESLint["ESLint & TypeScript Checks"]:::config
        TailwindCfg["Tailwind Config"]:::config
    end

    %% Data Flows
    UI -->|"login credentials"| APIGW
    Router -->|routing| UI
    ContextAPI -->|state| UI
    UI -->|"CRUD allergies, history"| APIGW
    UI -->|"scan image"| OCR
    OCR -->|"extracted text"| AIService
    UI -->|"analysis results"| AIService
    APIGW -->|"Auth requests"| AuthService
    APIGW -->|"DB queries"| Database
    AuthService -->|verifies| Database
    Migrations -->|schema| Database

    %% Env Variables
    EnvVars[".env<br/>(Supabase & Google API keys)"]:::config
    EnvVars --> APIGW
    EnvVars --> AIService

    %% Click Events - Components
    click Navbar "https://github.com/akhilathuluri/allergy-guard/blob/main/src/components/Navbar.tsx"
    click ProtectedRoute "https://github.com/akhilathuluri/allergy-guard/blob/main/src/components/ProtectedRoute.tsx"
    click Home "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/Home.tsx"
    click Dashboard "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/Dashboard.tsx"
    click Login "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/Login.tsx"
    click Signup "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/Signup.tsx"
    click AllergiesList "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/AllergiesList.tsx"
    click ScanProduct "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/ScanProduct.tsx"
    click RestaurantMenuScanner "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/RestaurantMenuScanner.tsx"
    click ScanHistory "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/ScanHistory.tsx"
    click ScanDetail "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/ScanDetail.tsx"
    click SmartMealRecommendations "https://github.com/akhilathuluri/allergy-guard/blob/main/src/pages/SmartMealRecommendations.tsx"
    click AuthContext "https://github.com/akhilathuluri/allergy-guard/blob/main/src/context/AuthContext.tsx"
    click supabaseClient "https://github.com/akhilathuluri/allergy-guard/blob/main/src/lib/supabase.ts"
    click geminiClient "https://github.com/akhilathuluri/allergy-guard/blob/main/src/lib/gemini.ts"
    click App "https://github.com/akhilathuluri/allergy-guard/blob/main/src/App.tsx"
    click main "https://github.com/akhilathuluri/allergy-guard/blob/main/src/main.tsx"
    click indexCSS "https://github.com/akhilathuluri/allergy-guard/blob/main/src/index.css"
    click tailwindConfig "https://github.com/akhilathuluri/allergy-guard/blob/main/tailwind.config.js"
    click viteConfig "https://github.com/akhilathuluri/allergy-guard/blob/main/vite.config.ts"
    click tsconfig "https://github.com/akhilathuluri/allergy-guard/blob/main/tsconfig.json"
    click tsconfigApp "https://github.com/akhilathuluri/allergy-guard/blob/main/tsconfig.app.json"
    click tsconfigNode "https://github.com/akhilathuluri/allergy-guard/blob/main/tsconfig.node.json"
    click eslintConfig "https://github.com/akhilathuluri/allergy-guard/blob/main/eslint.config.js"
    click postcssConfig "https://github.com/akhilathuluri/allergy-guard/blob/main/postcss.config.js"
    click migrations "https://github.com/akhilathuluri/allergy-guard/blob/main/supabase/migrations/20250302145845_fancy_cliff.sql"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064,color:#000
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#000
    classDef external fill:#FFF3E0,stroke:#E65100,color:#000
    classDef config fill:#ECEFF1,stroke:#37474F,color:#000
```
