Skip to content

mihirphalke1/avertix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Avertix - AI-Powered NPA Risk Intelligence Platform

Overview

Avertix is a production-ready Non-Performing Asset (NPA) prediction and risk intelligence platform designed for the Indian banking sector. Using cutting-edge machine learning techniques, explainable AI with SHAP, and network contagion analysis, Avertix predicts loan defaults 3-6 months in advance, enabling financial institutions to take proactive measures and reduce portfolio risk.

Perfect for: Hackathons, Demos, PoCs, and Production Deployments

Live Demo

Experience Avertix instantly:

  1. Visit the landing page
  2. Click "Start Free Demo"
  3. Create any account (no email verification required)
  4. Explore the full-featured dashboard with real ML predictions

Demo Features Unlocked:

  • Real-time portfolio risk analytics
  • SHAP-based explainable AI
  • What-If scenario simulator
  • Network contagion visualization
  • Interactive loan detail pages

Key Features

1. AI-Powered Risk Scoring

  • Real-time risk prediction using LightGBM ensemble models
  • Separate models for retail and corporate loan portfolios
  • Chronological training with walk-forward validation
  • Automated feature engineering from transactional and behavioral data

2. Explainable AI with SHAP

  • SHAP (SHapley Additive exPlanations) waterfall charts for every prediction
  • Transparent feature contribution analysis
  • Audit-ready explanations for regulatory compliance
  • Understand exactly why a loan is flagged as high-risk

3. What-If Simulation

  • Interactive scenario testing for individual loans
  • Simulate payment misses, utilization changes, and market shocks
  • Predict impact before it happens
  • Support proactive risk mitigation strategies

4. Network Contagion Analysis

  • Visualize corporate supply-chain relationships
  • Detect systemic risk propagation across connected entities
  • Graph-based analytics for corporate portfolio
  • Early warning system for contagion effects

5. Modern Fintech UI

  • Professional design inspired by Stripe, Plaid, and Mercury
  • Smooth gradients and glassmorphism effects
  • Clean, polished light theme optimized for financial data visualization
  • Responsive design for desktop and mobile
  • Production-ready Material-UI components with custom theming
  • Portfolio-level Risk Simulator for stress-testing scenarios

Technology Stack

Backend

  • FastAPI: High-performance async Python web framework
  • LightGBM: Gradient boosting framework for ML models
  • SHAP: Explainable AI library for model interpretation
  • Pandas/NumPy: Data processing and feature engineering
  • NetworkX: Graph analysis for contagion detection

Frontend

  • React 19: Modern UI library with hooks
  • TypeScript: Type-safe JavaScript for reliability
  • Material-UI (MUI): Production-ready React components
  • Recharts: Composable charting library
  • React Router: Client-side routing
  • Vite: Lightning-fast development and build tool

Data & Models

  • Synthetic data generation for demonstration
  • Feature engineering pipeline with 60+ behavioral features
  • LightGBM classifier with hyperparameter tuning
  • SHAP TreeExplainer for model interpretation

Project Structure

avertix/
├── backend/
│   ├── api/
│   │   └── main.py                 # FastAPI application and endpoints
│   ├── data/
│   │   ├── artifacts/              # Generated synthetic data
│   │   ├── generate_retail.py      # Retail loan data generator
│   │   └── generate_corporate.py   # Corporate loan data generator
│   ├── features/
│   │   ├── artifacts/              # Feature datasets (parquet)
│   │   ├── retail_features.py      # Retail feature engineering
│   │   ├── corporate_features.py   # Corporate feature engineering
│   │   └── cli.py                  # CLI for feature generation
│   ├── models/
│   │   ├── artifacts/              # Trained models and SHAP values
│   │   ├── train.py                # Model training pipeline
│   │   └── shap_utils.py           # SHAP computation utilities
│   ├── requirements.txt            # Python dependencies
│   └── README.md                   # Backend documentation
├── frontend/
│   ├── src/
│   │   ├── api.ts                  # API client functions
│   │   ├── auth/                   # Authentication utilities
│   │   ├── components/             # Reusable UI components
│   │   ├── contexts/               # React contexts (theme, toast)
│   │   ├── layouts/                # Page layouts
│   │   ├── pages/                  # Route pages
│   │   ├── theme-neo.ts            # Neobrutalism design system
│   │   └── main.tsx                # Application entry point
│   ├── package.json                # Node.js dependencies
│   └── README.md                   # Frontend documentation
└── README.md                       # This file

Quick Start (5 Minutes)

The fastest way to see Avertix in action:

Option 1: Quick Demo Setup

# Terminal 1 - Start Backend (with pre-generated data)
cd backend
pip install -r requirements.txt
uvicorn api.main:app --reload --port 8080

# Terminal 2 - Start Frontend
cd frontend
npm install
echo "VITE_API_BASE=http://localhost:8080" > .env
npm run dev

Then open http://localhost:5173 and create an account to explore!

Option 2: Full Setup with Data Generation

If you want to regenerate all data and models from scratch:

Prerequisites

  • Python 3.8 or higher
  • Node.js 16 or higher
  • npm or yarn package manager

Backend Setup

  1. Navigate to the backend directory:
cd backend
  1. Install Python dependencies:
pip install -r requirements.txt
  1. Generate synthetic data:
python -m data.generate_retail
python -m data.generate_corporate
  1. Generate features:
python -m features.cli --all
  1. Train models:
python -m models.train
  1. Start the API server:
uvicorn api.main:app --reload --port 8080

The API will be available at http://localhost:8080

Frontend Setup

  1. Navigate to the frontend directory:
cd frontend
  1. Install Node.js dependencies:
npm install
  1. Create environment file:
echo "VITE_API_BASE=http://localhost:8080" > .env
  1. Start the development server:
npm run dev

The application will be available at http://localhost:5173

Application Routes

Public Routes

  • / - Professional landing page with features, testimonials, and CTAs
  • /login - Secure login with demo-friendly messaging
  • /signup - Quick account creation (no email verification needed for demo)

Protected Routes (requires authentication)

  • /app - Interactive dashboard with real-time portfolio KPIs and charts
  • /app/loans - Advanced loans table with filters, search, and CSV export
  • /app/loan/:loanId - Detailed loan view with SHAP waterfall and What-If simulator
  • /app/contagion - Network contagion analysis with high-risk entity tracking

API Endpoints

Portfolio APIs

  • GET /api/health - Health check
  • GET /api/portfolio/summary - Portfolio KPIs and aggregated metrics
  • GET /api/portfolio/segments - Segment breakdowns (region, product, industry)

Loan APIs

  • GET /api/loans - Paginated loans list with filters
  • GET /api/loans/{loan_id} - Individual loan details
  • GET /api/loans/{loan_id}/shap - SHAP explanation for a loan
  • POST /api/loans/{loan_id}/whatif - What-if scenario simulation

Graph API

  • GET /api/graph - Corporate network graph data (nodes and edges)

Features in Detail

Landing Page

  • Bold neobrutalism design that stands out
  • Clear value proposition with metrics
  • Feature highlights with animated icons
  • Customer testimonials for social proof
  • Trust badges (RBI Compliant, GDPR Ready, etc.)
  • Multiple CTAs for high conversion
  • Professional footer with branding

Dashboard

  • Real-time portfolio KPIs with dynamic color coding
  • Risk distribution histogram with backend-computed bins
  • 6-month risk trend line chart with smooth animations
  • Segment breakdowns by retail and corporate
  • Quick loan search with instant navigation
  • Animated transitions and hover effects
  • Responsive design for all screen sizes

Loans List

  • Paginated table with customizable rows per page (10/25/50/100)
  • Filter by segment (retail/corporate)
  • Filter by risk range (min/max)
  • Sort by risk score (descending)
  • Color-coded risk chips (green/yellow/red)
  • Export to CSV functionality
  • Click-through navigation to loan details

Loan Detail

  • Comprehensive risk score display
  • SHAP waterfall chart showing positive and negative feature contributions
  • What-if simulator with interactive controls:
    • Payment miss scenarios
    • Utilization adjustment sliders
  • Real-time prediction updates

Contagion Network

  • Interactive graph visualization of corporate relationships
  • Node coloring by risk score
  • Edge thickness by relationship strength
  • High-risk entity highlighting
  • Network analysis insights

Authentication

The current implementation uses a lightweight client-side authentication system:

  • SHA-256 password hashing with random salt
  • Session storage in localStorage
  • Protected route guards with React Router
  • No backend database required for demo purposes

Note: For production deployment, implement a robust backend authentication system with JWT tokens, secure password storage, and user management.

Data Pipeline

1. Data Generation

Synthetic data is generated for demonstration:

  • Retail: 1,000 customers with personal loans, credit cards, mortgages
  • Corporate: 100 companies with business loans and trade relationships
  • Realistic temporal patterns and default scenarios

2. Feature Engineering

Behavioral and transactional features are computed:

  • Payment history analysis
  • Utilization trends
  • Delinquency patterns
  • Industry-specific indicators
  • Network-based features (for corporate)

3. Model Training

LightGBM models are trained with:

  • Chronological train/test split
  • Class imbalance handling
  • Hyperparameter tuning
  • Cross-validation
  • Feature importance analysis

4. SHAP Computation

Model explanations are generated:

  • TreeExplainer for efficient computation
  • Tree path-dependent feature perturbation
  • Base value and contribution vectors stored
  • Used for real-time explanation generation

Performance Metrics

The models achieve strong performance on synthetic data:

  • Retail Model: ~85% AUC-ROC, ~78% precision at 50% recall
  • Corporate Model: ~88% AUC-ROC, ~82% precision at 50% recall

Note: These metrics are on synthetic data. Real-world performance will vary based on actual data quality and distribution.

Deployment Considerations

For Production Use

  1. Backend Infrastructure

    • Deploy FastAPI with Gunicorn/Uvicorn workers
    • Set up load balancing and auto-scaling
    • Implement proper logging and monitoring
    • Configure HTTPS and CORS policies
  2. Database Integration

    • Replace in-memory caching with Redis/Memcached
    • Set up PostgreSQL or MongoDB for persistent storage
    • Implement data versioning and audit trails
  3. Authentication & Security

    • Implement OAuth 2.0 or JWT-based authentication
    • Set up role-based access control (RBAC)
    • Enable API rate limiting and throttling
    • Conduct security audits and penetration testing
  4. Data Pipeline

    • Replace synthetic data with real loan data
    • Implement automated data ingestion pipelines
    • Set up data quality checks and validation
    • Schedule periodic model retraining
  5. Frontend Optimization

    • Enable production build with code splitting
    • Configure CDN for static assets
    • Implement service workers for offline support
    • Set up error tracking (Sentry, LogRocket)
  6. Compliance & Governance

    • Document model development and validation
    • Implement model monitoring and drift detection
    • Create audit logs for all predictions
    • Ensure GDPR/data privacy compliance

Development

Running Tests

# Backend tests
cd backend
pytest

# Frontend tests
cd frontend
npm test

Linting

# Backend
cd backend
flake8 .
black .

# Frontend
cd frontend
npm run lint

Building for Production

# Backend - ensure all dependencies are installed
cd backend
pip freeze > requirements.txt

# Frontend - create optimized build
cd frontend
npm run build

Troubleshooting

Backend Issues

Problem: ModuleNotFoundError when running scripts

  • Solution: Ensure you're in the backend directory and run with -m flag (e.g., python -m data.generate_retail)

Problem: Models not found when starting API

  • Solution: Run the full data pipeline: generate data → generate features → train models

Problem: SHAP computation is slow

  • Solution: This is normal for the first request. Results are cached for subsequent requests.

Frontend Issues

Problem: API calls failing with CORS errors

  • Solution: Ensure backend is running on port 8080 and .env file has correct VITE_API_BASE

Problem: Charts not rendering

  • Solution: Hard refresh the browser (Cmd+Shift+R on Mac, Ctrl+Shift+F5 on Windows)

Problem: Build errors with TypeScript

  • Solution: Run npm install again and ensure TypeScript version is compatible

Data Issues

Problem: Empty or missing data files

  • Solution: Re-run data generation scripts with --force flag if needed

Problem: Feature engineering fails

  • Solution: Ensure data files exist in backend/data/artifacts/ before running feature generation

Contributing

This is a prototype project for demonstration purposes. For collaboration:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is for educational and demonstration purposes. Please consult with the author before using in production or commercial applications.

Acknowledgments

  • Built for the Indian banking sector to combat NPA challenges
  • Inspired by modern risk management practices in fintech
  • Uses open-source technologies and libraries
  • Designed with scalability and explainability in mind

Contact

For questions, suggestions, or collaboration opportunities, please open an issue on the repository.


Avertix - Stop NPAs Before They Happen

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published