# pprathik07/bharosa architecture

> Architecture diagram of the GitHub repository pprathik07/bharosa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pprathik07/bharosa
- Repository: https://github.com/pprathik07/bharosa

## Overview

Bharosa is a browser-based, voice-first welfare-scheme checker. A caller speaks or types a description; extraction marks possible facts as heard, then the conversation asks for and confirms deciding facts. Ordinary domain rules evaluate schemes, and the app presents rule traces and an SMS preview. The graph preserves the documented speech, multilingual, optional AI-extraction, and speech-output capabilities. Some wiring is documented in the README but its implementation was not sampled; those links are marked dashed with no evidence path.

Main entry points: [`src/app/hooks/useSession.ts`](https://github.com/pprathik07/bharosa/blob/main/src/app/hooks/useSession.ts) (Session orchestrator), [`src/conversation/machine.ts`](https://github.com/pprathik07/bharosa/blob/main/src/conversation/machine.ts) (Conversation reducer), [`src/extraction/ruleBasedExtractor.ts`](https://github.com/pprathik07/bharosa/blob/main/src/extraction/ruleBasedExtractor.ts) (Rule-based extraction), [`src/app/App.tsx`](https://github.com/pprathik07/bharosa/blob/main/src/app/App.tsx) (Call and results UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Caller experience"]
  node_browser["Browser app<br/>[main.tsx]"]
  node_page["Call and results UI<br/>[App.tsx]"]
  node_session["Session orchestrator<br/>[useSession.ts]"]
end

subgraph group_conversation["Conversation and extraction"]
  node_conversation_machine["Conversation reducer<br/>[machine.ts]"]
  node_confirmation["Answer confirmation<br/>[confirmAnswer.ts]"]
  node_extractor["Rule-based extraction"]
  node_lexicon["Multilingual lexicon<br/>[lexicon.ts]"]
  node_number_parser["Number parsing<br/>[numbers.ts]"]
  node_ai_extraction["Optional AI extraction<br/>[aiExtraction.ts]"]
end

subgraph group_eligibility["Eligibility and results"]
  node_scheme_data["Scheme and lexicon data<br/>[data.ts]"]
  node_domain_rules["Scheme rule evaluation<br/>[rules.ts]"]
  node_scheme_loader["Scheme validation<br/>[schemes.ts]"]
  node_fact_requirements["Required facts<br/>[requiredFacts.ts]"]
  node_result_formatting["Result and SMS formatting<br/>[outputs.ts]"]
end

subgraph group_ports["Ports and adapters"]
  node_speech_input_port["Speech input port<br/>[speechInput.ts]"]
  node_browser_input["Browser speech input<br/>[webSpeechInput.ts]"]
  node_typed_input["Typed and demo input<br/>[typedInput.ts]"]
  node_speech_output["Speech output adapters<br/>[webSpeechOutput.ts]"]
  node_sms_preview["SMS preview adapter"]
  node_logger[("Memory logger<br/>[memoryLogger.ts]")]
end

subgraph group_services["Optional server services"]
  node_model_schema["Extraction validation<br/>[extractSchema.ts]"]
  node_api_plugin["Dev API routes<br/>[apiPlugin.ts]"]
  node_model_service{{"AI model providers"}}
  node_speech_service["Gemini speech service<br/>[geminiSpeech.ts]"]
end

node_caller(("Caller"))
node_browser_speech{{"Browser speech engine"}}
node_text_message["SMS preview"]

node_caller -->|"uses"| node_browser
node_browser -->|"mounts"| node_page
node_page -->|"starts session"| node_session
node_page -.->|"shows results"| node_caller
node_session -->|"dispatches events"| node_conversation_machine
node_session -.->|"loads context"| node_scheme_data
node_session -->|"creates default"| node_extractor
node_session -->|"requests extraction"| node_ai_extraction
node_conversation_machine -->|"parses answers"| node_confirmation
node_conversation_machine -->|"evaluates eligibility"| node_domain_rules
node_conversation_machine -->|"builds results"| node_result_formatting
node_conversation_machine -->|"gets required facts"| node_fact_requirements
node_confirmation -->|"uses fallback parsing"| node_extractor
node_extractor -->|"matches phrases"| node_lexicon
node_extractor -->|"parses numbers"| node_number_parser
node_scheme_data -.->|"validates schemes"| node_scheme_loader
node_scheme_data -.->|"provides vocabulary"| node_lexicon
node_ai_extraction -.->|"calls dev route"| node_api_plugin
node_api_plugin -->|"validates extraction"| node_model_schema
node_api_plugin -.->|"requests extraction"| node_model_service
node_ai_extraction -.->|"falls back on error"| node_extractor
node_session -->|"receives transcripts"| node_speech_input_port
node_browser_input -->|"implements"| node_speech_input_port
node_typed_input -.->|"implements"| node_speech_input_port
node_browser_input -.->|"recognizes speech"| node_browser_speech
node_session -.->|"speaks replies"| node_speech_output
node_speech_output -.->|"uses voice"| node_browser_speech
node_speech_output -.->|"optional voice"| node_speech_service
node_conversation_machine -.->|"emits SMS effect"| node_sms_preview
node_sms_preview -.->|"formats preview"| node_text_message
node_session -.->|"records events"| node_logger

click node_browser "https://github.com/pprathik07/bharosa/blob/main/src/app/main.tsx"
click node_page "https://github.com/pprathik07/bharosa/blob/main/src/app/App.tsx"
click node_session "https://github.com/pprathik07/bharosa/blob/main/src/app/hooks/useSession.ts"
click node_scheme_data "https://github.com/pprathik07/bharosa/blob/main/src/app/data.ts"
click node_conversation_machine "https://github.com/pprathik07/bharosa/blob/main/src/conversation/machine.ts"
click node_confirmation "https://github.com/pprathik07/bharosa/blob/main/src/conversation/confirmAnswer.ts"
click node_extractor "https://github.com/pprathik07/bharosa/blob/main/src/extraction/ruleBasedExtractor.ts"
click node_lexicon "https://github.com/pprathik07/bharosa/blob/main/src/extraction/lexicon.ts"
click node_number_parser "https://github.com/pprathik07/bharosa/blob/main/src/extraction/numbers.ts"
click node_ai_extraction "https://github.com/pprathik07/bharosa/blob/main/src/app/aiExtraction.ts"
click node_model_schema "https://github.com/pprathik07/bharosa/blob/main/server/extractSchema.ts"
click node_api_plugin "https://github.com/pprathik07/bharosa/blob/main/server/apiPlugin.ts"
click node_speech_service "https://github.com/pprathik07/bharosa/blob/main/server/geminiSpeech.ts"
click node_domain_rules "https://github.com/pprathik07/bharosa/blob/main/src/domain/rules.ts"
click node_scheme_loader "https://github.com/pprathik07/bharosa/blob/main/src/domain/schemes.ts"
click node_fact_requirements "https://github.com/pprathik07/bharosa/blob/main/src/domain/requiredFacts.ts"
click node_result_formatting "https://github.com/pprathik07/bharosa/blob/main/src/conversation/outputs.ts"
click node_speech_input_port "https://github.com/pprathik07/bharosa/blob/main/src/ports/speechInput.ts"
click node_browser_input "https://github.com/pprathik07/bharosa/blob/main/src/adapters/webSpeechInput.ts"
click node_typed_input "https://github.com/pprathik07/bharosa/blob/main/src/adapters/typedInput.ts"
click node_speech_output "https://github.com/pprathik07/bharosa/blob/main/src/adapters/webSpeechOutput.ts"
click node_sms_preview "https://github.com/pprathik07/bharosa/blob/main/src/adapters/smsPreviewSender.ts"
click node_logger "https://github.com/pprathik07/bharosa/blob/main/src/adapters/memoryLogger.ts"

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_browser,node_page,node_session,node_browser_speech,node_text_message toneBlue
class node_conversation_machine,node_confirmation,node_extractor,node_lexicon,node_number_parser,node_ai_extraction toneAmber
class node_scheme_data,node_domain_rules,node_scheme_loader,node_fact_requirements,node_result_formatting toneMint
class node_speech_input_port,node_browser_input,node_typed_input,node_speech_output,node_sms_preview,node_logger toneRose
class node_model_schema,node_api_plugin,node_model_service,node_speech_service,node_caller toneIndigo
```

## Components

### Caller experience

- [Browser app](https://github.com/pprathik07/bharosa/blob/main/src/app/main.tsx): `src/app/main.tsx`
- [Call and results UI](https://github.com/pprathik07/bharosa/blob/main/src/app/App.tsx): `src/app/App.tsx`
- [Session orchestrator](https://github.com/pprathik07/bharosa/blob/main/src/app/hooks/useSession.ts): `src/app/hooks/useSession.ts`

### Conversation and extraction

- [Conversation reducer](https://github.com/pprathik07/bharosa/blob/main/src/conversation/machine.ts): `src/conversation/machine.ts`
- [Answer confirmation](https://github.com/pprathik07/bharosa/blob/main/src/conversation/confirmAnswer.ts): `src/conversation/confirmAnswer.ts`
- [Rule-based extraction](https://github.com/pprathik07/bharosa/blob/main/src/extraction/ruleBasedExtractor.ts): `src/extraction/ruleBasedExtractor.ts`
- [Multilingual lexicon](https://github.com/pprathik07/bharosa/blob/main/src/extraction/lexicon.ts): `src/extraction/lexicon.ts`
- [Number parsing](https://github.com/pprathik07/bharosa/blob/main/src/extraction/numbers.ts): `src/extraction/numbers.ts`
- [Optional AI extraction](https://github.com/pprathik07/bharosa/blob/main/src/app/aiExtraction.ts): `src/app/aiExtraction.ts`

### Eligibility and results

- [Scheme and lexicon data](https://github.com/pprathik07/bharosa/blob/main/src/app/data.ts): `src/app/data.ts`
- [Scheme rule evaluation](https://github.com/pprathik07/bharosa/blob/main/src/domain/rules.ts): `src/domain/rules.ts`
- [Scheme validation](https://github.com/pprathik07/bharosa/blob/main/src/domain/schemes.ts): `src/domain/schemes.ts`
- [Required facts](https://github.com/pprathik07/bharosa/blob/main/src/domain/requiredFacts.ts): `src/domain/requiredFacts.ts`
- [Result and SMS formatting](https://github.com/pprathik07/bharosa/blob/main/src/conversation/outputs.ts): `src/conversation/outputs.ts`

### Ports and adapters

- [Speech input port](https://github.com/pprathik07/bharosa/blob/main/src/ports/speechInput.ts): `src/ports/speechInput.ts`
- [Browser speech input](https://github.com/pprathik07/bharosa/blob/main/src/adapters/webSpeechInput.ts): `src/adapters/webSpeechInput.ts`
- [Typed and demo input](https://github.com/pprathik07/bharosa/blob/main/src/adapters/typedInput.ts): `src/adapters/typedInput.ts`
- [Speech output adapters](https://github.com/pprathik07/bharosa/blob/main/src/adapters/webSpeechOutput.ts): `src/adapters/webSpeechOutput.ts`
- [SMS preview adapter](https://github.com/pprathik07/bharosa/blob/main/src/adapters/smsPreviewSender.ts): `src/adapters/smsPreviewSender.ts`
- [Memory logger](https://github.com/pprathik07/bharosa/blob/main/src/adapters/memoryLogger.ts): `src/adapters/memoryLogger.ts`

### Optional server services

- [Extraction validation](https://github.com/pprathik07/bharosa/blob/main/server/extractSchema.ts): `server/extractSchema.ts`
- [Dev API routes](https://github.com/pprathik07/bharosa/blob/main/server/apiPlugin.ts): `server/apiPlugin.ts`
- **AI model providers**
- [Gemini speech service](https://github.com/pprathik07/bharosa/blob/main/server/geminiSpeech.ts): `server/geminiSpeech.ts`

### Other components

- **Caller**
- **Browser speech engine**
- **SMS preview**

## Connections

- Caller → Browser app: uses
- Browser app → Call and results UI: mounts (evidence: `src/app/main.tsx`)
- Call and results UI → Session orchestrator: starts session (evidence: `src/app/App.tsx`)
- Call and results UI → Caller: shows results
- Session orchestrator → Conversation reducer: dispatches events (evidence: `src/app/hooks/useSession.ts`)
- Session orchestrator → Scheme and lexicon data: loads context
- Session orchestrator → Rule-based extraction: creates default (evidence: `src/app/hooks/useSession.ts`)
- Session orchestrator → Optional AI extraction: requests extraction (evidence: `src/app/hooks/useSession.ts`)
- Conversation reducer → Answer confirmation: parses answers (evidence: `src/conversation/machine.ts`)
- Conversation reducer → Scheme rule evaluation: evaluates eligibility (evidence: `src/conversation/machine.ts`)
- Conversation reducer → Result and SMS formatting: builds results (evidence: `src/conversation/machine.ts`)
- Conversation reducer → Required facts: gets required facts (evidence: `src/conversation/machine.ts`)
- Answer confirmation → Rule-based extraction: uses fallback parsing (evidence: `src/conversation/confirmAnswer.ts`)
- Rule-based extraction → Multilingual lexicon: matches phrases (evidence: `src/extraction/ruleBasedExtractor.ts`)
- Rule-based extraction → Number parsing: parses numbers (evidence: `src/extraction/ruleBasedExtractor.ts`)
- Scheme and lexicon data → Scheme validation: validates schemes
- Scheme and lexicon data → Multilingual lexicon: provides vocabulary
- Optional AI extraction → Dev API routes: calls dev route
- Dev API routes → Extraction validation: validates extraction (evidence: `server/apiPlugin.ts`)
- Dev API routes → AI model providers: requests extraction
- Optional AI extraction → Rule-based extraction: falls back on error
- Session orchestrator → Speech input port: receives transcripts (evidence: `src/app/hooks/useSession.ts`)
- Browser speech input → Speech input port: implements (evidence: `src/adapters/webSpeechInput.ts`)
- Typed and demo input → Speech input port: implements
- Browser speech input → Browser speech engine: recognizes speech
- Session orchestrator → Speech output adapters: speaks replies
- Speech output adapters → Browser speech engine: uses voice
- Speech output adapters → Gemini speech service: optional voice
- Conversation reducer → SMS preview adapter: emits SMS effect
- SMS preview adapter → SMS preview: formats preview
- Session orchestrator → Memory logger: records events (evidence: `src/app/hooks/useSession.ts`)
