# rahullkumr/padh-ke-batao architecture

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

- Interactive diagram: https://gitdiagram.com/rahullkumr/padh-ke-batao
- Repository: https://github.com/rahullkumr/padh-ke-batao

## Overview

Padh Ke Batao is a local-first document explainer: a person selects or drops a document photo, the browser resizes it, and the server streams a Hindi or English explanation produced by a local Ollama model. The result highlights actions, deadlines, and urgency; the Listen feature uses ElevenLabs when configured, otherwise an installed local voice. The README documents the privacy boundary and major features; connections for unsampled HTML and service internals are limited to those documented relationships.

Main entry points: [`src/server.js`](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/server.js) (Fastify server), [`src/services/ollama.js`](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/services/ollama.js) (Model request and stream), [`public/js/app.js`](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/app.js) (Photo and results UI), [`public/js/speech.js`](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/speech.js) (Speech playback)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser experience"]
  node_webpage["App page<br/>[index.html]"]
  node_app["Photo and results UI<br/>[app.js]"]
  node_translations["Hindi and English text<br/>[i18n.js]"]
  node_browser_speech["Speech playback<br/>[speech.js]"]
end

subgraph group_server["Application server"]
  node_server_entry["Fastify server<br/>[server.js]"]
  node_static_pages["Page and asset serving<br/>[pages.js]"]
  node_settings["Runtime settings<br/>[config.js]"]
  node_explain_route["Photo explanation endpoint<br/>[explain.js]"]
  node_speak_route["Speech endpoints<br/>[speak.js]"]
end

subgraph group_explanation["Document explanation"]
  node_prompt["Explanation prompt and schema"]
  node_ollama_service["Model request and stream<br/>[ollama.js]"]
end

subgraph group_speech["Read aloud"]
  node_eleven_service["ElevenLabs speech service<br/>[elevenlabs.js]"]
end

node_person(("Document reader"))
node_local_voice["Installed system voice"]
node_ollama["Local Ollama model"]
node_elevenlabs["ElevenLabs"]

node_person -->|"opens app"| node_webpage
node_webpage -->|"loads interface"| node_app
node_app -->|"uses text"| node_translations
node_app -->|"initializes playback"| node_browser_speech
node_app -->|"posts resized photo"| node_explain_route
node_explain_route -->|"requests explanation"| node_ollama_service
node_ollama_service -->|"builds model prompt"| node_prompt
node_ollama_service -->|"sends image and prompt"| node_ollama
node_ollama -->|"streams answer"| node_ollama_service
node_ollama_service -->|"returns parsed result"| node_explain_route
node_explain_route -->|"streams progress and result"| node_app
node_server_entry -->|"registers route"| node_explain_route
node_server_entry -->|"registers route"| node_speak_route
node_server_entry -->|"registers route"| node_static_pages
node_server_entry -->|"warms model"| node_ollama_service
node_server_entry -->|"reads settings"| node_settings
node_static_pages -->|"serves page assets"| node_webpage
node_browser_speech -->|"uses text"| node_translations
node_browser_speech -->|"requests audio"| node_speak_route
node_browser_speech -->|"falls back to"| node_local_voice
node_speak_route -->|"requests speech"| node_eleven_service
node_eleven_service -->|"sends spoken text"| node_elevenlabs
node_elevenlabs -->|"returns audio stream"| node_eleven_service
node_speak_route -->|"returns audio or status"| node_browser_speech
node_server_entry -->|"checks voice availability"| node_eleven_service

click node_webpage "https://github.com/rahullkumr/padh-ke-batao/blob/main/public/index.html"
click node_app "https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/app.js"
click node_translations "https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/i18n.js"
click node_browser_speech "https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/speech.js"
click node_server_entry "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/server.js"
click node_static_pages "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/pages.js"
click node_settings "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/config.js"
click node_explain_route "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/explain.js"
click node_speak_route "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/speak.js"
click node_prompt "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/prompts/explain-document.js"
click node_ollama_service "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/services/ollama.js"
click node_eleven_service "https://github.com/rahullkumr/padh-ke-batao/blob/main/src/services/elevenlabs.js"

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_webpage,node_app,node_translations,node_browser_speech toneBlue
class node_server_entry,node_static_pages,node_settings,node_explain_route,node_speak_route toneAmber
class node_prompt,node_ollama_service toneMint
class node_eleven_service toneRose
class node_person,node_local_voice,node_ollama,node_elevenlabs toneIndigo
```

## Components

### Browser experience

- [App page](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/index.html): `public/index.html`
- [Photo and results UI](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/app.js): `public/js/app.js`
- [Hindi and English text](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/i18n.js): `public/js/i18n.js`
- [Speech playback](https://github.com/rahullkumr/padh-ke-batao/blob/main/public/js/speech.js): `public/js/speech.js`

### Application server

- [Fastify server](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/server.js): `src/server.js`
- [Page and asset serving](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/pages.js): `src/routes/pages.js`
- [Runtime settings](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/config.js): `src/config.js`
- [Photo explanation endpoint](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/explain.js): `src/routes/explain.js`
- [Speech endpoints](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/routes/speak.js): `src/routes/speak.js`

### Document explanation

- [Explanation prompt and schema](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/prompts/explain-document.js): `src/prompts/explain-document.js`
- [Model request and stream](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/services/ollama.js): `src/services/ollama.js`

### Read aloud

- [ElevenLabs speech service](https://github.com/rahullkumr/padh-ke-batao/blob/main/src/services/elevenlabs.js): `src/services/elevenlabs.js`

### Other components

- **Document reader**
- **Installed system voice**
- **Local Ollama model**
- **ElevenLabs**

## Connections

- Document reader → App page: opens app (evidence: `README.md`)
- App page → Photo and results UI: loads interface (evidence: `README.md`)
- Photo and results UI → Hindi and English text: uses text (evidence: `public/js/app.js`)
- Photo and results UI → Speech playback: initializes playback (evidence: `public/js/app.js`)
- Photo and results UI → Photo explanation endpoint: posts resized photo (evidence: `public/js/app.js`)
- Photo explanation endpoint → Model request and stream: requests explanation (evidence: `src/routes/explain.js`)
- Model request and stream → Explanation prompt and schema: builds model prompt (evidence: `src/services/ollama.js`)
- Model request and stream → Local Ollama model: sends image and prompt (evidence: `README.md`)
- Local Ollama model → Model request and stream: streams answer (evidence: `src/services/ollama.js`)
- Model request and stream → Photo explanation endpoint: returns parsed result (evidence: `src/routes/explain.js`)
- Photo explanation endpoint → Photo and results UI: streams progress and result (evidence: `src/routes/explain.js`)
- Fastify server → Photo explanation endpoint: registers route (evidence: `src/server.js`)
- Fastify server → Speech endpoints: registers route (evidence: `src/server.js`)
- Fastify server → Page and asset serving: registers route (evidence: `src/server.js`)
- Fastify server → Model request and stream: warms model (evidence: `src/server.js`)
- Fastify server → Runtime settings: reads settings (evidence: `src/server.js`)
- Page and asset serving → App page: serves page assets (evidence: `src/routes/pages.js`)
- Speech playback → Hindi and English text: uses text (evidence: `public/js/speech.js`)
- Speech playback → Speech endpoints: requests audio (evidence: `README.md`)
- Speech playback → Installed system voice: falls back to (evidence: `public/js/speech.js`)
- Speech endpoints → ElevenLabs speech service: requests speech (evidence: `src/routes/speak.js`)
- ElevenLabs speech service → ElevenLabs: sends spoken text (evidence: `README.md`)
- ElevenLabs → ElevenLabs speech service: returns audio stream (evidence: `src/services/elevenlabs.js`)
- Speech endpoints → Speech playback: returns audio or status (evidence: `src/routes/speak.js`)
- Fastify server → ElevenLabs speech service: checks voice availability (evidence: `src/server.js`)
