# codewithrishabh09/scamshield architecture

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

- Interactive diagram: https://gitdiagram.com/codewithrishabh09/scamshield
- Repository: https://github.com/codewithrishabh09/scamshield

## Overview

ScamShield is a backend API for detecting scams in digital-payment-related text and returning risk insights. The principal workflow accepts a scan, analyzes its text with rule, URL, and optional ML signals, scores and explains the findings, then persists results. The repository also includes authentication, feedback, dashboard, threat-pattern, recommendation, and audit capabilities. Several service modules were not excerpted; their presence is reflected where appropriate, but uncertain call relationships are omitted. Edges use excerpted code, SOURCE INDEX references, or the README.

Main entry points: [`backend/app/services/analysis.py`](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/analysis.py) (Scan analysis orchestrator), [`backend/app/api/v1/router.py`](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/router.py) (Versioned router), [`backend/app/api/v1/scans.py`](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/scans.py) (Scan endpoints), [`backend/app/services/auth.py`](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/auth.py) (Account service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entrypoints"]
  node_app["FastAPI application<br/>[main.py]"]
  node_api_router["Versioned router<br/>[router.py]"]
  node_scan_api["Scan endpoints<br/>[scans.py]"]
  node_auth_api["Authentication endpoints<br/>[auth.py]"]
  node_feedback_api["Feedback endpoints<br/>[feedback.py]"]
end

subgraph group_identity["Identity and feedback"]
  node_auth_service["Account service<br/>[auth.py]"]
  node_security["Token and password security<br/>[security.py]"]
  node_feedback_service["Feedback service<br/>[feedback.py]"]
  node_user_model["User records<br/>[user.py]"]
end

subgraph group_analysis["Scan analysis"]
  node_analysis_service["Scan analysis orchestrator<br/>[analysis.py]"]
  node_rule_detector["Rule detector<br/>[rule_detector.py]"]
  node_url_analyzer["URL analysis service<br/>[url_analyzer.py]"]
  node_url_detector["URL detector<br/>[url_detector.py]"]
  node_ml_classifier["Text classifier<br/>[ml_classifier.py]"]
  node_finding_model["Finding contract<br/>[base.py]"]
end

subgraph group_risk["Risk intelligence"]
  node_risk_engine["Risk calculation<br/>[engine.py]"]
  node_risk_scoring["Risk scoring<br/>[scoring.py]"]
  node_risk_explanation["Risk explanation<br/>[explainability.py]"]
  node_explanation_service["Finding explanations<br/>[explanation.py]"]
  node_recommendation["Recommendations<br/>[recommendation.py]"]
end

subgraph group_data["Persistence and insights"]
  node_scan_service["Scan lifecycle service<br/>[scan.py]"]
  node_threat_patterns["Threat-pattern service<br/>[threat_patterns.py]"]
  node_dashboard["Dashboard service<br/>[dashboard.py]"]
  node_audit["Audit service<br/>[audit.py]"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_database[("Relational database")]
  node_scan_models["Scan and analysis records"]
end

node_user_actor(("API client"))

node_user_actor -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_api_router
node_api_router -->|"registers"| node_scan_api
node_api_router -->|"registers"| node_auth_api
node_api_router -->|"registers"| node_feedback_api
node_scan_api -->|"invokes analysis"| node_analysis_service
node_scan_api -->|"uses lifecycle"| node_scan_service
node_auth_api -->|"invokes"| node_auth_service
node_auth_service -->|"uses credentials"| node_security
node_auth_service -->|"reads and writes"| node_user_model
node_feedback_api -->|"invokes"| node_feedback_service
node_analysis_service -->|"detects patterns"| node_rule_detector
node_analysis_service -->|"analyzes URLs"| node_url_analyzer
node_url_analyzer -->|"delegates detection"| node_url_detector
node_analysis_service -->|"classifies text"| node_ml_classifier
node_analysis_service -->|"calculates risk"| node_risk_engine
node_risk_engine -->|"scores findings"| node_risk_scoring
node_analysis_service -->|"builds risk explanation"| node_risk_explanation
node_analysis_service -->|"builds explanations"| node_explanation_service
node_risk_explanation -->|"uses recommendations"| node_recommendation
node_analysis_service -->|"persists results"| node_scan_models
node_analysis_service -->|"commits analysis"| node_database
node_db_session -->|"opens sessions"| node_database
node_rule_detector -->|"produces findings"| node_finding_model
node_analysis_service -->|"deduplicates findings"| node_finding_model

click node_app "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/main.py"
click node_api_router "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/router.py"
click node_scan_api "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/scans.py"
click node_auth_api "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/auth.py"
click node_feedback_api "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/feedback.py"
click node_auth_service "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/auth.py"
click node_security "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/core/security.py"
click node_feedback_service "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/feedback.py"
click node_analysis_service "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/analysis.py"
click node_rule_detector "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/rule_detector.py"
click node_url_analyzer "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/url_analyzer.py"
click node_url_detector "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/url_detector.py"
click node_ml_classifier "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/ml_classifier.py"
click node_finding_model "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/base.py"
click node_risk_engine "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/engine.py"
click node_risk_scoring "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/scoring.py"
click node_risk_explanation "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/explainability.py"
click node_explanation_service "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/explanation.py"
click node_recommendation "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/recommendation.py"
click node_scan_service "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/scan.py"
click node_threat_patterns "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/threat_patterns.py"
click node_dashboard "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/dashboard.py"
click node_audit "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/audit.py"
click node_db_session "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/db/session.py"
click node_scan_models "https://github.com/codewithrishabh09/scamshield/tree/main/backend/app/models"
click node_user_model "https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/models/user.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_app,node_api_router,node_scan_api,node_auth_api,node_feedback_api,node_user_actor toneBlue
class node_auth_service,node_security,node_feedback_service,node_user_model toneAmber
class node_analysis_service,node_rule_detector,node_url_analyzer,node_url_detector,node_ml_classifier,node_finding_model toneMint
class node_risk_engine,node_risk_scoring,node_risk_explanation,node_explanation_service,node_recommendation toneRose
class node_scan_service,node_threat_patterns,node_dashboard,node_audit,node_db_session,node_database,node_scan_models toneIndigo
```

## Components

### API entrypoints

- [FastAPI application](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/main.py): `backend/app/main.py`
- [Versioned router](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/router.py): `backend/app/api/v1/router.py`
- [Scan endpoints](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/scans.py): `backend/app/api/v1/scans.py`
- [Authentication endpoints](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/auth.py): `backend/app/api/v1/auth.py`
- [Feedback endpoints](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/api/v1/feedback.py): `backend/app/api/v1/feedback.py`

### Identity and feedback

- [Account service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/auth.py): `backend/app/services/auth.py`
- [Token and password security](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Feedback service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/feedback.py): `backend/app/services/feedback.py`
- [User records](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/models/user.py): `backend/app/models/user.py`

### Scan analysis

- [Scan analysis orchestrator](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/analysis.py): `backend/app/services/analysis.py`
- [Rule detector](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/rule_detector.py): `backend/app/detectors/rule_detector.py`
- [URL analysis service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/url_analyzer.py): `backend/app/services/url_analyzer.py`
- [URL detector](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/url_detector.py): `backend/app/detectors/url_detector.py`
- [Text classifier](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/ml_classifier.py): `backend/app/services/ml_classifier.py`
- [Finding contract](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/detectors/base.py): `backend/app/detectors/base.py`

### Risk intelligence

- [Risk calculation](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/engine.py): `backend/app/risk/engine.py`
- [Risk scoring](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/scoring.py): `backend/app/risk/scoring.py`
- [Risk explanation](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/explainability.py): `backend/app/risk/explainability.py`
- [Finding explanations](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/explanation.py): `backend/app/services/explanation.py`
- [Recommendations](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/risk/recommendation.py): `backend/app/risk/recommendation.py`

### Persistence and insights

- [Scan lifecycle service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/scan.py): `backend/app/services/scan.py`
- [Threat-pattern service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/threat_patterns.py): `backend/app/services/threat_patterns.py`
- [Dashboard service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/dashboard.py): `backend/app/services/dashboard.py`
- [Audit service](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/services/audit.py): `backend/app/services/audit.py`
- [Database sessions](https://github.com/codewithrishabh09/scamshield/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- **Relational database**
- [Scan and analysis records](https://github.com/codewithrishabh09/scamshield/tree/main/backend/app/models): `backend/app/models`

### Other components

- **API client**

## Connections

- API client → FastAPI application: sends requests (evidence: `backend/app/main.py`)
- FastAPI application → Versioned router: mounts routes (evidence: `backend/app/main.py`)
- Versioned router → Scan endpoints: registers (evidence: `backend/app/api/v1/router.py`)
- Versioned router → Authentication endpoints: registers (evidence: `backend/app/api/v1/router.py`)
- Versioned router → Feedback endpoints: registers (evidence: `backend/app/api/v1/router.py`)
- Scan endpoints → Scan analysis orchestrator: invokes analysis (evidence: `backend/app/api/v1/scans.py`)
- Scan endpoints → Scan lifecycle service: uses lifecycle (evidence: `backend/app/api/v1/scans.py`)
- Authentication endpoints → Account service: invokes (evidence: `backend/app/api/v1/auth.py`)
- Account service → Token and password security: uses credentials (evidence: `backend/app/services/auth.py`)
- Account service → User records: reads and writes (evidence: `backend/app/services/auth.py`)
- Feedback endpoints → Feedback service: invokes (evidence: `backend/app/api/v1/feedback.py`)
- Scan analysis orchestrator → Rule detector: detects patterns (evidence: `backend/app/services/analysis.py`)
- Scan analysis orchestrator → URL analysis service: analyzes URLs (evidence: `backend/app/services/analysis.py`)
- URL analysis service → URL detector: delegates detection (evidence: `backend/app/services/url_analyzer.py`)
- Scan analysis orchestrator → Text classifier: classifies text (evidence: `backend/app/services/analysis.py`)
- Scan analysis orchestrator → Risk calculation: calculates risk (evidence: `backend/app/services/analysis.py`)
- Risk calculation → Risk scoring: scores findings (evidence: `backend/app/risk/engine.py`)
- Scan analysis orchestrator → Risk explanation: builds risk explanation (evidence: `backend/app/services/analysis.py`)
- Scan analysis orchestrator → Finding explanations: builds explanations (evidence: `backend/app/services/analysis.py`)
- Risk explanation → Recommendations: uses recommendations (evidence: `backend/app/risk/explainability.py`)
- Scan analysis orchestrator → Scan and analysis records: persists results (evidence: `backend/app/services/analysis.py`)
- Scan analysis orchestrator → Relational database: commits analysis (evidence: `backend/app/services/analysis.py`)
- Database sessions → Relational database: opens sessions (evidence: `backend/app/db/session.py`)
- Rule detector → Finding contract: produces findings (evidence: `backend/app/detectors/rule_detector.py`)
- Scan analysis orchestrator → Finding contract: deduplicates findings (evidence: `backend/app/services/analysis.py`)
