Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transaction Risk System

Python 3.9+ License: MIT Code style: black FastAPI Flask Deployment: Render

This repository contains a transaction risk assessment system that ingests transaction-level data, computes risk-related features, and returns a risk score and decision through an API. The system includes a backend inference service, a rule-based decision layer, and a lightweight UI for interactive testing.

Transaction Risk System UI


Live Deployments


Objective

The goal of this system is to:

  • Ingest transaction-level data
  • Engineer fraud/risk-relevant features
  • Serve ML-based risk decisions via a low-latency API
  • Provide a UI for interactive testing
  • Maintain production discipline via CI/CD and security checks

This repository is intentionally structured to mirror real-world fintech / risk-engineering systems rather than a notebook-style ML project.


High-Level Architecture

flowchart LR
    User[User / Client]
    UI[Flask UI]
    API[FastAPI Inference API]
    DE[Decision Engine]
    Model[ML Model]
    Data[(Feature Store)]

    User --> UI
    UI --> API
    API --> DE
    DE --> Model
    DE --> Data
    Model --> DE
    DE --> API
    API --> UI
Loading

Repository Structure

TRANSACTION-RISK-SYSTEM-V2/
│
├── .github/                # CI/CD workflows (GitHub Actions)
├── data/                   # Data lifecycle management
│   ├── raw/                # Raw, untouched data
│   ├── validated/          # Schema-validated data
│   ├── curated/            # Cleaned & model-ready data
│   └── features/           # Engineered feature outputs
│
├── docs/                   # System documentation
│   └── decision_framing.md # Risk logic & decision rationale
│
├── src/                    # Application source code
│   ├── api/                # FastAPI service (inference layer)
│   ├── decision_engine/    # Core risk & rule-based logic
│   ├── ingestion/          # Data ingestion & validation
│   ├── features/           # Feature engineering pipeline
│   ├── models/             # Model loading & artifacts
│   ├── config/             # Configurations & constants
│   └── ui/                 # Flask-based UI client
│
├── requirements.txt        # Python dependencies
├── .gitignore
└── README.md

Data & Feature Pipeline

flowchart TD
    Raw[Raw Transactions]
    Validate[Schema Validation]
    Curate[Cleaning & Sorting]
    FeatureEng[Feature Engineering]
    FeatureStore[(Feature Store)]

    Raw --> Validate
    Validate --> Curate
    Curate --> FeatureEng
    FeatureEng --> FeatureStore
Loading

Example Features

  • PCA components (V1–V28)
  • Transaction amount & log amount
  • Velocity features (tx_count_last_600, tx_count_last_3600)
  • Rule-derived risk flags

Decision Engine

The Decision Engine is responsible for:

  • Accepting a feature vector
  • Scaling and transforming inputs
  • Running ML inference
  • Applying rule-based thresholds
  • Returning a structured decision
flowchart LR
    Input[Feature Vector]
    Scale[Scaler]
    Infer[ML Inference]
    Rules[Risk Rules]
    Output[Decision + Risk Score]

    Input --> Scale --> Infer --> Rules --> Output
Loading

FastAPI Inference Service

Base URL:
https://transaction-risk-system-v2.onrender.com/

Endpoint: /decide

Method: POST

Request Body:

{
  "feature_vector": {
    "Time": 123456,
    "V1": 0.0,
    "V2": 0.0,
    "...": "...",
    "Amount": 149.62,
    "tx_count_last_600": 1,
    "tx_count_last_3600": 4
  }
}

Response:

{
  "risk_score": 0.73,
  "decision": "DECLINE"
}

Flask UI (Client Layer)

The UI is intentionally kept thin:

  • No ML logic
  • No feature engineering
  • Only acts as a client to the FastAPI service

Live UI:
https://transaction-risk-system-ui.onrender.com/

UI Design Principles

  • Sensible defaults (V1–V28 default to 0)
  • Advanced features hidden by default
  • Manual override supported for testing

CI/CD Pipeline

This repository uses GitHub Actions to enforce production discipline.

flowchart LR
    Commit[Git Push]
    Test[Test & Lint]
    Security[Security Scan]
    Build[Build Verification]
    Deploy[Render Auto Deploy]

    Commit --> Test --> Security --> Build --> Deploy
Loading

Pipeline Capabilities

  • Multi-version Python testing (3.9–3.11)
  • Linting (flake8)
  • Unit tests (pytest)
  • Security scans (Bandit, Safety)
  • Import & build verification

Security & Reliability

  • No secrets hardcoded
  • Dependency vulnerability scanning
  • Non-blocking security reporting
  • Environment parity across local, CI, and production

Local Development

# Create environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run FastAPI
uvicorn src.api.app:app --reload

# Run UI
cd src/ui
python app.py

Design Philosophy

This project prioritizes:

  • Separation of concerns - Clear boundaries between data, logic, and presentation layers
  • Production realism over toy examples - Mimics actual production system architecture
  • Explainability and traceability - Every decision can be audited and explained
  • Interview-ready architecture - Demonstrates system design and engineering best practices

Future Enhancements

  • Model versioning and A/B testing framework
  • Drift detection & monitoring
  • Authentication & rate limiting
  • Feature store abstraction (e.g., Feast integration)
  • Event-driven ingestion pipeline
  • Horizontal scaling with load balancing
  • Real-time monitoring dashboards

Technology Stack

  • Backend: FastAPI, Flask
  • ML: scikit-learn, XGBoost
  • Data Processing: pandas, NumPy
  • Deployment: Render (serverless)
  • CI/CD: GitHub Actions
  • Security: Bandit, Safety

Author

Prateek

Built as a production-style ML system to demonstrate readiness for Data Scientist / ML Engineer roles at leading technology companies.


"Good models impress. Reliable systems get deployed."

About

Transaction risk assessment system with real-time ML inference, rule-based decisioning, API service, UI client, and CI/CD pipeline.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages