# kashvi009/janani-ai-compass architecture

> Architecture diagram of the GitHub repository kashvi009/janani-ai-compass, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kashvi009/janani-ai-compass
- Repository: https://github.com/kashvi009/janani-ai-compass

## Overview

##### Project type and purpose
- This is a full-stack, AI-powered maternal health web application (JANANI).
- Frontend: React + TypeScript + Vite + Tailwind CSS + shadcn/ui.
- Backend: Supabase (Auth, Postgres DB, Edge Functions).
- Core features: symptom analyzer, health scorecard, AI chatbot, ultrasound scheduler, PCOS tracker, gamification, facial login.

##### File structure
- Top-level directories:
- public/ – static assets (robots.txt, index.html)
- src/ – all React source code
- supabase/ – configuration, database migrations, and Edge Functions
- src/components/ – reusable UI components and domain-specific widgets (e.g., SymptomTracker, AIChatbot).
- src/pages/ – route entry points (Index, Dashboard, NotFound).
- src/hooks/ – custom React hooks for stateful logic (useHealthScore, useProfile, etc.).
- src/integrations/supabase/ – client configuration and type definitions.
- Configuration files: tsconfig, vite.config.ts, tailwind.config.ts, eslint.config.js.

##### README for additional insights
- Confirms architecture: SPA hosted on a static host (Vercel).
- Supabase is used for authentication, database, and serverless logic.
- AI/ML logic lives partly in frontend utilities and partly in Supabase Edge Functions.

a. Main components
- Client Browser (React SPA)
- Static Hosting (Vercel/Netlify)
- Supabase Auth & Postgres Database
- Supabase Edge Functions (health score calculation, symptom analysis)
- AI/ML Logic (rule-based logic, future LLM integration)
- External Services (email/SMS reminders, calendar API)
b. Relationships & interactions
- User → React SPA (HTTPS)
- SPA → Supabase Auth (login/signup)
- SPA → Supabase Postgres (CRUD via Supabase client)
- SPA → Edge Functions (invoke via REST)
- Edge Functions → Database (read/write metrics)
- Edge Functions → AI logic modules
- Notifications → External services
c. Architectural patterns & principles
- SPA decoupled from backend services
- Supabase as BaaS (Auth, DB, Functions)
- Component-based UI with domain-specific and generic “ui/” modules
- Hooks for encapsulating stateful logic
d. Key technologies/frameworks
- React + TS + Vite
- Tailwind CSS + shadcn/ui
- Supabase Auth, Postgres, Edge Functions
- Node.js runtime for serverless functions
- Rule-based AI logic in JS/TS utilities

##### Detailed capture of essential elements
- SQL migration folder under Supabase to indicate versioned schema changes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% User Layer
    User["End User"]:::external
    Browser["Web Browser"]:::frontend

    User -->|"access via HTTPS"| Browser

    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        ReactSPA["React SPA"]:::frontend
        subgraph "Entry Points"
            MainTSX["src/main.tsx"]:::frontend
            AppTSX["src/App.tsx"]:::frontend
        end
        subgraph "Pages"
            IndexPage["src/pages/Index.tsx"]:::frontend
            DashboardPage["src/pages/Dashboard.tsx"]:::frontend
            NotFoundPage["src/pages/NotFound.tsx"]:::frontend
        end
        subgraph "Components"
            SymptomAnalyzer["SymptomAnalyzer"]:::frontend
            SymptomTracker["SymptomTracker"]:::frontend
            HealthScorecard["HealthScorecard"]:::frontend
            AIChatbot["AIChatbot"]:::frontend
            AIAssistant["AIAssistant"]:::frontend
            AIExplanation["AIExplanation"]:::frontend
            AIModelExplanation["AIModelExplanation"]:::frontend
            UltrasoundScheduler["UltrasoundScheduler"]:::frontend
            PCOSTracker["PCOSTracker"]:::frontend
            FacialLogin["FacialLogin"]:::frontend
            ProfileEditor["ProfileEditor"]:::frontend
        end
        subgraph "Hooks"
            useGameification["useGameification"]:::frontend
            useHealthScore["useHealthScore"]:::frontend
            useHealthScorecard["useHealthScorecard"]:::frontend
            useSymptomLogger["useSymptomLogger"]:::frontend
            useProfile["useProfile"]:::frontend
        end
        subgraph "Integrations"
            SupabaseClient["client.ts"]:::backend
            SupabaseTypes["types.ts"]:::backend
        end
        Utils["utils.ts"]:::backend
        UIPrimitives["src/components/ui/"]:::frontend
        TailwindConfig["tailwind.config.ts"]:::frontend
        ViteConfig["vite.config.ts"]:::frontend
    end

    Browser -->|"loads SPA"| ReactSPA
    ReactSPA -->|"imports entry"| MainTSX
    ReactSPA -->|"renders root"| AppTSX
    ReactSPA -->|"navigates"| IndexPage
    ReactSPA -->|"navigates"| DashboardPage
    ReactSPA -->|"navigates"| NotFoundPage
    ReactSPA -->|"uses component"| SymptomAnalyzer
    ReactSPA -->|"uses component"| SymptomTracker
    ReactSPA -->|"uses component"| HealthScorecard
    ReactSPA -->|"uses component"| AIChatbot
    ReactSPA -->|"uses component"| UltrasoundScheduler
    ReactSPA -->|"uses component"| PCOSTracker
    ReactSPA -->|"uses component"| FacialLogin
    ReactSPA -->|"uses hook"| useGameification
    ReactSPA -->|"uses hook"| useHealthScore
    ReactSPA -->|"uses hook"| useHealthScorecard
    ReactSPA -->|"uses hook"| useSymptomLogger
    ReactSPA -->|"uses hook"| useProfile
    ReactSPA -->|"calls supabase client"| SupabaseClient
    ReactSPA -->|"refers types"| SupabaseTypes
    ReactSPA -->|"uses utils"| Utils
    ReactSPA -.->|"deployed on"| Vercel

    %% Hosting Layer
    Vercel["Vercel Hosting"]:::hosting

    %% Backend Layer
    subgraph "Backend (Supabase)"
        direction TB
        SupabaseAuth["Supabase Auth"]:::backend
        SupabaseDB["Supabase Postgres"]:::backend
        subgraph "Configuration"
            ConfigToml["supabase/config.toml"]:::backend
            MigrationSQL["supabase/migrations/20250703100508-3db2c4a7-7e79-4199-8065-5181ec027dc9.sql"]:::backend
        end
        subgraph "Edge Functions"
            CalculateHealthScore["calculate-health-score"]:::functions
        end
    end

    ReactSPA -->|"login/signup"| SupabaseAuth
    ReactSPA -->|"CRUD via client"| SupabaseDB
    SupabaseAuth -->|"stores user"| SupabaseDB
    CalculateHealthScore -->|"read/write metrics"| SupabaseDB
    ReactSPA -->|"invoke calculate-health-score"| CalculateHealthScore
    CalculateHealthScore -->|"uses AI logic"| Utils

    %% AI & External Layer
    subgraph "AI Logic & External Services"
        AIModel["Rule-based AI Logic"]:::functions
        ExternalServices["Email/SMS & Calendar API"]:::external
    end

    Utils -->|"core AI rules"| AIModel
    CalculateHealthScore -->|"send notifications"| ExternalServices

    %% Click Events
    click MainTSX "https://github.com/kashvi009/janani-ai-compass/blob/main/src/main.tsx"
    click AppTSX "https://github.com/kashvi009/janani-ai-compass/blob/main/src/App.tsx"
    click IndexPage "https://github.com/kashvi009/janani-ai-compass/blob/main/src/pages/Index.tsx"
    click DashboardPage "https://github.com/kashvi009/janani-ai-compass/blob/main/src/pages/Dashboard.tsx"
    click NotFoundPage "https://github.com/kashvi009/janani-ai-compass/blob/main/src/pages/NotFound.tsx"
    click SymptomAnalyzer "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/SymptomAnalyzer.tsx"
    click SymptomTracker "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/SymptomTracker.tsx"
    click HealthScorecard "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/HealthScorecard.tsx"
    click AIChatbot "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/AIChatbot.tsx"
    click AIAssistant "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/AIAssistant.tsx"
    click AIExplanation "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/AIExplanation.tsx"
    click AIModelExplanation "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/AIModelExplanation.tsx"
    click UltrasoundScheduler "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/UltrasoundScheduler.tsx"
    click PCOSTracker "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/PCOSTracker.tsx"
    click FacialLogin "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/FacialLogin.tsx"
    click useGameification "https://github.com/kashvi009/janani-ai-compass/blob/main/src/hooks/useGameification.ts"
    click useHealthScore "https://github.com/kashvi009/janani-ai-compass/blob/main/src/hooks/useHealthScore.ts"
    click useHealthScorecard "https://github.com/kashvi009/janani-ai-compass/blob/main/src/hooks/useHealthScorecard.ts"
    click useSymptomLogger "https://github.com/kashvi009/janani-ai-compass/blob/main/src/hooks/useSymptomLogger.ts"
    click useProfile "https://github.com/kashvi009/janani-ai-compass/blob/main/src/hooks/useProfile.ts"
    click ProfileEditor "https://github.com/kashvi009/janani-ai-compass/blob/main/src/components/ProfileEditor.tsx"
    click SupabaseClient "https://github.com/kashvi009/janani-ai-compass/blob/main/src/integrations/supabase/client.ts"
    click SupabaseTypes "https://github.com/kashvi009/janani-ai-compass/blob/main/src/integrations/supabase/types.ts"
    click ConfigToml "https://github.com/kashvi009/janani-ai-compass/blob/main/supabase/config.toml"
    click MigrationSQL "https://github.com/kashvi009/janani-ai-compass/blob/main/supabase/migrations/20250703100508-3db2c4a7-7e79-4199-8065-5181ec027dc9.sql"
    click CalculateHealthScore "https://github.com/kashvi009/janani-ai-compass/blob/main/supabase/functions/calculate-health-score/index.ts"
    click Utils "https://github.com/kashvi009/janani-ai-compass/blob/main/src/lib/utils.ts"
    click UIPrimitives "https://github.com/kashvi009/janani-ai-compass/tree/main/src/components/ui/"
    click TailwindConfig "https://github.com/kashvi009/janani-ai-compass/blob/main/tailwind.config.ts"
    click ViteConfig "https://github.com/kashvi009/janani-ai-compass/blob/main/vite.config.ts"

    %% Styles
    classDef frontend fill:#cceeff,stroke:#333,stroke-width:1px
    classDef backend fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef functions fill:#ffddcc,stroke:#333,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef hosting fill:#e0e0ff,stroke:#333,stroke-width:1px
```
