# vatshayan/upi-fraud-detection-using-machine-learning architecture

> Architecture diagram of the GitHub repository vatshayan/upi-fraud-detection-using-machine-learning, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vatshayan/upi-fraud-detection-using-machine-learning
- Repository: https://github.com/vatshayan/upi-fraud-detection-using-machine-learning

## Overview

##### Project type and purpose
- This is a full-stack web application for real-time UPI fraud detection.
- The frontend is a simple HTML/CSS interface (templates/index.html + static/styles.css).
- The backend is a Python/Flask app (app.py) that loads and runs a pre-trained machine-learning model.
- model.ipynb is used offline for data exploration, model training, and export.

##### File structure
- Top level:
- README.md – project overview
- app.py – Flask application entry point (routes, request handling, model inference)
- model.ipynb – Jupyter notebook for ML development
- Directories:
- /templates – Jinja2 HTML template(s) for user input and displaying results
- /static – CSS (and potentially JS or images) for styling and client behavior
- No explicit database folder; data persistence (if any) might be a flat file or in-memory.

##### README for additional clues
- Emphasizes a “user-friendly interface” for entering transaction details and “real-time fraud assessments.”
- Mentions security and privacy best practices (use HTTPS, sanitize inputs).
- No external services listed, so assume all inference happens in-app.

- Client-side UI (Browser)
- Web Server / API Layer (Flask app.py)
- ML Model Service (loaded from serialized model file or in-memory object)
- Data Store (optional – e.g., CSV/JSON log of transactions or a lightweight DB)
- Offline Model-Training Environment (model.ipynb + raw data)

1. User (Browser) → HTTP POST /predict → Flask API
2. Flask API → (call) ML Model Service → returns fraud score/label
3. Flask API → optional write to Data Store (logging/persistence)
4. Flask API → HTTP response → Browser (fraud assessment display)
5. Offline Training → reads raw data → updates ML Model → exports new serialized model → deployed to Web Server

c. Architectural patterns & design principles
- MVC-style separation:
- View = HTML templates
- Controller = Flask routes + request handling
- Model = ML inference code + serialized model artifacts
- Single-service deployment (monolith) with clear internal module boundaries
- Keep ML training and inference decoupled (batch vs. real-time)
- Security: enforce input validation, HTTPS for all endpoints, sanitize user inputs

d. Key technologies & libraries
- Python 3.x, Flask (app.py)
- Jinja2 templating (templates/index.html)
- CSS for styling (static/styles.css)
- scikit-learn / pandas / numpy inside model.ipynb + inference code
- Optional: SQLite or CSV for simple persistence

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    subgraph "User Interface"
        UI["Browser\n(templates/index.html)"]:::frontend
        CSS["static/styles.css"]:::frontend
    end

    %% Backend Server Layer
    subgraph "Backend Server"
        API["Flask API\n(app.py)"]:::backend
        Model["ML Inference Module\n(app.py)"]:::model
        Store["Data Store\n(CSV/SQLite)"]:::store
    end

    %% Offline Training Pipeline
    subgraph "Offline Training Pipeline"
        Raw["Raw Data"]:::training
        Notebook["model.ipynb"]:::training
        Export["Serialized Model"]:::training
    end

    %% Documentation
    Doc["README.md"]:::docs

    %% Connections - Real-time Flow
    UI -->|"HTTP POST /predict"| API
    API -->|"Model.predict(input_json)"| Model
    API -->|"Log transaction"| Store
    API -->|"HTTP Response (fraud score)"| UI

    %% Connections - Offline Training Flow
    Raw -->|"train model"| Notebook
    Notebook -->|"export model"| Export
    Export -->|"deployed to"| Model

    %% Documentation Link
    Doc --- API

    %% Click Events
    click UI "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/templates/index.html"
    click CSS "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/static/styles.css"
    click API "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/app.py"
    click Model "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/app.py"
    click Notebook "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/model.ipynb"
    click Doc "https://github.com/vatshayan/upi-fraud-detection-using-machine-learning/blob/main/README.md"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef model fill:#FFD580,stroke:#333,stroke-width:1px
    classDef store fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef training fill:#FFA500,stroke:#333,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:1px
```
