# shyam062006/fraud-shield architecture

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

- Interactive diagram: https://gitdiagram.com/shyam062006/fraud-shield
- Repository: https://github.com/shyam062006/fraud-shield

## Overview

FRAUD SHIELD scores payment transactions and returns a verdict with model-grounded explanations. The main workflow runs from operator input in the browser, through the injected bridge and validated API request, to feature engineering, model inference, and explanation generation; the bridge then renders the result. The README also describes model benchmarking and the model-info endpoint. Source excerpts show the prediction path and API/UI wiring; training details beyond the documented benchmark are not inspected.

Main entry points: [`backend/app/main.py`](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/main.py) (FastAPI Service), [`backend/app/model_service.py`](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/model_service.py) (Model Inference and Attribution), [`backend/static/bridge.js`](https://github.com/shyam062006/fraud-shield/blob/main/backend/static/bridge.js) (Runtime Bridge), [`frontend/index.html`](https://github.com/shyam062006/fraud-shield/blob/main/frontend/index.html) (Fraud UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Transaction UI"]
  node_ui["Fraud UI<br/>[index.html]"]
  node_bridge["Runtime Bridge<br/>[bridge.js]"]
end

subgraph group_api["API and Contracts"]
  node_api_service["FastAPI Service<br/>[main.py]"]
  node_contracts["Request and Response Schemas<br/>[schemas.py]"]
  node_settings["Runtime Settings<br/>[config.py]"]
end

subgraph group_inference["Fraud Analysis"]
  node_feature_engineering["Feature Engineering<br/>[features.py]"]
  node_model_service["Model Inference and Attribution<br/>[model_service.py]"]
  node_explanations["Risk Explanations<br/>[explain.py]"]
end

subgraph group_model["Model Assets and Evaluation"]
  node_model_artifact["Random Forest Artifact<br/>[model.pkl]"]
  node_scaler_artifact["Scaler Artifact<br/>[scaler.pkl]"]
  node_metrics["Benchmark Metrics<br/>[metrics.json]"]
  node_training_benchmark["Training and Benchmark"]
end

node_operator(("Transaction Operator"))

node_operator -->|"enters transaction"| node_ui
node_ui -->|"receives injection"| node_bridge
node_bridge -->|"posts prediction"| node_api_service
node_api_service -->|"validates and responds"| node_contracts
node_api_service -->|"extracts features"| node_feature_engineering
node_api_service -->|"requests inference"| node_model_service
node_api_service -->|"generates reasons"| node_explanations
node_model_service -->|"uses feature names"| node_feature_engineering
node_model_service -->|"resolves artifact paths"| node_settings
node_model_service -->|"loads model"| node_model_artifact
node_model_service -->|"loads scaler"| node_scaler_artifact
node_api_service -->|"reads runtime settings"| node_settings
node_api_service -->|"reads metrics"| node_metrics
node_bridge -->|"renders prediction"| node_ui
node_training_benchmark -.->|"produces production model"| node_model_artifact
node_training_benchmark -.->|"produces scaler"| node_scaler_artifact

click node_ui "https://github.com/shyam062006/fraud-shield/blob/main/frontend/index.html"
click node_bridge "https://github.com/shyam062006/fraud-shield/blob/main/backend/static/bridge.js"
click node_api_service "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/main.py"
click node_contracts "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/schemas.py"
click node_settings "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/config.py"
click node_feature_engineering "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/features.py"
click node_model_service "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/model_service.py"
click node_explanations "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/explain.py"
click node_model_artifact "https://github.com/shyam062006/fraud-shield/blob/main/ML/model.pkl"
click node_scaler_artifact "https://github.com/shyam062006/fraud-shield/blob/main/ML/scaler.pkl"
click node_metrics "https://github.com/shyam062006/fraud-shield/blob/main/backend/app/metrics.json"
click node_training_benchmark "https://github.com/shyam062006/fraud-shield/blob/main/ML/train_final_model.ipynb"

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_ui,node_bridge toneBlue
class node_api_service,node_contracts,node_settings toneAmber
class node_feature_engineering,node_model_service,node_explanations toneMint
class node_model_artifact,node_scaler_artifact,node_metrics,node_training_benchmark toneRose
class node_operator toneIndigo
```

## Components

### Transaction UI

- [Fraud UI](https://github.com/shyam062006/fraud-shield/blob/main/frontend/index.html): `frontend/index.html`
- [Runtime Bridge](https://github.com/shyam062006/fraud-shield/blob/main/backend/static/bridge.js): `backend/static/bridge.js`

### API and Contracts

- [FastAPI Service](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/main.py): `backend/app/main.py`
- [Request and Response Schemas](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [Runtime Settings](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/config.py): `backend/app/config.py`

### Fraud Analysis

- [Feature Engineering](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/features.py): `backend/app/features.py`
- [Model Inference and Attribution](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/model_service.py): `backend/app/model_service.py`
- [Risk Explanations](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/explain.py): `backend/app/explain.py`

### Model Assets and Evaluation

- [Random Forest Artifact](https://github.com/shyam062006/fraud-shield/blob/main/ML/model.pkl): `ML/model.pkl`
- [Scaler Artifact](https://github.com/shyam062006/fraud-shield/blob/main/ML/scaler.pkl): `ML/scaler.pkl`
- [Benchmark Metrics](https://github.com/shyam062006/fraud-shield/blob/main/backend/app/metrics.json): `backend/app/metrics.json`
- [Training and Benchmark](https://github.com/shyam062006/fraud-shield/blob/main/ML/train_final_model.ipynb): `ML/train_final_model.ipynb`

### Other components

- **Transaction Operator**

## Connections

- Transaction Operator → Fraud UI: enters transaction (evidence: `README.md`)
- Fraud UI → Runtime Bridge: receives injection
- Runtime Bridge → FastAPI Service: posts prediction (evidence: `backend/static/bridge.js`)
- FastAPI Service → Request and Response Schemas: validates and responds (evidence: `backend/app/main.py`)
- FastAPI Service → Feature Engineering: extracts features (evidence: `backend/app/main.py`)
- FastAPI Service → Model Inference and Attribution: requests inference (evidence: `backend/app/main.py`)
- FastAPI Service → Risk Explanations: generates reasons (evidence: `backend/app/main.py`)
- Model Inference and Attribution → Feature Engineering: uses feature names (evidence: `backend/app/model_service.py`)
- Model Inference and Attribution → Runtime Settings: resolves artifact paths (evidence: `backend/app/model_service.py`)
- Model Inference and Attribution → Random Forest Artifact: loads model (evidence: `backend/app/model_service.py`)
- Model Inference and Attribution → Scaler Artifact: loads scaler (evidence: `backend/app/model_service.py`)
- FastAPI Service → Runtime Settings: reads runtime settings (evidence: `backend/app/main.py`)
- FastAPI Service → Benchmark Metrics: reads metrics (evidence: `backend/app/main.py`)
- Runtime Bridge → Fraud UI: renders prediction (evidence: `backend/static/bridge.js`)
- Training and Benchmark → Random Forest Artifact: produces production model (evidence: `README.md`)
- Training and Benchmark → Scaler Artifact: produces scaler (evidence: `README.md`)
