# ayushsalunkhe/medgemma-pillidentification architecture

> Architecture diagram of the GitHub repository ayushsalunkhe/medgemma-pillidentification, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayushsalunkhe/medgemma-pillidentification
- Repository: https://github.com/ayushsalunkhe/medgemma-pillidentification

## Overview

##### Project type and purpose
- This is a single-page, front-end React+TypeScript application built with Vite.
- Purpose: let users upload images of medicine labels, fetch drug details from the FDA API, and translate or enrich content via the Gemini AI API.

##### File structure
Top level:
- index.html & index.tsx – entry point for the browser.
- App.tsx – root React component.
- vite.config.ts – build and dev-server config.
- package.json & tsconfig.json – dependencies and TS settings.
- .gitignore, metadata.json – misc.

Directories:
- hooks/ – custom hooks (useTranslations).
- services/ – API wrappers (fdaService.ts, geminiService.ts).
- types.ts – shared TypeScript types and interfaces.

##### README for additional insights
- The app runs locally with `npm run dev`.
- Requires setting `GEMINI_API_KEY` in `.env.local`.
- No server-side code—instead, the front end directly calls external REST and AI APIs.

a. Main components to include:
1) Browser / Client: your React SPA (App.tsx + all components & hooks)
2) Service Layer: fdaService and geminiService modules
3) External APIs:
- FDA Open API for drug information
- Gemini AI API for translation/enrichment
4) Dev/Build Tooling: Vite Dev Server & bundler (for local dev and production builds)
5) Environment Configuration: `.env.local` with GEMINI_API_KEY

b. Relationships and data flow
- User uploads an image → ImageUploader component captures file →
↓
- fdaService POST/GET to FDA API → returns raw medicine data →
↓
- MedicineInfoCard and SideEffectsChart render FDA data →
↓
- If translation is needed, the TranslationLoader hook calls geminiService → Gemini API → returns translated text → UI updates.

c. Architectural patterns and design principles
- Layered architecture: UI Components → Hooks → Services → External APIs
- Separation of concerns: components handle rendering, services handle external calls, hooks handle orchestration
- Environment-driven configuration: API key injection via Vite’s env mechanism

d. Key technologies and libraries
- React + TypeScript
- Vite (dev server & build)
- FDA Open API (REST)
- Gemini AI API (AI/ML)
- Custom hook pattern (useTranslations)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Title
    subgraph "System Architecture: Medicine Label Translator App"
    end

    %% Presentation Layer
    subgraph "Presentation Layer (UI Components)"
        direction TB
        Header["Header"]:::frontend
        Loader["Loader"]:::frontend
        ImageUploader["ImageUploader"]:::frontend
        LanguageSelector["LanguageSelector"]:::frontend
        MedicineInfoCard["MedicineInfoCard"]:::frontend
        SideEffectsChart["SideEffectsChart"]:::frontend
        TranslationLoaderUI["TranslationLoader (UI)"]:::frontend
        FormattedContent["FormattedContent"]:::frontend
        subgraph "Icon Library"
            direction TB
            AlertTriangleIcon["AlertTriangleIcon"]:::frontend
            BanIcon["BanIcon"]:::frontend
            CameraIcon["CameraIcon"]:::frontend
            ChevronDownIcon["ChevronDownIcon"]:::frontend
            ClockIcon["ClockIcon"]:::frontend
            GlobeIcon["GlobeIcon"]:::frontend
            InfoIcon["InfoIcon"]:::frontend
            PillIcon["PillIcon"]:::frontend
            ThermometerIcon["ThermometerIcon"]:::frontend
            UploadIcon["UploadIcon"]:::frontend
        end
    end

    %% Hooks Layer
    subgraph "Business Logic Layer (Custom Hooks)"
        direction TB
        UseTranslations["useTranslations"]:::hook
    end

    %% Services Layer
    subgraph "Data Access Layer (Services)"
        direction TB
        FdaService["fdaService"]:::service
        GeminiService["geminiService"]:::service
    end

    %% Shared Types & Config
    subgraph "Shared & Config"
        direction TB
        Types["types.ts"]:::config
        Metadata["metadata.json"]:::config
        EnvLocal[".env.local (GEMINI_API_KEY)"]:::config
    end

    %% Tooling
    subgraph "Build & Tooling"
        direction TB
        ViteConfig["vite.config.ts"]:::tooling
        TsConfig["tsconfig.json"]:::tooling
        PackageJson["package.json"]:::tooling
    end

    %% Entry Points
    subgraph "Entry Points"
        direction TB
        IndexHTML["index.html"]:::config
        IndexTSX["index.tsx"]:::frontend
        AppTSX["App.tsx"]:::frontend
    end

    %% External APIs
    subgraph "External APIs"
        direction TB
        FDAAPI["FDA Open API"]:::external
        GeminiAPI["Gemini AI API"]:::external
    end

    %% Dev Server
    DevServer["Vite Dev Server"]:::tooling

    %% Data Flows
    ImageUploader -->|"upload image"| FdaService
    FdaService -->|"GET /drug/{id}"| FDAAPI
    FDAAPI -->|"drug data"| FdaService
    FdaService -->|"medicine data"| MedicineInfoCard
    MedicineInfoCard -->|renders| SideEffectsChart
    LanguageSelector -->|"select language"| UseTranslations
    UseTranslations -->|"POST translation request"| GeminiService
    GeminiService -->|"call AI"| GeminiAPI
    GeminiAPI -->|"translated text"| GeminiService
    GeminiService -->|"text response"| TranslationLoaderUI
    TranslationLoaderUI -->|"display"| FormattedContent

    %% App Initialization Flow
    IndexHTML --> IndexTSX
    IndexTSX --> AppTSX
    AppTSX --> Header
    AppTSX --> ImageUploader
    AppTSX --> MedicineInfoCard

    %% Dependencies
    AppTSX --> UseTranslations
    UseTranslations --> FdaService
    UseTranslations --> GeminiService

    %% Tooling & Config links
    DevServer --> IndexHTML
    DevServer --> ViteConfig
    ViteConfig --> TsConfig
    ViteConfig --> PackageJson

    %% Shared types
    FdaService --> Types
    GeminiService --> Types
    PresentationLayer --> Types

    %% Click Events
    click Header "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/Header.tsx"
    click Loader "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/Loader.tsx"
    click ImageUploader "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/ImageUploader.tsx"
    click LanguageSelector "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/LanguageSelector.tsx"
    click MedicineInfoCard "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/MedicineInfoCard.tsx"
    click SideEffectsChart "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/SideEffectsChart.tsx"
    click TranslationLoaderUI "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/TranslationLoader.tsx"
    click FormattedContent "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/FormattedContent.tsx"
    click AlertTriangleIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/AlertTriangleIcon.tsx"
    click BanIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/BanIcon.tsx"
    click CameraIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/CameraIcon.tsx"
    click ChevronDownIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/ChevronDownIcon.tsx"
    click ClockIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/ClockIcon.tsx"
    click GlobeIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/GlobeIcon.tsx"
    click InfoIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/InfoIcon.tsx"
    click PillIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/PillIcon.tsx"
    click ThermometerIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/ThermometerIcon.tsx"
    click UploadIcon "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//components/icons/UploadIcon.tsx"
    click UseTranslations "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//hooks/useTranslations.ts"
    click FdaService "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//services/fdaService.ts"
    click GeminiService "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//services/geminiService.ts"
    click Types "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//types.ts"
    click Metadata "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//metadata.json"
    click EnvLocal "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//.env.local"
    click ViteConfig "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//vite.config.ts"
    click TsConfig "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//tsconfig.json"
    click PackageJson "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//package.json"
    click IndexHTML "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//index.html"
    click IndexTSX "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//index.tsx"
    click AppTSX "https://github.com/ayushsalunkhe/medgemma-pillidentification/blob/main//App.tsx"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:1px;
    classDef hook fill:#d1c4e9,stroke:#512da8,stroke-width:1px;
    classDef service fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px;
    classDef external fill:#ffe0b2,stroke:#e65100,stroke-width:1px;
    classDef tooling fill:#e0e0e0,stroke:#424242,stroke-width:1px;
    classDef config fill:#fff9c4,stroke:#fbc02d,stroke-width:1px;
```
