# charanms0125/upi-shield architecture

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

- Interactive diagram: https://gitdiagram.com/charanms0125/upi-shield
- Repository: https://github.com/charanms0125/upi-shield

## Overview

UPI SHIELD is a UPI scam-detection and incident-response platform. Users sign in, inspect messages, URLs, UPI IDs, QR payloads, or transactions, and receive a risk score with explanations and safety guidance; they can also explore fraud networks, simulate payments, and file incident reports. The backend combines specialized detectors and graph intelligence behind API routes, with SQL/MongoDB persistence. The README documents several capabilities whose implementation was not sampled; those branches are represented without asserting unverified internal calls.

Main entry points: [`backend/app/main.py`](https://github.com/charanms0125/upi-shield/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/services/risk_engine.py`](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/risk_engine.py) (Unified risk fusion), [`frontend/src/App.tsx`](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/App.tsx) (Feature routes), [`backend/app/database/models.py`](https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/models.py) (Domain records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["User experience"]
  node_app["Feature routes<br/>[App.tsx]"]
  node_auth_context["Session context<br/>[AuthContext.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_risk_views["Risk analysis views"]
  node_payment["Payment interceptor"]
  node_network_view["Fraud network view"]
  node_report_view["Incident reporting"]
  node_admin_view["SOC administration<br/>[AdminPage.tsx]"]
end

subgraph group_api["API and identity"]
  node_server["FastAPI application<br/>[main.py]"]
  node_auth_api["Authentication routes<br/>[auth.py]"]
  node_analysis_api["Analysis routes<br/>[analyze.py]"]
  node_dashboard_api["Dashboard routes<br/>[dashboard.py]"]
  node_network_api["Network routes<br/>[network.py]"]
  node_reports_api["Report routes<br/>[reports.py]"]
  node_admin_api["Admin routes<br/>[admin.py]"]
  node_security["Token security<br/>[security.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_detection["Fraud detection"]
  node_risk_engine["Unified risk fusion<br/>[risk_engine.py]"]
  node_message["Message analysis"]
  node_url["URL analysis<br/>[url_analyzer.py]"]
  node_upi["UPI profile analysis<br/>[upi_analyzer.py]"]
  node_qr["QR payload analysis<br/>[qr_analyzer.py]"]
  node_anomaly["Transaction anomaly"]
end

subgraph group_operations["Response and intelligence"]
  node_graph_service["Fraud graph<br/>[graph_service.py]"]
  node_synthetic["Synthetic datasets<br/>[synthetic_data.py]"]
  node_training["Model training<br/>[train_models.py]"]
end

subgraph group_data["Persistence and models"]
  node_store_models["Domain records<br/>[models.py]"]
  node_sql[("SQL database session<br/>[session.py]")]
  node_mongo[("MongoDB manager<br/>[mongodb.py]")]
end

node_user(("UPI user"))

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_risk_views
node_app -->|"routes to"| node_network_view
node_app -->|"routes to"| node_report_view
node_app -->|"routes to"| node_admin_view
node_app -->|"provides"| node_auth_context
node_auth_context -->|"calls auth API"| node_api_client
node_api_client -.->|"requests API"| node_server
node_payment -->|"requests analysis"| node_api_client
node_server -->|"registers routes"| node_auth_api
node_server -->|"registers routes"| node_analysis_api
node_server -->|"registers routes"| node_dashboard_api
node_server -->|"registers routes"| node_network_api
node_server -->|"registers routes"| node_reports_api
node_server -->|"registers routes"| node_admin_api
node_analysis_api -->|"invokes"| node_risk_engine
node_risk_engine -->|"scores message"| node_message
node_risk_engine -->|"scores URL"| node_url
node_risk_engine -->|"scores UPI"| node_upi
node_risk_engine -->|"scores QR"| node_qr
node_risk_engine -->|"scores transaction"| node_anomaly
node_risk_engine -->|"checks graph risk"| node_graph_service
node_qr -->|"validates recipient"| node_upi
node_message -->|"loads model"| node_training
node_anomaly -->|"loads model"| node_training
node_training -->|"trains from"| node_synthetic
node_graph_service -->|"uses generated graph data"| node_synthetic
node_auth_api -->|"hashes credentials"| node_security
node_auth_api -->|"queries users"| node_store_models
node_auth_api -->|"records users"| node_mongo
node_analysis_api -->|"persists analysis"| node_store_models
node_dashboard_api -->|"reads metrics"| node_store_models
node_network_api -.->|"serves graph"| node_graph_service
node_reports_api -.->|"stores reports"| node_store_models
node_admin_api -->|"reads administration data"| node_store_models
node_admin_api -->|"triggers retraining"| node_training
node_sql -->|"reads database URL"| node_config
node_store_models -->|"maps records"| node_sql
node_mongo -->|"reads connection settings"| node_config
node_server -->|"initializes database"| node_sql
node_server -->|"connects and syncs"| node_mongo
node_risk_engine -->|"reads signal weights"| node_config

click node_app "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/App.tsx"
click node_auth_context "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/context/AuthContext.tsx"
click node_api_client "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/services/api.ts"
click node_risk_views "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/AnalyzeMessagePage.tsx"
click node_payment "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/components/SimulatedPaymentModal.tsx"
click node_network_view "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/FraudNetworkPage.tsx"
click node_report_view "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/ReportFraudPage.tsx"
click node_admin_view "https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/AdminPage.tsx"
click node_server "https://github.com/charanms0125/upi-shield/blob/main/backend/app/main.py"
click node_auth_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/auth.py"
click node_analysis_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/analyze.py"
click node_dashboard_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/dashboard.py"
click node_network_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/network.py"
click node_reports_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/reports.py"
click node_admin_api "https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/admin.py"
click node_risk_engine "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/risk_engine.py"
click node_message "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/message_analyzer.py"
click node_url "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/url_analyzer.py"
click node_upi "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/upi_analyzer.py"
click node_qr "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/qr_analyzer.py"
click node_anomaly "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/anomaly_detector.py"
click node_graph_service "https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/graph_service.py"
click node_synthetic "https://github.com/charanms0125/upi-shield/blob/main/backend/app/ml/synthetic_data.py"
click node_training "https://github.com/charanms0125/upi-shield/blob/main/backend/app/ml/train_models.py"
click node_store_models "https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/models.py"
click node_sql "https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/session.py"
click node_mongo "https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/mongodb.py"
click node_security "https://github.com/charanms0125/upi-shield/blob/main/backend/app/core/security.py"
click node_config "https://github.com/charanms0125/upi-shield/blob/main/backend/app/core/config.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_auth_context,node_api_client,node_risk_views,node_payment,node_network_view,node_report_view,node_admin_view,node_user toneBlue
class node_server,node_auth_api,node_analysis_api,node_dashboard_api,node_network_api,node_reports_api,node_admin_api,node_security,node_config toneAmber
class node_risk_engine,node_message,node_url,node_upi,node_qr,node_anomaly toneMint
class node_graph_service,node_synthetic,node_training toneRose
class node_store_models,node_sql,node_mongo toneIndigo
```

## Components

### User experience

- [Feature routes](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session context](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [API client](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Risk analysis views](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/AnalyzeMessagePage.tsx): `frontend/src/pages/AnalyzeMessagePage.tsx`
- [Payment interceptor](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/components/SimulatedPaymentModal.tsx): `frontend/src/components/SimulatedPaymentModal.tsx`
- [Fraud network view](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/FraudNetworkPage.tsx): `frontend/src/pages/FraudNetworkPage.tsx`
- [Incident reporting](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/ReportFraudPage.tsx): `frontend/src/pages/ReportFraudPage.tsx`
- [SOC administration](https://github.com/charanms0125/upi-shield/blob/main/frontend/src/pages/AdminPage.tsx): `frontend/src/pages/AdminPage.tsx`

### API and identity

- [FastAPI application](https://github.com/charanms0125/upi-shield/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Analysis routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/analyze.py): `backend/app/api/analyze.py`
- [Dashboard routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/dashboard.py): `backend/app/api/dashboard.py`
- [Network routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/network.py): `backend/app/api/network.py`
- [Report routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/reports.py): `backend/app/api/reports.py`
- [Admin routes](https://github.com/charanms0125/upi-shield/blob/main/backend/app/api/admin.py): `backend/app/api/admin.py`
- [Token security](https://github.com/charanms0125/upi-shield/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Runtime settings](https://github.com/charanms0125/upi-shield/blob/main/backend/app/core/config.py): `backend/app/core/config.py`

### Fraud detection

- [Unified risk fusion](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/risk_engine.py): `backend/app/services/risk_engine.py`
- [Message analysis](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/message_analyzer.py): `backend/app/services/message_analyzer.py`
- [URL analysis](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/url_analyzer.py): `backend/app/services/url_analyzer.py`
- [UPI profile analysis](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/upi_analyzer.py): `backend/app/services/upi_analyzer.py`
- [QR payload analysis](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/qr_analyzer.py): `backend/app/services/qr_analyzer.py`
- [Transaction anomaly](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/anomaly_detector.py): `backend/app/services/anomaly_detector.py`

### Response and intelligence

- [Fraud graph](https://github.com/charanms0125/upi-shield/blob/main/backend/app/services/graph_service.py): `backend/app/services/graph_service.py`
- [Synthetic datasets](https://github.com/charanms0125/upi-shield/blob/main/backend/app/ml/synthetic_data.py): `backend/app/ml/synthetic_data.py`
- [Model training](https://github.com/charanms0125/upi-shield/blob/main/backend/app/ml/train_models.py): `backend/app/ml/train_models.py`

### Persistence and models

- [Domain records](https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/models.py): `backend/app/database/models.py`
- [SQL database session](https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [MongoDB manager](https://github.com/charanms0125/upi-shield/blob/main/backend/app/database/mongodb.py): `backend/app/database/mongodb.py`

### Other components

- **UPI user**

## Connections

- UPI user → Feature routes: uses (evidence: `README.md`)
- Feature routes → Risk analysis views: routes to (evidence: `frontend/src/App.tsx`)
- Feature routes → Fraud network view: routes to (evidence: `frontend/src/App.tsx`)
- Feature routes → Incident reporting: routes to (evidence: `frontend/src/App.tsx`)
- Feature routes → SOC administration: routes to (evidence: `frontend/src/App.tsx`)
- Feature routes → Session context: provides (evidence: `frontend/src/App.tsx`)
- Session context → API client: calls auth API (evidence: `frontend/src/context/AuthContext.tsx`)
- API client → FastAPI application: requests API
- Payment interceptor → API client: requests analysis (evidence: `frontend/src/components/SimulatedPaymentModal.tsx`)
- FastAPI application → Authentication routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Analysis routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Dashboard routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Network routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Report routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Admin routes: registers routes (evidence: `backend/app/main.py`)
- Analysis routes → Unified risk fusion: invokes (evidence: `backend/app/api/analyze.py`)
- Unified risk fusion → Message analysis: scores message (evidence: `backend/app/services/risk_engine.py`)
- Unified risk fusion → URL analysis: scores URL (evidence: `backend/app/services/risk_engine.py`)
- Unified risk fusion → UPI profile analysis: scores UPI (evidence: `backend/app/services/risk_engine.py`)
- Unified risk fusion → QR payload analysis: scores QR (evidence: `backend/app/services/risk_engine.py`)
- Unified risk fusion → Transaction anomaly: scores transaction (evidence: `backend/app/services/risk_engine.py`)
- Unified risk fusion → Fraud graph: checks graph risk (evidence: `backend/app/services/risk_engine.py`)
- QR payload analysis → UPI profile analysis: validates recipient (evidence: `backend/app/services/qr_analyzer.py`)
- Message analysis → Model training: loads model (evidence: `backend/app/services/message_analyzer.py`)
- Transaction anomaly → Model training: loads model (evidence: `backend/app/services/anomaly_detector.py`)
- Model training → Synthetic datasets: trains from (evidence: `backend/app/ml/train_models.py`)
- Fraud graph → Synthetic datasets: uses generated graph data (evidence: `backend/app/services/graph_service.py`)
- Authentication routes → Token security: hashes credentials (evidence: `backend/app/api/auth.py`)
- Authentication routes → Domain records: queries users (evidence: `backend/app/api/auth.py`)
- Authentication routes → MongoDB manager: records users (evidence: `backend/app/api/auth.py`)
- Analysis routes → Domain records: persists analysis (evidence: `backend/app/api/analyze.py`)
- Dashboard routes → Domain records: reads metrics (evidence: `backend/app/api/dashboard.py`)
- Network routes → Fraud graph: serves graph
- Report routes → Domain records: stores reports
- Admin routes → Domain records: reads administration data (evidence: `backend/app/api/admin.py`)
- Admin routes → Model training: triggers retraining (evidence: `backend/app/api/admin.py`)
- SQL database session → Runtime settings: reads database URL (evidence: `backend/app/database/session.py`)
- Domain records → SQL database session: maps records (evidence: `backend/app/database/models.py`)
- MongoDB manager → Runtime settings: reads connection settings (evidence: `backend/app/database/mongodb.py`)
- FastAPI application → SQL database session: initializes database (evidence: `backend/app/main.py`)
- FastAPI application → MongoDB manager: connects and syncs (evidence: `backend/app/main.py`)
- Unified risk fusion → Runtime settings: reads signal weights (evidence: `backend/app/services/risk_engine.py`)
