# swethaallada/kavach architecture

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

- Interactive diagram: https://gitdiagram.com/swethaallada/kavach
- Repository: https://github.com/swethaallada/kavach

## Overview

Kavach is a citizen-safety service that analyzes suspicious messages and screenshots through one shared decision engine, returning a localized verdict with citations and scam-only guidance. The web UI and WhatsApp adapter are documented entry points; the backend also supports pattern submissions and an anonymized trends view. The graph preserves the documented classifier stages and major product branches. Some internal links rely on README statements or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`backend/services/classifier.py`](https://github.com/swethaallada/kavach/blob/main/backend/services/classifier.py) (Classifier), [`backend/routes/webhook.py`](https://github.com/swethaallada/kavach/blob/main/backend/routes/webhook.py) (WhatsApp adapter), [`frontend/src/pages/HomePage.jsx`](https://github.com/swethaallada/kavach/blob/main/frontend/src/pages/HomePage.jsx) (Analysis page), [`frontend/src/App.jsx`](https://github.com/swethaallada/kavach/blob/main/frontend/src/App.jsx) (Web app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webapp["Web app<br/>[App.jsx]"]
  node_home["Analysis page<br/>[HomePage.jsx]"]
  node_input["Text and image input<br/>[AnalyzePanel.jsx]"]
  node_verdictui["Verdict display<br/>[VerdictCard.jsx]"]
  node_trendui["Trends dashboard"]
  node_languageui["Language context<br/>[LangContext.js]"]
end

subgraph group_api["Channel and API"]
  node_analyze_route["Analyze endpoint<br/>[analyze.py]"]
  node_image_route["Image endpoint<br/>[image.py]"]
  node_whatsapp["WhatsApp adapter<br/>[webhook.py]"]
  node_patterns_route["Pattern intake API<br/>[patterns.py]"]
  node_trends_route["Trends API<br/>[trends.py]"]
end

subgraph group_engine["Decision engine"]
  node_classifier["Classifier<br/>[classifier.py]"]
  node_rules["Rules classifier<br/>[rules.py]"]
  node_llm["LLM analysis<br/>[llm.py]"]
  node_rag["Pattern retrieval<br/>[rag.py]"]
  node_vision["Image extraction<br/>[vision.py]"]
  node_report["Guided report<br/>[report.py]"]
  node_locales["Response locales<br/>[locales_loader.py]"]
end

subgraph group_data["Knowledge and signals"]
  node_pattern_store[("Crowd pattern store<br/>[pattern_store.py]")]
  node_store[("Telemetry and audit store<br/>[store.py]")]
end

node_citizen(("Citizen"))
node_twilio(("Twilio"))
node_supabase[("Supabase")]
node_xai{{"xAI Grok"}}

node_citizen -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_home
node_home -->|"renders"| node_input
node_input -->|"submits text"| node_analyze_route
node_input -->|"submits image"| node_image_route
node_home -->|"renders verdict"| node_verdictui
node_languageui -->|"supplies language"| node_home
node_analyze_route -->|"calls analyze"| node_classifier
node_image_route -->|"extracts text"| node_vision
node_image_route -->|"analyzes text"| node_classifier
node_twilio -->|"sends message"| node_whatsapp
node_whatsapp -->|"calls analyze"| node_classifier
node_whatsapp -->|"extracts image text"| node_vision
node_whatsapp -->|"formats reply"| node_locales
node_patterns_route -->|"reads and writes"| node_pattern_store
node_classifier -->|"classifies first"| node_rules
node_classifier -->|"requests analysis"| node_llm
node_llm -->|"calls model"| node_xai
node_classifier -->|"retrieves citations"| node_rag
node_classifier -->|"builds guidance"| node_report
node_classifier -->|"localizes response"| node_locales
node_classifier -->|"logs audit"| node_store
node_store -->|"writes telemetry"| node_supabase
node_webapp -->|"routes to trends"| node_trendui
node_trendui -->|"requests trends"| node_trends_route
node_trends_route -->|"reads aggregate"| node_supabase

click node_webapp "https://github.com/swethaallada/kavach/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/swethaallada/kavach/blob/main/frontend/src/pages/HomePage.jsx"
click node_input "https://github.com/swethaallada/kavach/blob/main/frontend/src/components/AnalyzePanel.jsx"
click node_verdictui "https://github.com/swethaallada/kavach/blob/main/frontend/src/components/VerdictCard.jsx"
click node_trendui "https://github.com/swethaallada/kavach/blob/main/frontend/src/components/TrendsDashboard.jsx"
click node_languageui "https://github.com/swethaallada/kavach/blob/main/frontend/src/lib/LangContext.js"
click node_analyze_route "https://github.com/swethaallada/kavach/blob/main/backend/routes/analyze.py"
click node_image_route "https://github.com/swethaallada/kavach/blob/main/backend/routes/image.py"
click node_whatsapp "https://github.com/swethaallada/kavach/blob/main/backend/routes/webhook.py"
click node_patterns_route "https://github.com/swethaallada/kavach/blob/main/backend/routes/patterns.py"
click node_trends_route "https://github.com/swethaallada/kavach/blob/main/backend/routes/trends.py"
click node_classifier "https://github.com/swethaallada/kavach/blob/main/backend/services/classifier.py"
click node_rules "https://github.com/swethaallada/kavach/blob/main/backend/services/rules.py"
click node_llm "https://github.com/swethaallada/kavach/blob/main/backend/services/llm.py"
click node_rag "https://github.com/swethaallada/kavach/blob/main/backend/services/rag.py"
click node_vision "https://github.com/swethaallada/kavach/blob/main/backend/services/vision.py"
click node_report "https://github.com/swethaallada/kavach/blob/main/backend/services/report.py"
click node_locales "https://github.com/swethaallada/kavach/blob/main/backend/core/locales_loader.py"
click node_pattern_store "https://github.com/swethaallada/kavach/blob/main/backend/services/pattern_store.py"
click node_store "https://github.com/swethaallada/kavach/blob/main/backend/services/store.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_webapp,node_home,node_input,node_verdictui,node_trendui,node_languageui toneBlue
class node_analyze_route,node_image_route,node_whatsapp,node_patterns_route,node_trends_route,node_supabase toneAmber
class node_classifier,node_rules,node_llm,node_rag,node_vision,node_report,node_locales toneMint
class node_pattern_store,node_store toneRose
class node_citizen,node_twilio,node_xai toneIndigo
```

## Components

### Web experience

- [Web app](https://github.com/swethaallada/kavach/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Analysis page](https://github.com/swethaallada/kavach/blob/main/frontend/src/pages/HomePage.jsx): `frontend/src/pages/HomePage.jsx`
- [Text and image input](https://github.com/swethaallada/kavach/blob/main/frontend/src/components/AnalyzePanel.jsx): `frontend/src/components/AnalyzePanel.jsx`
- [Verdict display](https://github.com/swethaallada/kavach/blob/main/frontend/src/components/VerdictCard.jsx): `frontend/src/components/VerdictCard.jsx`
- [Trends dashboard](https://github.com/swethaallada/kavach/blob/main/frontend/src/components/TrendsDashboard.jsx): `frontend/src/components/TrendsDashboard.jsx`
- [Language context](https://github.com/swethaallada/kavach/blob/main/frontend/src/lib/LangContext.js): `frontend/src/lib/LangContext.js`

### Channel and API

- [Analyze endpoint](https://github.com/swethaallada/kavach/blob/main/backend/routes/analyze.py): `backend/routes/analyze.py`
- [Image endpoint](https://github.com/swethaallada/kavach/blob/main/backend/routes/image.py): `backend/routes/image.py`
- [WhatsApp adapter](https://github.com/swethaallada/kavach/blob/main/backend/routes/webhook.py): `backend/routes/webhook.py`
- [Pattern intake API](https://github.com/swethaallada/kavach/blob/main/backend/routes/patterns.py): `backend/routes/patterns.py`
- [Trends API](https://github.com/swethaallada/kavach/blob/main/backend/routes/trends.py): `backend/routes/trends.py`

### Decision engine

- [Classifier](https://github.com/swethaallada/kavach/blob/main/backend/services/classifier.py): `backend/services/classifier.py`
- [Rules classifier](https://github.com/swethaallada/kavach/blob/main/backend/services/rules.py): `backend/services/rules.py`
- [LLM analysis](https://github.com/swethaallada/kavach/blob/main/backend/services/llm.py): `backend/services/llm.py`
- [Pattern retrieval](https://github.com/swethaallada/kavach/blob/main/backend/services/rag.py): `backend/services/rag.py`
- [Image extraction](https://github.com/swethaallada/kavach/blob/main/backend/services/vision.py): `backend/services/vision.py`
- [Guided report](https://github.com/swethaallada/kavach/blob/main/backend/services/report.py): `backend/services/report.py`
- [Response locales](https://github.com/swethaallada/kavach/blob/main/backend/core/locales_loader.py): `backend/core/locales_loader.py`

### Knowledge and signals

- [Crowd pattern store](https://github.com/swethaallada/kavach/blob/main/backend/services/pattern_store.py): `backend/services/pattern_store.py`
- [Telemetry and audit store](https://github.com/swethaallada/kavach/blob/main/backend/services/store.py): `backend/services/store.py`

### Other components

- **Citizen**
- **Twilio**
- **Supabase**
- **xAI Grok**

## Connections

- Citizen → Web app: uses (evidence: `README.md`)
- Web app → Analysis page: routes to (evidence: `frontend/src/App.jsx`)
- Analysis page → Text and image input: renders (evidence: `frontend/src/pages/HomePage.jsx`)
- Text and image input → Analyze endpoint: submits text (evidence: `README.md`)
- Text and image input → Image endpoint: submits image (evidence: `README.md`)
- Analysis page → Verdict display: renders verdict (evidence: `frontend/src/pages/HomePage.jsx`)
- Language context → Analysis page: supplies language (evidence: `frontend/src/pages/HomePage.jsx`)
- Analyze endpoint → Classifier: calls analyze (evidence: `README.md`)
- Image endpoint → Image extraction: extracts text (evidence: `backend/routes/image.py`)
- Image endpoint → Classifier: analyzes text (evidence: `backend/routes/image.py`)
- Twilio → WhatsApp adapter: sends message (evidence: `README.md`)
- WhatsApp adapter → Classifier: calls analyze (evidence: `README.md`)
- WhatsApp adapter → Image extraction: extracts image text (evidence: `backend/routes/webhook.py`)
- WhatsApp adapter → Response locales: formats reply
- Pattern intake API → Crowd pattern store: reads and writes (evidence: `backend/routes/patterns.py`)
- Classifier → Rules classifier: classifies first (evidence: `backend/services/classifier.py`)
- Classifier → LLM analysis: requests analysis (evidence: `backend/services/classifier.py`)
- LLM analysis → xAI Grok: calls model (evidence: `README.md`)
- Classifier → Pattern retrieval: retrieves citations (evidence: `backend/services/classifier.py`)
- Classifier → Guided report: builds guidance (evidence: `backend/services/classifier.py`)
- Classifier → Response locales: localizes response (evidence: `backend/services/classifier.py`)
- Classifier → Telemetry and audit store: logs audit (evidence: `backend/services/classifier.py`)
- Telemetry and audit store → Supabase: writes telemetry (evidence: `README.md`)
- Web app → Trends dashboard: routes to trends (evidence: `frontend/src/App.jsx`)
- Trends dashboard → Trends API: requests trends (evidence: `README.md`)
- Trends API → Supabase: reads aggregate (evidence: `README.md`)
