# fullmetal-007/genai_health_buddy architecture

> Architecture diagram of the GitHub repository fullmetal-007/genai_health_buddy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fullmetal-007/genai_health_buddy
- Repository: https://github.com/fullmetal-007/genai_health_buddy

## Overview

##### Project Type and Purpose
- This is a full-stack, AI-powered web application named “GenAI Health Buddy.”
- Purpose: provide prescription analysis, medicine info, symptom checking, interactive chat, and WhatsApp notifications using Google Gemini API and Meta WhatsApp Business API.

##### File Structure
- Top-level files:
- App.tsx, index.tsx, index.html, vite.config.ts → React / Vite frontend
- services/ (backendService.ts, geminiService.ts) → frontend API wrappers
- components/ → UI modules (cards, uploader, chat, spinner, etc.)
- backend/ → Node.js/Express server (server.js, package.json, .env)
- metadata.json, types.ts, tsconfig.json → type definitions and metadata
- No database directory—no persistent storage; logic lives in frontend, calls two external APIs.
- Environment files indicate two runtime contexts: frontend (Google API key) and backend (Meta credentials).

##### README for Additional Insights
- Confirms tech stack: React + TypeScript + Tailwind (frontend), Node + Express (backend); native ES modules with importmap, no heavy build step.
- Architecture sketch in text: frontend handles UI and calls AI engine directly, backend handles WhatsApp integration.
- Key external systems: Google Gemini API, Meta WhatsApp Business API.

##### Main Components and Their Relationships
a. Frontend Application (Browser)
- React UI Components (in /components)
- Service Layer (services/geminiService.ts calls Google Gemini; services/backendService.ts talks to Express)
- Static asset host (npx serve or similar)
b. Backend Server (Node + Express)
- Endpoint(s) for WhatsApp messages (server.js)
- Environment config for Meta API credentials
c. External Services
- Google Gemini API – generative AI tasks (prescription OCR, chat, symptom analysis)
- Meta WhatsApp Business API – sending summary via WhatsApp
d. Data Flow
1. User uploads prescription or sends a query in UI
2. Frontend → geminiService (HTTP REST to Google Gemini) → receives parsed data or text
3. Frontend displays results and optionally calls backendService to send WhatsApp
4. backendService → Express backend → Meta WhatsApp API → WhatsApp recipient
5. Responses flow back to frontend for confirmation display

##### Architectural Patterns & Design Principles
- Separation of concerns: UI, service wrappers, and backend integration are strictly partitioned.
- API-driven: frontend orchestrates calls to AI engine and backend rather than embedding logic.
- Environment isolation: two .env files ensure secrets do not cross boundaries.
- Modular components: reusable React components for cards, uploaders, and chat.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Browser
    subgraph "Frontend (Browser)"
        direction TB
        subgraph "React UI"
            direction TB
            CC["ComparisonCard"]:::frontend
            HD["Header"]:::frontend
            IC["Icons"]:::frontend
            LS["LanguageSelector"]:::frontend
            LG["Logo"]:::frontend
            MC["MedicineCard"]:::frontend
            PR["PrescriptionResult"]:::frontend
            PU["PrescriptionUploader"]:::frontend
            SB["SearchBar"]:::frontend
            SP["Spinner"]:::frontend
        end
        subgraph "Service Layer"
            direction TB
            GS["geminiService.ts"]:::frontend
            BS["backendService.ts"]:::frontend
        end
        subgraph "Config & Types"
            direction TB
            VC["vite.config.ts"]:::frontend
            TC["tsconfig.json"]:::frontend
            TT["types.ts"]:::frontend
            MJ["metadata.json"]:::frontend
        end
    end

    %% Backend Server
    subgraph "Express Server"
        direction TB
        ES["server.js"]:::backend
        PJ["package.json"]:::backend
        PL["package-lock.json"]:::backend
        EN[".env"]:::backend
    end

    %% External APIs
    GoogleGemini["Google Gemini API"]:::external
    MetaWhatsApp["Meta WhatsApp Business API"]:::external
    UserInbox["User Inbox (WhatsApp)"]:::external

    %% Data Flow
    PU -->|"upload prescription / send query"| GS
    SB -->|"search medicine"| GS
    PR -->|"interactive chat"| GS
    GS -->|"REST API calls"| GoogleGemini
    GoogleGemini -->|"AI response"| GS
    GS -->|"returns data"| PR

    PU -->|"request WhatsApp send"| BS
    BS -->|"HTTP POST"| ES
    ES -->|"Meta API call"| MetaWhatsApp
    MetaWhatsApp -->|"delivers message"| UserInbox
    MetaWhatsApp -->|"callback"| ES
    ES -->|"response"| BS
    BS -->|"confirmation"| PU

    %% Click Events
    click CC "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/ComparisonCard.tsx"
    click HD "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/Header.tsx"
    click IC "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/Icons.tsx"
    click LS "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/LanguageSelector.tsx"
    click LG "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/Logo.tsx"
    click MC "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/MedicineCard.tsx"
    click PR "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/PrescriptionResult.tsx"
    click PU "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/PrescriptionUploader.tsx"
    click SB "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/SearchBar.tsx"
    click SP "https://github.com/fullmetal-007/genai_health_buddy/blob/main/components/Spinner.tsx"
    click GS "https://github.com/fullmetal-007/genai_health_buddy/blob/main/services/geminiService.ts"
    click BS "https://github.com/fullmetal-007/genai_health_buddy/blob/main/services/backendService.ts"
    click VC "https://github.com/fullmetal-007/genai_health_buddy/blob/main/vite.config.ts"
    click TC "https://github.com/fullmetal-007/genai_health_buddy/blob/main/tsconfig.json"
    click TT "https://github.com/fullmetal-007/genai_health_buddy/blob/main/types.ts"
    click MJ "https://github.com/fullmetal-007/genai_health_buddy/blob/main/metadata.json"
    click ES "https://github.com/fullmetal-007/genai_health_buddy/blob/main/backend/server.js"
    click PJ "https://github.com/fullmetal-007/genai_health_buddy/blob/main/backend/package.json"
    click PL "https://github.com/fullmetal-007/genai_health_buddy/blob/main/backend/package-lock.json"
    click EN "https://github.com/fullmetal-007/genai_health_buddy/blob/main/backend/.env"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    class UserInbox,GoogleGemini,MetaWhatsApp external
    class ES,PJ,PL,EN backend
    class CC,HD,IC,LS,LG,MC,PR,PU,SB,SP,GS,BS,VC,TC,TT,MJ frontend
```
