# iamkarthik2004/singham architecture

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

- Interactive diagram: https://gitdiagram.com/iamkarthik2004/singham
- Repository: https://github.com/iamkarthik2004/singham

## Overview

SINGHAM is a Flask cybersecurity web app for everyday users. The main workflow is to choose a threat dashboard, submit an email, URL, QR image/destination, or file, and receive a verdict with risk indicators and advice. Email analysis extracts PDF text and uses retrieval-augmented reasoning; URL and malware scans extract features, classify them, and provide explanations; QR scanning decodes a destination and checks it as a URL. The sampled code confirms URL and email paths and shared explanation logic. QR and malware flows are documented, but their backend wiring is not shown in the excerpts.

Main entry points: [`backend/app.py`](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py) (Flask routes), [`frontend/templates/email_dashboard.html`](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/email_dashboard.html) (Email dashboard), [`frontend/templates/url_dashboard.html`](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/url_dashboard.html) (URL dashboard), [`frontend/templates/qr_dashboard.html`](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/qr_dashboard.html) (QR dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_flask["Flask routes<br/>[app.py]"]
  node_home["Home dashboard<br/>[home.html]"]
  node_emaildash["Email dashboard"]
  node_urldash["URL dashboard<br/>[url_dashboard.html]"]
  node_qrdash["QR dashboard<br/>[qr_dashboard.html]"]
  node_emailui["Email upload UI<br/>[script.js]"]
  node_urlui["URL scan UI<br/>[app.js]"]
  node_qrui["QR decode and scan<br/>[app.js]"]
end

subgraph group_email["Email analysis"]
  node_pdf["PDF text extraction<br/>[app.py]"]
  node_rag["Email RAG analysis<br/>[app.py]"]
  node_knowledge["Threat knowledge base<br/>[knowledge_base.txt]"]
  node_gemini["Gemini service"]
  node_faiss[("FAISS retrieval")]
end

subgraph group_urlqr["URL and QR analysis"]
  node_urlfeatures["URL feature extraction"]
  node_urlmodel["URL classifier<br/>[app.py]"]
  node_explain["SHAP explanations<br/>[explainability.py]"]
end

subgraph group_malware["Malware and reporting"]
  node_malwareui["Malware scan dashboard"]
  node_malwareresult["Malware result view"]
  node_pefeatures["PE feature extraction"]
  node_malwaremodel["Malware classifier<br/>[app.py]"]
  node_malwareexplain["Malware explanations<br/>[explainability.py]"]
  node_stats[("Scan statistics<br/>[app.py]")]
end

node_user(("User"))

node_user -->|"opens"| node_home
node_flask -->|"renders"| node_home
node_flask -->|"renders"| node_urldash
node_user -->|"selects"| node_emaildash
node_user -->|"selects"| node_qrdash
node_emaildash -->|"uses"| node_emailui
node_emailui -->|"uploads PDF"| node_flask
node_flask -->|"extracts text"| node_pdf
node_flask -->|"invokes analysis"| node_rag
node_rag -->|"retrieves from"| node_knowledge
node_rag -.->|"queries"| node_gemini
node_rag -->|"retrieves with"| node_faiss
node_urldash -->|"uses"| node_urlui
node_urlui -->|"posts URL"| node_flask
node_flask -->|"extracts features"| node_urlfeatures
node_flask -->|"classifies"| node_urlmodel
node_flask -->|"requests SHAP"| node_explain
node_qrdash -->|"uses"| node_qrui
node_qrui -->|"posts decoded URL"| node_flask
node_user -->|"selects"| node_malwareui
node_malwareui -.->|"submits file"| node_flask
node_flask -.->|"extracts PE features"| node_pefeatures
node_flask -.->|"classifies file"| node_malwaremodel
node_flask -.->|"requests explanation"| node_malwareexplain
node_flask -.->|"renders result"| node_malwareresult
node_flask -->|"updates counts"| node_stats

click node_flask "https://github.com/iamkarthik2004/singham/blob/main/backend/app.py"
click node_home "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/home.html"
click node_emaildash "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/email_dashboard.html"
click node_urldash "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/url_dashboard.html"
click node_qrdash "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/qr_dashboard.html"
click node_emailui "https://github.com/iamkarthik2004/singham/blob/main/frontend/static/email/script.js"
click node_urlui "https://github.com/iamkarthik2004/singham/blob/main/frontend/static/url_scam/app.js"
click node_qrui "https://github.com/iamkarthik2004/singham/blob/main/frontend/static/fake_qr/app.js"
click node_pdf "https://github.com/iamkarthik2004/singham/blob/main/backend/app.py"
click node_rag "https://github.com/iamkarthik2004/singham/blob/main/backend/app.py"
click node_knowledge "https://github.com/iamkarthik2004/singham/blob/main/backend/knowledge_base.txt"
click node_urlfeatures "https://github.com/iamkarthik2004/singham/blob/main/backend/featureextraction.py"
click node_urlmodel "https://github.com/iamkarthik2004/singham/blob/main/backend/app.py"
click node_explain "https://github.com/iamkarthik2004/singham/blob/main/backend/explainability.py"
click node_malwareui "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/malware_dashboard.html"
click node_malwareresult "https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/malware_result.html"
click node_pefeatures "https://github.com/iamkarthik2004/singham/blob/main/backend/feature_extraction_malware.py"
click node_malwaremodel "https://github.com/iamkarthik2004/singham/blob/main/backend/app.py"
click node_malwareexplain "https://github.com/iamkarthik2004/singham/blob/main/backend/explainability.py"
click node_stats "https://github.com/iamkarthik2004/singham/blob/main/backend/app.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_flask,node_home,node_emaildash,node_urldash,node_qrdash,node_emailui,node_urlui,node_qrui,node_user toneBlue
class node_pdf,node_rag,node_knowledge,node_gemini,node_faiss toneAmber
class node_urlfeatures,node_urlmodel,node_explain toneMint
class node_malwareui,node_malwareresult,node_pefeatures,node_malwaremodel,node_malwareexplain,node_stats toneRose
```

## Components

### Web experience

- [Flask routes](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`
- [Home dashboard](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/home.html): `frontend/templates/home.html`
- [Email dashboard](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/email_dashboard.html): `frontend/templates/email_dashboard.html`
- [URL dashboard](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/url_dashboard.html): `frontend/templates/url_dashboard.html`
- [QR dashboard](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/qr_dashboard.html): `frontend/templates/qr_dashboard.html`
- [Email upload UI](https://github.com/iamkarthik2004/singham/blob/main/frontend/static/email/script.js): `frontend/static/email/script.js`
- [URL scan UI](https://github.com/iamkarthik2004/singham/blob/main/frontend/static/url_scam/app.js): `frontend/static/url_scam/app.js`
- [QR decode and scan](https://github.com/iamkarthik2004/singham/blob/main/frontend/static/fake_qr/app.js): `frontend/static/fake_qr/app.js`

### Email analysis

- [PDF text extraction](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`
- [Email RAG analysis](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`
- [Threat knowledge base](https://github.com/iamkarthik2004/singham/blob/main/backend/knowledge_base.txt): `backend/knowledge_base.txt`
- **Gemini service**
- **FAISS retrieval**

### URL and QR analysis

- [URL feature extraction](https://github.com/iamkarthik2004/singham/blob/main/backend/featureextraction.py): `backend/featureextraction.py`
- [URL classifier](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`
- [SHAP explanations](https://github.com/iamkarthik2004/singham/blob/main/backend/explainability.py): `backend/explainability.py`

### Malware and reporting

- [Malware scan dashboard](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/malware_dashboard.html): `frontend/templates/malware_dashboard.html`
- [Malware result view](https://github.com/iamkarthik2004/singham/blob/main/frontend/templates/malware_result.html): `frontend/templates/malware_result.html`
- [PE feature extraction](https://github.com/iamkarthik2004/singham/blob/main/backend/feature_extraction_malware.py): `backend/feature_extraction_malware.py`
- [Malware classifier](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`
- [Malware explanations](https://github.com/iamkarthik2004/singham/blob/main/backend/explainability.py): `backend/explainability.py`
- [Scan statistics](https://github.com/iamkarthik2004/singham/blob/main/backend/app.py): `backend/app.py`

### Other components

- **User**

## Connections

- User → Home dashboard: opens (evidence: `README.md`)
- Flask routes → Home dashboard: renders (evidence: `backend/app.py`)
- Flask routes → URL dashboard: renders (evidence: `backend/app.py`)
- User → Email dashboard: selects (evidence: `README.md`)
- User → QR dashboard: selects (evidence: `README.md`)
- Email dashboard → Email upload UI: uses (evidence: `frontend/static/email/script.js`)
- Email upload UI → Flask routes: uploads PDF (evidence: `frontend/static/email/script.js`)
- Flask routes → PDF text extraction: extracts text (evidence: `backend/app.py`)
- Flask routes → Email RAG analysis: invokes analysis (evidence: `backend/app.py`)
- Email RAG analysis → Threat knowledge base: retrieves from (evidence: `backend/app.py`)
- Email RAG analysis → Gemini service: queries (evidence: `README.md`)
- Email RAG analysis → FAISS retrieval: retrieves with (evidence: `backend/app.py`)
- URL dashboard → URL scan UI: uses (evidence: `frontend/static/url_scam/app.js`)
- URL scan UI → Flask routes: posts URL (evidence: `frontend/static/url_scam/app.js`)
- Flask routes → URL feature extraction: extracts features (evidence: `backend/app.py`)
- Flask routes → URL classifier: classifies (evidence: `backend/app.py`)
- Flask routes → SHAP explanations: requests SHAP (evidence: `backend/app.py`)
- QR dashboard → QR decode and scan: uses (evidence: `frontend/static/fake_qr/app.js`)
- QR decode and scan → Flask routes: posts decoded URL (evidence: `frontend/static/fake_qr/app.js`)
- User → Malware scan dashboard: selects (evidence: `README.md`)
- Malware scan dashboard → Flask routes: submits file (evidence: `README.md`)
- Flask routes → PE feature extraction: extracts PE features (evidence: `README.md`)
- Flask routes → Malware classifier: classifies file (evidence: `README.md`)
- Flask routes → Malware explanations: requests explanation (evidence: `README.md`)
- Flask routes → Malware result view: renders result (evidence: `README.md`)
- Flask routes → Scan statistics: updates counts (evidence: `backend/app.py`)
