# nethmipamosha/scamlens architecture

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

- Interactive diagram: https://gitdiagram.com/nethmipamosha/scamlens
- Repository: https://github.com/nethmipamosha/scamlens

## Overview

ScamLens is a Streamlit decision-support application that classifies SMS as Legitimate, Spam, or Scam and explains the result. The main workflow runs from message entry through text preprocessing, three-class prediction, tactic detection, and calibrated risk scoring, then presents word-level explanations and safety guidance. Users can also test edited messages, check prediction stability, revisit session history, and explore model insights. The README documents product capabilities; source excerpts show key model and helper implementations, but not every dashboard interaction.

Main entry points: [`code/app.py`](https://github.com/nethmipamosha/scamlens/blob/main/code/app.py) (Streamlit dashboard), [`code/src/model.py`](https://github.com/nethmipamosha/scamlens/blob/main/code/src/model.py) (Risk combiner), [`code/src/train.py`](https://github.com/nethmipamosha/scamlens/blob/main/code/src/train.py) (Model training), [`code/src/preprocess.py`](https://github.com/nethmipamosha/scamlens/blob/main/code/src/preprocess.py) (Text preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User experience"]
  node_dashboard["Streamlit dashboard<br/>[app.py]"]
  node_history[("Session history<br/>[app.py]")]
  node_insights["Model insights<br/>[app.py]"]
end

subgraph group_analysis["Message analysis"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
  node_classifier["Three-class classifier<br/>[model.py]"]
  node_risk["Risk combiner<br/>[model.py]"]
  node_tactics["Tactic detection<br/>[tactics.py]"]
end

subgraph group_modeling["Model lifecycle"]
  node_training["Model training<br/>[train.py]"]
  node_dataset[("SMS dataset<br/>[sms_phishing.csv]")]
end

subgraph group_explanations["Explanations and robustness"]
  node_explain["Word explanations<br/>[explain.py]"]
  node_safety["Safety guidance<br/>[tactics.py]"]
  node_whatif["What-if analysis<br/>[app.py]"]
  node_stability["Stability testing<br/>[stability.py]"]
end

node_user(("Message sender"))
node_analyst(("Message analyst"))

node_user -->|"enters message"| node_dashboard
node_dashboard -->|"preprocesses text"| node_preprocess
node_preprocess -->|"extracts TF-IDF"| node_classifier
node_dashboard -->|"requests prediction"| node_classifier
node_dashboard -->|"detects tactics"| node_tactics
node_dashboard -->|"requests risk score"| node_risk
node_classifier -->|"supplies class scores"| node_risk
node_risk -->|"returns risk result"| node_dashboard
node_dashboard -->|"generates explanations"| node_explain
node_explain -->|"formats tokens"| node_preprocess
node_dashboard -->|"shows safety tips"| node_safety
node_dashboard -->|"tests edits"| node_whatif
node_whatif -->|"compares risk scores"| node_risk
node_dashboard -->|"checks robustness"| node_stability
node_stability -->|"scores variants"| node_risk
node_dashboard -->|"stores session results"| node_history
node_history -->|"reopens message"| node_dashboard
node_dashboard -->|"presents metrics"| node_insights
node_analyst -->|"explores metrics"| node_insights
node_dataset -->|"provides examples"| node_training
node_training -->|"cleans training text"| node_preprocess
node_training -->|"fits classifier"| node_classifier
node_training -->|"fits combiner"| node_risk
node_training -->|"generates evaluation data"| node_insights

click node_dashboard "https://github.com/nethmipamosha/scamlens/blob/main/code/app.py"
click node_history "https://github.com/nethmipamosha/scamlens/blob/main/code/app.py"
click node_insights "https://github.com/nethmipamosha/scamlens/blob/main/code/app.py"
click node_preprocess "https://github.com/nethmipamosha/scamlens/blob/main/code/src/preprocess.py"
click node_classifier "https://github.com/nethmipamosha/scamlens/blob/main/code/src/model.py"
click node_risk "https://github.com/nethmipamosha/scamlens/blob/main/code/src/model.py"
click node_tactics "https://github.com/nethmipamosha/scamlens/blob/main/code/src/tactics.py"
click node_explain "https://github.com/nethmipamosha/scamlens/blob/main/code/src/explain.py"
click node_safety "https://github.com/nethmipamosha/scamlens/blob/main/code/src/tactics.py"
click node_whatif "https://github.com/nethmipamosha/scamlens/blob/main/code/app.py"
click node_stability "https://github.com/nethmipamosha/scamlens/blob/main/code/src/stability.py"
click node_training "https://github.com/nethmipamosha/scamlens/blob/main/code/src/train.py"
click node_dataset "https://github.com/nethmipamosha/scamlens/blob/main/code/data/sms_phishing.csv"

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_dashboard,node_history,node_insights toneBlue
class node_preprocess,node_classifier,node_risk,node_tactics toneAmber
class node_training,node_dataset toneMint
class node_explain,node_safety,node_whatif,node_stability toneRose
class node_user,node_analyst toneIndigo
```

## Components

### User experience

- [Streamlit dashboard](https://github.com/nethmipamosha/scamlens/blob/main/code/app.py): `code/app.py`
- [Session history](https://github.com/nethmipamosha/scamlens/blob/main/code/app.py): `code/app.py`
- [Model insights](https://github.com/nethmipamosha/scamlens/blob/main/code/app.py): `code/app.py`

### Message analysis

- [Text preprocessing](https://github.com/nethmipamosha/scamlens/blob/main/code/src/preprocess.py): `code/src/preprocess.py`
- [Three-class classifier](https://github.com/nethmipamosha/scamlens/blob/main/code/src/model.py): `code/src/model.py`
- [Risk combiner](https://github.com/nethmipamosha/scamlens/blob/main/code/src/model.py): `code/src/model.py`
- [Tactic detection](https://github.com/nethmipamosha/scamlens/blob/main/code/src/tactics.py): `code/src/tactics.py`

### Model lifecycle

- [Model training](https://github.com/nethmipamosha/scamlens/blob/main/code/src/train.py): `code/src/train.py`
- [SMS dataset](https://github.com/nethmipamosha/scamlens/blob/main/code/data/sms_phishing.csv): `code/data/sms_phishing.csv`

### Explanations and robustness

- [Word explanations](https://github.com/nethmipamosha/scamlens/blob/main/code/src/explain.py): `code/src/explain.py`
- [Safety guidance](https://github.com/nethmipamosha/scamlens/blob/main/code/src/tactics.py): `code/src/tactics.py`
- [What-if analysis](https://github.com/nethmipamosha/scamlens/blob/main/code/app.py): `code/app.py`
- [Stability testing](https://github.com/nethmipamosha/scamlens/blob/main/code/src/stability.py): `code/src/stability.py`

### Other components

- **Message sender**
- **Message analyst**

## Connections

- Message sender → Streamlit dashboard: enters message (evidence: `README.md`)
- Streamlit dashboard → Text preprocessing: preprocesses text (evidence: `README.md`)
- Text preprocessing → Three-class classifier: extracts TF-IDF (evidence: `README.md`)
- Streamlit dashboard → Three-class classifier: requests prediction (evidence: `README.md`)
- Streamlit dashboard → Tactic detection: detects tactics (evidence: `code/app.py`)
- Streamlit dashboard → Risk combiner: requests risk score (evidence: `README.md`)
- Three-class classifier → Risk combiner: supplies class scores (evidence: `code/src/model.py`)
- Risk combiner → Streamlit dashboard: returns risk result (evidence: `README.md`)
- Streamlit dashboard → Word explanations: generates explanations (evidence: `code/app.py`)
- Word explanations → Text preprocessing: formats tokens (evidence: `code/src/explain.py`)
- Streamlit dashboard → Safety guidance: shows safety tips (evidence: `code/app.py`)
- Streamlit dashboard → What-if analysis: tests edits (evidence: `README.md`)
- What-if analysis → Risk combiner: compares risk scores (evidence: `README.md`)
- Streamlit dashboard → Stability testing: checks robustness (evidence: `code/app.py`)
- Stability testing → Risk combiner: scores variants (evidence: `code/src/stability.py`)
- Streamlit dashboard → Session history: stores session results (evidence: `README.md`)
- Session history → Streamlit dashboard: reopens message (evidence: `code/app.py`)
- Streamlit dashboard → Model insights: presents metrics (evidence: `README.md`)
- Message analyst → Model insights: explores metrics (evidence: `README.md`)
- SMS dataset → Model training: provides examples (evidence: `code/src/train.py`)
- Model training → Text preprocessing: cleans training text (evidence: `code/src/train.py`)
- Model training → Three-class classifier: fits classifier (evidence: `code/src/train.py`)
- Model training → Risk combiner: fits combiner (evidence: `code/src/train.py`)
- Model training → Model insights: generates evaluation data (evidence: `README.md`)
