# shalani98/fraud-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/shalani98/fraud-detection-system
- Repository: https://github.com/shalani98/fraud-detection-system

## Overview

##### What this project is (type + purpose)
This is a **full-stack fraud detection web app**:

- **Frontend:** React (Vite-based) UI that collects credit card feature inputs and calls an API.
- **Backend:** Flask API that **loads a pre-trained scikit-learn model from `fraud_model.pkl`** and returns a fraud prediction.
- **Data:** `data/creditcard.csv` is the dataset used for training/validation (in this repo it’s more “artifact/reference data” than a runtime dependency).
- **Deployment target:** **AWS EC2** running the built frontend + Flask API.

##### Frontend (React/Vite)
- `frontend/src/*` (runtime UI code)
- `frontend/src/pages/Web.jsx` likely the main page that submits input
- `frontend/src/App.jsx`, `main.jsx` entry points
- `frontend/dist/*` (production build artifacts: static HTML/CSS/JS)
- `frontend/dist/index.html`
- `frontend/dist/assets/index-*.js`, `index-*.css`
- `frontend/package.json`, `vite.config.js` (build + dev tooling)

##### Backend (Flask + ML inference)
- `backend/app.py` (Flask server + API routes; loads model)
- `backend/fraud_model.pkl` (model artifact used at runtime)
- `backend/requirements.txt` (dependencies: Flask, scikit-learn, etc.)

##### Data
- `data/creditcard.csv` (dataset; not necessarily used at runtime)

##### Deployment (EC2)
README states “production-ready code deployed on AWS EC2”.
- Flask backend process
- Static frontend (either served by a separate static server or potentially by Flask / a web server)

##### User Browser → Frontend (React SPA)
- Browser loads static assets (HTML/CSS/JS)

##### Frontend (React) → Backend API (Flask)
- HTTP requests (likely JSON)
- Endpoint conceptually as: `POST /predict` (or similar; confirm by reading `backend/app.py`)

##### Backend API (Flask) → Model Artifact (`fraud_model.pkl`)
- On startup or first request: “load pickle”
- On request: “run `model.predict(...)` / `predict_proba(...)`”

##### Backend API → Frontend
- Response: prediction result (fraud / not fraud, probability, etc.)

Optional but accurate additions:
- **Training pipeline (offline):** `creditcard.csv` → training script (not present in tree) → `fraud_model.pkl`
- As a separate lane (“Offline training”) even if training code isn’t included, because the artifact exists and must come from somewhere.

##### Architectural patterns to highlight (based on structure)
- **SPA + REST API** separation (clear frontend/backend split)
- **Artifact-based ML inference** (pickle file shipped with the backend)
- **Single-node deployment** (EC2 hosting both layers) unless you split them in production
- **Build step** (Vite builds `src` → `dist`)

- “Build-time components” vs “Run-time components”
- “Offline ML lifecycle” vs “Online inference”

Use labels that tie directly to the repo to avoid hand-wavy architecture:

- “React UI (`frontend/src`, built to `frontend/dist` via Vite)”
- “Flask API (`backend/app.py`)”
- “scikit-learn model (`backend/fraud_model.pkl`)”
- “Dataset (offline): `data/creditcard.csv`”
- “AWS EC2 instance (production host)”

- “HTTP(S) JSON: feature vector → prediction”
- “Returns: fraud flag / probability”

##### “Don’t overthink it” but still be very detailed: component checklist
To “separate into as many components as possible” (without inventing things), include:

Runtime:
- Browser
- Static asset hosting (dist)
- Flask web server
- Prediction endpoint handler (inside Flask)
- Feature preprocessing step (if present in `app.py`; verify)
- Model loader
- Model inference

Offline/Build:
- React source → build → dist
- Dataset → training → pickle

Deployment:
- EC2 as the hosting boundary

## Diagram (Mermaid)

```mermaid
flowchart TD

%% =========================
%% Diagram A — Runtime / Production Architecture
%% =========================
subgraph "Diagram A — Runtime / Production (Most Important)"
direction TB

subgraph "Client"
direction TB
U["User"]:::external
B["Web Browser"]:::external
U -->|"uses"| B
end

subgraph "AWS EC2 Instance (Deployment Boundary)"
direction TB

RP["Reverse Proxy / Web Server (Optional: Nginx/Apache)"]:::optional

subgraph "Frontend (Static SPA)"
direction TB
FE_STATIC["Static Web Assets (Vite build output)"]:::frontend
FE_INDEX["index.html"]:::artifact
FE_BUNDLE["Bundled JS/CSS (assets)"]:::artifact
FE_STATIC -->|"serves"| FE_INDEX
FE_STATIC -->|"serves"| FE_BUNDLE
end

subgraph "Backend (Flask + ML Inference)"
direction TB
API["Flask API Service"]:::backend

subgraph "API Internals"
direction TB
PRED_EP["Prediction Endpoint Handler (e.g., POST /predict)"]:::backend
PREP["Feature Parsing/Preprocessing (if present)"]:::backend
MODEL_LOADER["Model Loader (pickle load)"]:::ml
INFER["Model Inference (predict/predict_proba)"]:::ml

API -->|"routes"| PRED_EP
PRED_EP -->|"parse_request"| PREP
PREP -->|"ensure_feature_vector"| MODEL_LOADER
MODEL_LOADER -->|"provides_estimator"| INFER
end

MODEL["fraud_model.pkl (scikit-learn estimator)"]:::mlartifact
MODEL_LOADER -->|"loads"| MODEL
INFER -->|"uses"| MODEL
end

end

B -->|"GET / (HTML)"| RP
B -->|"GET /assets/* (JS/CSS)"| RP
RP -->|"serve_static"| FE_STATIC

B -->|"HTTP(S) JSON:features->prediction"| RP
RP -->|"proxy_/api_or_/predict"| API
API -->|"JSON:fraud_flag/probability"| RP
RP -->|"HTTP_response"| B

end

%% =========================
%% Diagram B — Build/Dev + ML Lifecycle
%% =========================
subgraph "Diagram B — Build/Dev + ML Lifecycle"
direction TB

subgraph "Developer Machine / CI"
direction TB
DEV["Developer"]:::external
DEV_B["Dev Browser"]:::external
DEV -->|"runs/tests"| DEV_B

subgraph "Frontend Dev & Build"
direction TB
FE_SRC["React Frontend Source (Vite/React)"]:::frontend
FE_PAGE["Main UI Page (form + submit)"]:::frontend
FE_APP["React App Root"]:::frontend
FE_MAIN["React Entry Point (bootstrap)"]:::frontend
FE_STYLE["Styling (App + global CSS)"]:::frontend
VITE_CFG["Vite/Node Tooling & Config"]:::build
BUILD["Build Step (npm run build)"]:::build
DIST["Production Build Output (dist)"]:::artifact

FE_SRC -->|"contains"| FE_PAGE
FE_SRC -->|"contains"| FE_APP
FE_SRC -->|"contains"| FE_MAIN
FE_SRC -->|"contains"| FE_STYLE
VITE_CFG -->|"configures"| BUILD
FE_SRC -->|"input"| BUILD
BUILD -->|"outputs"| DIST
end

subgraph "Backend Dev"
direction TB
API_DEV["Flask Dev Server"]:::backend
REQ["Python Dependencies (requirements.txt)"]:::build
REQ -->|"install"| API_DEV
end

DEV_B -->|"dev_HTTP_calls"| API_DEV
DEV_B -->|"hot_reload_UI"| FE_SRC

end

subgraph "Offline ML (Training Lifecycle)"
direction TB
DATASET["Dataset (offline reference): creditcard.csv"]:::data
TRAIN["Training/Validation (not in repo)"]:::offline
MODEL_OUT["Model Artifact Output: fraud_model.pkl"]:::mlartifact

DATASET -->|"train_input"| TRAIN
TRAIN -->|"produces"| MODEL_OUT
end

subgraph "Deploy to AWS EC2"
direction TB
DEPLOY["Deploy Step (copy artifacts + start services)"]:::deploy
DEPLOY -->|"ships"| DIST
DEPLOY -->|"ships"| API_DEV
DEPLOY -->|"ships"| MODEL_OUT
end

end

%% =========================
%% Click Events (component mapping)
%% =========================
click FE_SRC "https://github.com/shalani98/fraud-detection-system/tree/main/frontend/src/"
click FE_PAGE "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/src/pages/Web.jsx"
click FE_APP "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/src/App.jsx"
click FE_MAIN "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/src/main.jsx"
click FE_STYLE "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/src/App.css"
click FE_STYLE "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/src/index.css"
click FE_STATIC "https://github.com/shalani98/fraud-detection-system/tree/main/frontend/dist/"
click FE_INDEX "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/dist/index.html"
click FE_BUNDLE "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/dist/assets/index-BLzImUoE.js"
click FE_BUNDLE "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/dist/assets/index-DQ3P1g1z.css"
click VITE_CFG "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/package.json"
click VITE_CFG "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/package-lock.json"
click VITE_CFG "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/vite.config.js"
click VITE_CFG "https://github.com/shalani98/fraud-detection-system/blob/main/frontend/index.html"
click API "https://github.com/shalani98/fraud-detection-system/blob/main/backend/app.py"
click API_DEV "https://github.com/shalani98/fraud-detection-system/blob/main/backend/app.py"
click MODEL "https://github.com/shalani98/fraud-detection-system/blob/main/backend/fraud_model.pkl"
click MODEL_OUT "https://github.com/shalani98/fraud-detection-system/blob/main/backend/fraud_model.pkl"
click REQ "https://github.com/shalani98/fraud-detection-system/blob/main/backend/requirements.txt"
click DATASET "https://github.com/shalani98/fraud-detection-system/blob/main/data/creditcard.csv"

%% =========================
%% Styles
%% =========================
classDef external fill:#111827,stroke:#374151,color:#F9FAFB,stroke-width:1px
classDef frontend fill:#1D4ED8,stroke:#1E3A8A,color:#EFF6FF,stroke-width:1px
classDef backend fill:#15803D,stroke:#14532D,color:#ECFDF5,stroke-width:1px
classDef ml fill:#6D28D9,stroke:#4C1D95,color:#F5F3FF,stroke-width:1px
classDef mlartifact fill:#7C3AED,stroke:#4C1D95,color:#F5F3FF,stroke-width:1px,stroke-dasharray: 4 2
classDef artifact fill:#0EA5E9,stroke:#075985,color:#E0F2FE,stroke-width:1px,stroke-dasharray: 3 2
classDef data fill:#F59E0B,stroke:#92400E,color:#FFFBEB,stroke-width:1px
classDef build fill:#6B7280,stroke:#374151,color:#F9FAFB,stroke-width:1px
classDef offline fill:#9CA3AF,stroke:#4B5563,color:#111827,stroke-width:1px,stroke-dasharray: 4 2
classDef deploy fill:#334155,stroke:#0F172A,color:#F8FAFC,stroke-width:1px
classDef optional fill:#FFFFFF,stroke:#9CA3AF,color:#111827,stroke-width:1px,stroke-dasharray: 6 3
```
