# praveenkumar-dev-art/gemma-4-competition architecture

> Architecture diagram of the GitHub repository praveenkumar-dev-art/gemma-4-competition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/praveenkumar-dev-art/gemma-4-competition
- Repository: https://github.com/praveenkumar-dev-art/gemma-4-competition

## Overview

#### Purpose and entry points
Sanjeevani is a multilingual, voice-first rural-health triage application. The primary web entry is `sanjeevani-app/src/main.jsx`, which mounts `sanjeevani-app/src/App.jsx`. It is built as a React/Vite PWA and can be packaged into Android through Capacitor; the Android host starts at `sanjeevani-app/android/app/src/main/java/com/sanjeevani/triage/MainActivity.java`.

#### Application shell and safety UI
`App.jsx` composes the user journey and persistent safety surfaces: disclaimer, header, intake, chat/triage, emergency handling, and reports.
- `sanjeevani-app/src/App.jsx`
- `sanjeevani-app/src/components/Disclaimer.jsx`
- `sanjeevani-app/src/components/EmergencyModal.jsx`

The emergency UI is a control boundary: RED triage escalates to a blocking 108-call overlay rather than normal conversational continuation.

#### Patient intake and interaction layer
The app collects patient demographics, selected language, and symptom conversation before or during triage. Voice-oriented interaction is implemented in dedicated UI components, while chat renders bilingual clinical guidance.
- `sanjeevani-app/src/components/PatientIntakeWizard.jsx`
- `sanjeevani-app/src/components/VoiceWidget.jsx`
- `sanjeevani-app/src/components/ChatContainer.jsx`

Input crosses from browser/device interaction into shared clinical state; the design supports Tamil, Malayalam, Telugu, Hindi, and English.

#### Triage state and agentic memory
`TriageContext` is the central client-side state boundary. It accumulates patient and conversation information across turns, including the documented Patient, Rough, Clean, and concentrated-question memory pages. UI components consume this shared state rather than independently determining care urgency.
- `sanjeevani-app/src/context/TriageContext.jsx`
- `sanjeevani-app/src/components/TriagePanel.jsx`

#### Clinical reasoning pipeline and offline fallback
Clinical logic applies SOCRATES-guided questioning, a symptom ontology, and WHO-aligned severity classification. This local engine is the continuity path when no model API key or network is available; it should remain independent from remote inference.
- `sanjeevani-app/src/scripts/clinicalAgent/index.js`
- `sanjeevani-app/src/scripts/clinicalAgent/clinicalReasoningEngine.js`
- `sanjeevani-app/src/scripts/clinicalAgent/symptomOntology.js`

The outcome controls three principal routes: RED emergency escalation, YELLOW clinic referral, and GREEN self-care guidance.

#### Remote Gemma inference boundary
Prompt construction and model access are separated from the UI and deterministic clinical fallback. Prompt templates constrain multilingual SOCRATES dialogue and structured output; the service calls Google’s Gemini API for Gemma-compatible model responses, configured through Vite environment variables.
- `sanjeevani-app/src/scripts/clinicalAgent/doctorPrompts.js`
- `sanjeevani-app/src/services/gemmaService.js`

Remote output must be interpreted into application triage state, not treated as unbounded presentation content.

#### Care routing, reports, and external runtime services
Triage results drive clinic discovery/referral, patient-facing triage panels, and a dual report/pass surface. Mock/local data supports development or offline scenarios.
- `sanjeevani-app/src/components/ClinicLocator.jsx`
- `sanjeevani-app/src/components/TriagePass.jsx`
- `sanjeevani-app/src/data/mockData.js`

A separate Node HTTP runtime provides `/api/tts` audio support on port 3001: `sanjeevani-app/server.js`. Web builds use Vite (`sanjeevani-app/vite.config.js`); Android packaging uses Capacitor (`sanjeevani-app/capacitor.config.json` and `sanjeevani-app/android/`). CI runs through `.github/workflows/ci.yml`.

Main entry points: [`sanjeevani-app/src/context/TriageContext.jsx`](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/context/TriageContext.jsx) (Triage state and memory), [`sanjeevani-app/src/App.jsx`](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/App.jsx) (Application shell), [`sanjeevani-app/src/scripts/clinicalAgent/index.js`](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/index.js) (Clinical agent), [`sanjeevani-app/src/components/ChatContainer.jsx`](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/ChatContainer.jsx) (Bilingual chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React PWA"]
  node_web_entry["Web entry<br/>React/Vite entry<br/>[main.jsx]"]
  node_app_shell["Application shell<br/>React composition<br/>[App.jsx]"]
  node_intake["Patient intake<br/>intake UI"]
  node_voice["Voice interaction<br/>voice UI<br/>[VoiceWidget.jsx]"]
  node_chat["Bilingual chat<br/>chat UI<br/>[ChatContainer.jsx]"]
  node_triage_state[("Triage state and memory<br/>shared client state<br/>[TriageContext.jsx]")]
  node_triage_panel["Triage panel<br/>outcome UI<br/>[TriagePanel.jsx]"]
  node_emergency["108 emergency overlay<br/>safety control<br/>[EmergencyModal.jsx]"]
  node_clinic_locator["Clinic referral<br/>care routing UI<br/>[ClinicLocator.jsx]"]
  node_triage_pass["Triage report/pass<br/>report UI<br/>[TriagePass.jsx]"]
  node_mock_data[("Offline mock data<br/>local data<br/>[mockData.js]")]
end

subgraph group_clinical["Clinical decisioning"]
  node_clinical_agent["Clinical agent<br/>reasoning orchestrator<br/>[index.js]"]
  node_reasoning_engine["Offline reasoning engine<br/>deterministic triage"]
  node_symptom_ontology[("Symptom ontology<br/>clinical knowledge<br/>[symptomOntology.js]")]
  node_prompts["Clinical prompts<br/>prompt templates<br/>[doctorPrompts.js]"]
end

subgraph group_services["External services"]
  node_gemma_service["Gemma inference service<br/>remote inference adapter<br/>[gemmaService.js]"]
  node_tts_server["TTS API<br/>Node HTTP service<br/>[server.js]"]
end

subgraph group_runtime["Build and delivery"]
  node_android_host["Android host<br/>Capacitor Android runtime<br/>[MainActivity.java]"]
  node_ci{{"CI pipeline<br/>GitHub Actions<br/>[ci.yml]"}}
end

node_web_entry -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_intake
node_app_shell -->|"renders"| node_chat
node_app_shell -->|"renders"| node_triage_panel
node_app_shell -->|"renders"| node_emergency
node_intake -->|"stores patient and language"| node_triage_state
node_voice -->|"supplies voice input"| node_triage_state
node_chat -->|"reads and writes turns"| node_triage_state
node_chat -->|"requests speech audio"| node_tts_server
node_triage_state -->|"submits clinical context"| node_clinical_agent
node_clinical_agent -->|"uses offline fallback"| node_reasoning_engine
node_reasoning_engine -->|"consults"| node_symptom_ontology
node_clinical_agent -->|"builds constrained prompts"| node_prompts
node_clinical_agent -.->|"uses when available"| node_gemma_service
node_clinical_agent -->|"returns structured outcome"| node_triage_state
node_triage_state -->|"drives guidance"| node_triage_panel
node_triage_state -->|"RED escalation"| node_emergency
node_triage_state -->|"YELLOW referral"| node_clinic_locator
node_triage_state -->|"generates report"| node_triage_pass
node_mock_data -.->|"offline development data"| node_clinic_locator
node_android_host -->|"hosts packaged PWA"| node_app_shell
node_ci -->|"builds and validates"| node_web_entry

click node_web_entry "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/main.jsx"
click node_app_shell "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/App.jsx"
click node_intake "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/PatientIntakeWizard.jsx"
click node_voice "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/VoiceWidget.jsx"
click node_chat "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/ChatContainer.jsx"
click node_triage_state "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/context/TriageContext.jsx"
click node_triage_panel "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/TriagePanel.jsx"
click node_emergency "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/EmergencyModal.jsx"
click node_clinic_locator "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/ClinicLocator.jsx"
click node_triage_pass "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/TriagePass.jsx"
click node_clinical_agent "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/index.js"
click node_reasoning_engine "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/clinicalReasoningEngine.js"
click node_symptom_ontology "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/symptomOntology.js"
click node_prompts "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/doctorPrompts.js"
click node_gemma_service "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/services/gemmaService.js"
click node_tts_server "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/server.js"
click node_mock_data "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/data/mockData.js"
click node_android_host "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/android/app/src/main/java/com/sanjeevani/triage/MainActivity.java"
click node_ci "https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/.github/workflows/ci.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_entry,node_app_shell,node_intake,node_voice,node_chat,node_triage_state,node_triage_panel,node_emergency,node_clinic_locator,node_triage_pass,node_mock_data toneBlue
class node_clinical_agent,node_reasoning_engine,node_symptom_ontology,node_prompts toneAmber
class node_gemma_service,node_tts_server toneMint
class node_android_host,node_ci toneRose
```

## Components

### React PWA

- [Web entry](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/main.jsx): React/Vite entry · `sanjeevani-app/src/main.jsx`
- [Application shell](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/App.jsx): React composition · Composes the care journey and persistent safety UI. · `sanjeevani-app/src/App.jsx`
- [Patient intake](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/PatientIntakeWizard.jsx): intake UI · `sanjeevani-app/src/components/PatientIntakeWizard.jsx`
- [Voice interaction](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/VoiceWidget.jsx): voice UI · `sanjeevani-app/src/components/VoiceWidget.jsx`
- [Bilingual chat](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/ChatContainer.jsx): chat UI · `sanjeevani-app/src/components/ChatContainer.jsx`
- [Triage state and memory](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/context/TriageContext.jsx): shared client state · Holds patient, conversation, and multi-page agent memory. · `sanjeevani-app/src/context/TriageContext.jsx`
- [Triage panel](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/TriagePanel.jsx): outcome UI · `sanjeevani-app/src/components/TriagePanel.jsx`
- [108 emergency overlay](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/EmergencyModal.jsx): safety control · Blocks normal conversation for RED outcomes. · `sanjeevani-app/src/components/EmergencyModal.jsx`
- [Clinic referral](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/ClinicLocator.jsx): care routing UI · `sanjeevani-app/src/components/ClinicLocator.jsx`
- [Triage report/pass](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/components/TriagePass.jsx): report UI · `sanjeevani-app/src/components/TriagePass.jsx`
- [Offline mock data](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/data/mockData.js): local data · `sanjeevani-app/src/data/mockData.js`

### Clinical decisioning

- [Clinical agent](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/index.js): reasoning orchestrator · `sanjeevani-app/src/scripts/clinicalAgent/index.js`
- [Offline reasoning engine](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/clinicalReasoningEngine.js): deterministic triage · SOCRATES and WHO-aligned classification continuity path. · `sanjeevani-app/src/scripts/clinicalAgent/clinicalReasoningEngine.js`
- [Symptom ontology](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/symptomOntology.js): clinical knowledge · `sanjeevani-app/src/scripts/clinicalAgent/symptomOntology.js`
- [Clinical prompts](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/scripts/clinicalAgent/doctorPrompts.js): prompt templates · Constrains multilingual dialogue and structured output. · `sanjeevani-app/src/scripts/clinicalAgent/doctorPrompts.js`

### External services

- [Gemma inference service](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/src/services/gemmaService.js): remote inference adapter · Calls Gemini API and interprets model output into triage state. · `sanjeevani-app/src/services/gemmaService.js`
- [TTS API](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/server.js): Node HTTP service · Provides /api/tts on port 3001. · `sanjeevani-app/server.js`

### Build and delivery

- [Android host](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/sanjeevani-app/android/app/src/main/java/com/sanjeevani/triage/MainActivity.java): Capacitor Android runtime · `sanjeevani-app/android/app/src/main/java/com/sanjeevani/triage/MainActivity.java`
- [CI pipeline](https://github.com/praveenkumar-dev-art/gemma-4-competition/blob/main/.github/workflows/ci.yml): GitHub Actions · `.github/workflows/ci.yml`

## Connections

- Web entry → Application shell: mounts
- Application shell → Patient intake: renders
- Application shell → Bilingual chat: renders
- Application shell → Triage panel: renders
- Application shell → 108 emergency overlay: renders
- Patient intake → Triage state and memory: stores patient and language
- Voice interaction → Triage state and memory: supplies voice input
- Bilingual chat → Triage state and memory: reads and writes turns
- Bilingual chat → TTS API: requests speech audio
- Triage state and memory → Clinical agent: submits clinical context
- Clinical agent → Offline reasoning engine: uses offline fallback
- Offline reasoning engine → Symptom ontology: consults
- Clinical agent → Clinical prompts: builds constrained prompts
- Clinical agent → Gemma inference service: uses when available
- Clinical agent → Triage state and memory: returns structured outcome
- Triage state and memory → Triage panel: drives guidance
- Triage state and memory → 108 emergency overlay: RED escalation
- Triage state and memory → Clinic referral: YELLOW referral
- Triage state and memory → Triage report/pass: generates report
- Offline mock data → Clinic referral: offline development data
- Android host → Application shell: hosts packaged PWA
- CI pipeline → Web entry: builds and validates
