# ankitkr-ak007/nabha-health-connect-app architecture

> Architecture diagram of the GitHub repository ankitkr-ak007/nabha-health-connect-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ankitkr-ak007/nabha-health-connect-app
- Repository: https://github.com/ankitkr-ak007/nabha-health-connect-app

## Overview

##### Project Type and Purpose
- This is a **single-page, client-side web application** built with React + TypeScript + Vite.
- Purpose: Let users describe symptoms in natural language, call an AI service (Google Gemini or OpenAI) to analyze them, and display results. Supplements include doctor lookup, pharmacy stock, video consultations, and email notifications.

##### File Structure
- **components/** → UI elements & pages (SymptomChecker, FindDoctor, AuthLayout, Modals, etc.).
- **contexts/** → React context for authentication & global state.
- **hooks/** → Custom hook (useLocalStorage) for persisting tokens or preferences.
- **services/** → External-integration layer (geminiService.ts for AI API; emailService.ts for transactional emails).
- **data/** → Static data (list of doctors).
- **index.tsx / App.tsx** → Root component & entry point.
- **tsconfig.json, vite.config.ts** → Build & bundler configs.

##### README for Insights
- Tech stack: React, TypeScript, Vite, Tailwind CSS.
- Workflow: User Input → Frontend calls AI service → AI returns analysis → Frontend displays.

##### Main Components
a. **Client / Browser** – Hosts the React app (static files served by Vite or a static-hosting provider).
b. **React Application**
- **Presentation Layer**: `components/*`
- **State Layer**: `contexts/AuthContext.tsx`
- **Data Layer**: `data/doctors.ts` (static lookup)
- **Service Layer**: `services/geminiService.ts`, `services/emailService.ts`
- **Utility Layer**: `hooks/useLocalStorage.ts`
c. **External Services**
- **AI API** (Google Gemini / OpenAI)
- **Email Provider** (e.g., SendGrid, SES)
d. **Storage**
- **LocalStorage** (via the custom hook) for tokens/preferences
- **Environment Variables** (`.env.local` / Vite) for API keys

##### Relationships & Data Flows
- **User → Browser**: Enters symptoms, navigates UI.
- **UI Components → Context**: Read/write auth state.
- **Components → Services**:
- SymptomChecker calls `geminiService` → HTTP POST to AI API → parses response → UI displays results.
- Notification or onboarding flows call `emailService` → sends transactional emails.
- **Services → External APIs**: Over secure HTTPS (keys from `import.meta.env.VITE_API_KEY`).
- **Hooks → LocalStorage**: Persist/rehydrate auth tokens.

##### Architectural Patterns & Principles
- **Component-Based UI** (React)
- **Separation of Concerns**
- Presentation vs. Service vs. Data vs. State
- **Context API** for cross-component state (Auth)
- **Modular Service Layer** for easy swapping of AI providers

##### Essential Elements to Capture
- Clear **component groups** (UI vs logic vs data vs integration)
- **External services** explicitly (AI + Email)
- **LocalStorage** as client-side persistence

- **Comprehensive** (covers every folder/group in the tree)
- **Accurate** (reflects real data flows & tech choices)
- **Actionable** (easy for new team members to understand & extend)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Entry Point
    Browser["Client / Browser"]:::external
    index["index.tsx"]:::config
    App["App.tsx"]:::frontend

    Browser -->|"loads"| index
    index -->|"renders"| App

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        SC["SymptomChecker.tsx"]:::frontend
        FD["FindDoctor.tsx"]:::frontend
        AL["AuthLayout.tsx"]:::frontend
        BM["BookingModal.tsx"]:::frontend
        OM["OrderMedicineModal.tsx"]:::frontend
        VC["VideoCallModal.tsx"]:::frontend
        DC["DoctorCard.tsx"]:::frontend
        PS["PharmacyStock.tsx"]:::frontend
        OC["OnlineConsultations.tsx"]:::frontend
        HR["HealthRecords.tsx"]:::frontend
        HM["Home.tsx"]:::frontend
        LG["Login.tsx"]:::frontend
        RG["Register.tsx"]:::frontend
        HD["Header.tsx"]:::frontend
        FT["Footer.tsx"]:::frontend
        IC["Icons.tsx"]:::frontend
    end

    App -->|"imports UI"| SC
    App --> FD
    App --> AL
    App --> HD
    App --> FT

    AL --> LG
    AL --> RG

    SC -->|"uses"| BM
    SC --> OM
    SC --> VC

    FD --> DC

    %% Application Logic Layer
    subgraph "Application Logic"
        direction TB
        AC["AuthContext.tsx"]:::logic
        UH["useLocalStorage.ts"]:::logic
        LS["LocalStorage"]:::data
    end

    SC -->|"auth check"| AC
    FD --> AC
    AC -->|"persists token"| UH
    UH -->|"reads/writes"| LS

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DOC["doctors.ts"]:::data
    end

    FD -->|"loads list"| DOC

    %% Integration Layer
    subgraph "Integration Layer"
        direction TB
        AIService["geminiService.ts"]:::integration
        EmailService["emailService.ts"]:::integration
    end

    SC -->|"POST /analyzeSymptoms"| AIService
    AL -->|"sendEmail()"| EmailService

    %% External Services
    subgraph "External Services"
        direction TB
        AIAPI["AI API (Gemini/OpenAI)"]:::external
        EmailProv["Email Provider"]:::external
        Env["Environment Variables (.env)"]:::config
    end

    AIService -->|"HTTPS"| AIAPI
    EmailService -->|"SMTP/HTTPS"| EmailProv
    Env -.-> AIService
    Env -.-> EmailService

    %% Configuration & Build
    subgraph "Configuration & Build"
        direction TB
        VITE["vite.config.ts"]:::config
        TS["tsconfig.json"]:::config
        PKG["package.json"]:::config
        PKG2["package-lock.json"]:::config
        HTML["index.html"]:::config
        META["metadata.json"]:::config
    end

    index --> HTML
    VITE --> index
    TS --> App

    %% Click Events
    click index "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/index.tsx"
    click App "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/App.tsx"
    click SC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/SymptomChecker.tsx"
    click FD "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/FindDoctor.tsx"
    click AL "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/AuthLayout.tsx"
    click BM "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/BookingModal.tsx"
    click OM "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/OrderMedicineModal.tsx"
    click VC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/VideoCallModal.tsx"
    click DC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/DoctorCard.tsx"
    click PS "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/PharmacyStock.tsx"
    click OC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/OnlineConsultations.tsx"
    click HR "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/HealthRecords.tsx"
    click HM "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/Home.tsx"
    click LG "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/Login.tsx"
    click RG "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/Register.tsx"
    click HD "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/Header.tsx"
    click FT "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/Footer.tsx"
    click IC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/components/icons/Icons.tsx"
    click AC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/contexts/AuthContext.tsx"
    click UH "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/hooks/useLocalStorage.ts"
    click DOC "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/data/doctors.ts"
    click AIService "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/services/geminiService.ts"
    click EmailService "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/services/emailService.ts"
    click VITE "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/vite.config.ts"
    click TS "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/tsconfig.json"
    click PKG "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/package.json"
    click PKG2 "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/package-lock.json"
    click HTML "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/index.html"
    click META "https://github.com/ankitkr-ak007/nabha-health-connect-app/blob/master/metadata.json"

    %% Styles
    classDef frontend fill:#B3D4FC,stroke:#333,stroke-width:1px
    classDef logic fill:#CFFCDD,stroke:#333,stroke-width:1px
    classDef integration fill:#FFE2B3,stroke:#333,stroke-width:1px
    classDef external fill:#FFB3B3,stroke:#333,stroke-width:1px
    classDef data fill:#FFF2B3,stroke:#333,stroke-width:1px
    classDef config fill:#E0E0E0,stroke:#333,stroke-width:1px
```
