# dhruvasai/jansahayak- architecture

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

- Interactive diagram: https://gitdiagram.com/dhruvasai/jansahayak-
- Repository: https://github.com/dhruvasai/jansahayak-

## Overview

JanSahayak is a multilingual welfare-scheme application assistant delivered through Telegram and WhatsApp. A citizen converses by text or voice, provides eligibility details and Aadhaar imagery, then the system queues form generation and returns an application reference, screenshot, and (where available) SMS confirmation. The graph preserves the documented OCR, speech, conversation memory, scheme, and application-record capabilities. Some runtime modules are indexed but unsampled, so their internal links are omitted or marked unverified rather than inferred.

Main entry points: [`main.py`](https://github.com/dhruvasai/jansahayak-/blob/main/main.py) (FastAPI backend), [`aws_services.py`](https://github.com/dhruvasai/jansahayak-/blob/main/aws_services.py) (AWS service helpers), [`routers/rpa_queue.py`](https://github.com/dhruvasai/jansahayak-/blob/main/routers/rpa_queue.py) (RPA job queue), [`routers/telegram_webhook.py`](https://github.com/dhruvasai/jansahayak-/blob/main/routers/telegram_webhook.py) (Telegram handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Channels and API"]
  node_backend["FastAPI backend<br/>[main.py]"]
  node_telegram_handler["Telegram handler"]
  node_whatsapp_handler["WhatsApp handler"]
  node_legacy_webhook["WhatsApp webhook<br/>[webhook.py]"]
  node_polling_bot["Polling bot<br/>[polling_bot.py]"]
  node_src_polling_bot["Alternate polling bot<br/>[polling_bot.py]"]
end

subgraph group_conversation["Conversation and Documents"]
  node_chat["Chat and eligibility<br/>[chat.py]"]
  node_documents["Aadhaar OCR and checks<br/>[documents.py]"]
  node_memory["Conversation memory<br/>[memory.py]"]
  node_stt["Speech recognition<br/>[stt_engine.py]"]
end

subgraph group_application["Application Processing"]
  node_scheme_catalog["Scheme catalog<br/>[schemes.py]"]
  node_application_api["Application records API<br/>[applications.py]"]
  node_application_model["Application record schema<br/>[application.py]"]
  node_user_model["User schema<br/>[user.py]"]
  node_message_model["Message schema<br/>[message.py]"]
  node_rpa_queue["RPA job queue<br/>[rpa_queue.py]"]
  node_rpa_agent["Scheme form agent<br/>[rpa_agent.py]"]
  node_application_result["Reference and screenshot"]
end

subgraph group_persistence["State and Records"]
end

subgraph group_integrations["Cloud Integrations"]
  node_aws["AWS service helpers<br/>[aws_services.py]"]
  node_src_aws["Alternate AWS helpers<br/>[aws_services.py]"]
  node_s3[("Amazon S3")]
  node_dynamodb[("Amazon DynamoDB")]
  node_sns["Amazon SNS"]
  node_bedrock["Amazon Bedrock"]
  node_transcribe["Amazon Transcribe"]
  node_textract["Amazon Textract"]
  node_groq["Groq services"]
end

node_citizen(("Rural citizen"))
node_telegram(("Telegram"))
node_twilio(("Twilio WhatsApp"))

node_citizen -->|"sends messages"| node_telegram
node_citizen -->|"sends messages"| node_twilio
node_telegram -->|"delivers updates"| node_telegram_handler
node_twilio -->|"posts messages"| node_whatsapp_handler
node_backend -->|"mounts route"| node_telegram_handler
node_backend -->|"mounts route"| node_whatsapp_handler
node_backend -->|"mounts route"| node_rpa_queue
node_backend -->|"mounts route"| node_documents
node_backend -->|"mounts route"| node_application_api
node_backend -->|"mounts route"| node_scheme_catalog
node_backend -->|"mounts route"| node_legacy_webhook
node_telegram_handler -->|"processes text"| node_chat
node_telegram_handler -->|"loads and saves history"| node_memory
node_telegram_handler -->|"requests OCR"| node_documents
node_telegram_handler -->|"enqueues application"| node_rpa_queue
node_whatsapp_handler -->|"requests OCR"| node_documents
node_whatsapp_handler -->|"submits form"| node_rpa_agent
node_legacy_webhook -->|"requests response"| node_chat
node_legacy_webhook -->|"runs submission"| node_rpa_agent
node_chat -->|"requests LLM"| node_aws
node_chat -.->|"fallback inference"| node_groq
node_documents -->|"uses OCR helpers"| node_aws
node_documents -.->|"extracts document text"| node_textract
node_stt -.->|"fallback transcription"| node_transcribe
node_stt -.->|"transcribes audio"| node_groq
node_rpa_queue -->|"runs scheme form"| node_rpa_agent
node_rpa_queue -->|"stores and notifies"| node_aws
node_rpa_queue -->|"sends confirmation"| node_application_result
node_rpa_agent -->|"returns ID and image"| node_application_result
node_aws -->|"stores screenshots"| node_s3
node_aws -->|"stores application"| node_dynamodb
node_aws -->|"sends SMS"| node_sns
node_aws -->|"runs inference"| node_bedrock
node_polling_bot -.->|"uses conversation routes"| node_chat
node_polling_bot -.->|"uses job queue"| node_rpa_queue
node_src_polling_bot -.->|"uses conversation routes"| node_chat
node_src_polling_bot -.->|"uses job queue"| node_rpa_queue

click node_backend "https://github.com/dhruvasai/jansahayak-/blob/main/main.py"
click node_telegram_handler "https://github.com/dhruvasai/jansahayak-/blob/main/routers/telegram_webhook.py"
click node_whatsapp_handler "https://github.com/dhruvasai/jansahayak-/blob/main/routers/whatsapp_webhook.py"
click node_legacy_webhook "https://github.com/dhruvasai/jansahayak-/blob/main/routers/webhook.py"
click node_chat "https://github.com/dhruvasai/jansahayak-/blob/main/routers/chat.py"
click node_documents "https://github.com/dhruvasai/jansahayak-/blob/main/routers/documents.py"
click node_memory "https://github.com/dhruvasai/jansahayak-/blob/main/routers/memory.py"
click node_stt "https://github.com/dhruvasai/jansahayak-/blob/main/services/stt_engine.py"
click node_scheme_catalog "https://github.com/dhruvasai/jansahayak-/blob/main/routers/schemes.py"
click node_application_api "https://github.com/dhruvasai/jansahayak-/blob/main/routers/applications.py"
click node_application_model "https://github.com/dhruvasai/jansahayak-/blob/main/models/application.py"
click node_user_model "https://github.com/dhruvasai/jansahayak-/blob/main/models/user.py"
click node_message_model "https://github.com/dhruvasai/jansahayak-/blob/main/models/message.py"
click node_rpa_queue "https://github.com/dhruvasai/jansahayak-/blob/main/routers/rpa_queue.py"
click node_rpa_agent "https://github.com/dhruvasai/jansahayak-/blob/main/rpa_agent.py"
click node_polling_bot "https://github.com/dhruvasai/jansahayak-/blob/main/polling_bot.py"
click node_src_polling_bot "https://github.com/dhruvasai/jansahayak-/blob/main/src/polling_bot.py"
click node_aws "https://github.com/dhruvasai/jansahayak-/blob/main/aws_services.py"
click node_src_aws "https://github.com/dhruvasai/jansahayak-/blob/main/src/aws_services.py"

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_backend,node_telegram_handler,node_whatsapp_handler,node_legacy_webhook,node_polling_bot,node_src_polling_bot toneBlue
class node_chat,node_documents,node_memory,node_stt toneAmber
class node_scheme_catalog,node_application_api,node_application_model,node_user_model,node_message_model,node_rpa_queue,node_rpa_agent,node_application_result toneMint
class node_aws,node_src_aws,node_s3,node_dynamodb,node_sns,node_bedrock,node_transcribe,node_textract,node_groq,node_citizen,node_telegram,node_twilio toneIndigo
```

## Components

### Channels and API

- [FastAPI backend](https://github.com/dhruvasai/jansahayak-/blob/main/main.py): `main.py`
- [Telegram handler](https://github.com/dhruvasai/jansahayak-/blob/main/routers/telegram_webhook.py): `routers/telegram_webhook.py`
- [WhatsApp handler](https://github.com/dhruvasai/jansahayak-/blob/main/routers/whatsapp_webhook.py): `routers/whatsapp_webhook.py`
- [WhatsApp webhook](https://github.com/dhruvasai/jansahayak-/blob/main/routers/webhook.py): `routers/webhook.py`
- [Polling bot](https://github.com/dhruvasai/jansahayak-/blob/main/polling_bot.py): `polling_bot.py`
- [Alternate polling bot](https://github.com/dhruvasai/jansahayak-/blob/main/src/polling_bot.py): `src/polling_bot.py`

### Conversation and Documents

- [Chat and eligibility](https://github.com/dhruvasai/jansahayak-/blob/main/routers/chat.py): `routers/chat.py`
- [Aadhaar OCR and checks](https://github.com/dhruvasai/jansahayak-/blob/main/routers/documents.py): `routers/documents.py`
- [Conversation memory](https://github.com/dhruvasai/jansahayak-/blob/main/routers/memory.py): `routers/memory.py`
- [Speech recognition](https://github.com/dhruvasai/jansahayak-/blob/main/services/stt_engine.py): `services/stt_engine.py`

### Application Processing

- [Scheme catalog](https://github.com/dhruvasai/jansahayak-/blob/main/routers/schemes.py): `routers/schemes.py`
- [Application records API](https://github.com/dhruvasai/jansahayak-/blob/main/routers/applications.py): `routers/applications.py`
- [Application record schema](https://github.com/dhruvasai/jansahayak-/blob/main/models/application.py): `models/application.py`
- [User schema](https://github.com/dhruvasai/jansahayak-/blob/main/models/user.py): `models/user.py`
- [Message schema](https://github.com/dhruvasai/jansahayak-/blob/main/models/message.py): `models/message.py`
- [RPA job queue](https://github.com/dhruvasai/jansahayak-/blob/main/routers/rpa_queue.py): `routers/rpa_queue.py`
- [Scheme form agent](https://github.com/dhruvasai/jansahayak-/blob/main/rpa_agent.py): `rpa_agent.py`
- **Reference and screenshot**

### Cloud Integrations

- [AWS service helpers](https://github.com/dhruvasai/jansahayak-/blob/main/aws_services.py): `aws_services.py`
- [Alternate AWS helpers](https://github.com/dhruvasai/jansahayak-/blob/main/src/aws_services.py): `src/aws_services.py`
- **Amazon S3**
- **Amazon DynamoDB**
- **Amazon SNS**
- **Amazon Bedrock**
- **Amazon Transcribe**
- **Amazon Textract**
- **Groq services**

### Other components

- **Rural citizen**
- **Telegram**
- **Twilio WhatsApp**

## Connections

- Rural citizen → Telegram: sends messages (evidence: `README.md`)
- Rural citizen → Twilio WhatsApp: sends messages (evidence: `README.md`)
- Telegram → Telegram handler: delivers updates (evidence: `README.md`)
- Twilio WhatsApp → WhatsApp handler: posts messages (evidence: `routers/whatsapp_webhook.py`)
- FastAPI backend → Telegram handler: mounts route (evidence: `main.py`)
- FastAPI backend → WhatsApp handler: mounts route (evidence: `main.py`)
- FastAPI backend → RPA job queue: mounts route (evidence: `main.py`)
- FastAPI backend → Aadhaar OCR and checks: mounts route (evidence: `main.py`)
- FastAPI backend → Application records API: mounts route (evidence: `main.py`)
- FastAPI backend → Scheme catalog: mounts route (evidence: `main.py`)
- FastAPI backend → WhatsApp webhook: mounts route (evidence: `main.py`)
- Telegram handler → Chat and eligibility: processes text (evidence: `routers/telegram_webhook.py`)
- Telegram handler → Conversation memory: loads and saves history (evidence: `routers/telegram_webhook.py`)
- Telegram handler → Aadhaar OCR and checks: requests OCR (evidence: `routers/telegram_webhook.py`)
- Telegram handler → RPA job queue: enqueues application (evidence: `routers/telegram_webhook.py`)
- WhatsApp handler → Aadhaar OCR and checks: requests OCR (evidence: `routers/whatsapp_webhook.py`)
- WhatsApp handler → Scheme form agent: submits form (evidence: `routers/whatsapp_webhook.py`)
- WhatsApp webhook → Chat and eligibility: requests response (evidence: `routers/webhook.py`)
- WhatsApp webhook → Scheme form agent: runs submission (evidence: `routers/webhook.py`)
- Chat and eligibility → AWS service helpers: requests LLM (evidence: `routers/chat.py`)
- Chat and eligibility → Groq services: fallback inference (evidence: `routers/chat.py`)
- Aadhaar OCR and checks → AWS service helpers: uses OCR helpers (evidence: `routers/documents.py`)
- Aadhaar OCR and checks → Amazon Textract: extracts document text (evidence: `README.md`)
- Speech recognition → Amazon Transcribe: fallback transcription (evidence: `README.md`)
- Speech recognition → Groq services: transcribes audio (evidence: `README.md`)
- RPA job queue → Scheme form agent: runs scheme form (evidence: `routers/rpa_queue.py`)
- RPA job queue → AWS service helpers: stores and notifies (evidence: `routers/rpa_queue.py`)
- RPA job queue → Reference and screenshot: sends confirmation (evidence: `routers/rpa_queue.py`)
- Scheme form agent → Reference and screenshot: returns ID and image (evidence: `rpa_agent.py`)
- AWS service helpers → Amazon S3: stores screenshots
- AWS service helpers → Amazon DynamoDB: stores application
- AWS service helpers → Amazon SNS: sends SMS
- AWS service helpers → Amazon Bedrock: runs inference (evidence: `aws_services.py`)
- Polling bot → Chat and eligibility: uses conversation routes (evidence: `polling_bot.py`)
- Polling bot → RPA job queue: uses job queue (evidence: `polling_bot.py`)
- Alternate polling bot → Chat and eligibility: uses conversation routes (evidence: `src/polling_bot.py`)
- Alternate polling bot → RPA job queue: uses job queue (evidence: `src/polling_bot.py`)
