Skip to content

anupama0307/Debuggers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

95 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RISKOFF - Complete Implementation Walkthrough

Project: RISKOFF - A Fintech Platform for Risk Assessment and Loan Management

RISKOFF is an AI-powered smart lending platform that automates loan processing, risk assessment, and financial management. It integrates machine learning for risk scoring, parses financial documents for verification, and provides user-friendly interfaces for customers and admins. This README provides a comprehensive overview of the implementation, building upon the previous RISKON + VisualPe framework with enhanced features, security, and integrations.

🌟 Features

Customer-Facing Features

  • πŸ“Š Financial Dashboard: Visualize income, expenses, investments, and spending patterns.
  • πŸ“„ Bank Statement Upload: Auto-parse and categorize transactions from CSV uploads with identity verification.
  • 🎯 Customer Score: AI-calculated creditworthiness score (0-900) based on DTI, expenses, and risk rules.
  • πŸ’° Loan Application: Apply for Personal, Home, Car, Education, or Business loans with instant AI assessment.
  • πŸ“‹ Loan Tracking: Real-time status updates and history.
  • ❓ Grievance System: AI-generated explanations for approvals/rejections.
  • πŸ€– AI Chat Agent: Contextual responses for loan queries.
  • πŸŽ™οΈ Voice-to-Text Engine: Users can apply for loans using voice notes. The system uses Gemini 1.5 Flash to transcribe audio directly into structured loan queries.
  • πŸ“€ File Uploads: Support for receipts (images), bank statements (CSV), and audio transcription.

Admin-Facing Features

  • πŸ“ˆ Dashboard: Overview stats (loans by status, total volume).
  • πŸ€– Auto-Processing: Auto-approve low-risk, auto-reject high-risk loans.
  • πŸ” Risk Analysis: Detailed ML-based assessment with fraud detection.
  • 🚨 Fraud Detection: Flags mismatches in expenses or identities.
  • πŸ’¬ AI Responses: Automated grievance explanations and notifications.
  • πŸ‘¨β€πŸ’Ό Role-Based Access: Admin-only endpoints for loan review and updates.

Core Capabilities

  • AI-Powered Risk Engine: EMI calculation and rule-based scoring.
  • Document Parsing: AI extraction for receipts, statements, and audio.
  • Notifications: Email alerts via Gmail SMTP.
  • Audit Logging: Track all actions for compliance.
  • Security: JWT auth, rate limiting, CORS, and headers.

πŸ“¦ Technology Stack

Component Technology/Framework
Backend FastAPI (Python)
Frontend React.js, TailwindCSS, Recharts
Database Supabase (PostgreSQL)
AI/LLM Google Gemini 1.5 Flash
ML Model Scikit-learn (Random Forest)
Authentication Supabase Auth (JWT + OTP)
Email Gmail SMTP
Containerization Docker
Other Libraries Pandas (parsing), Fuzzywuzzy (verification), SlowAPI (rate limiting)

πŸ“ Project Structure

riskoff/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ main.py          # FastAPI entry point + middleware
β”‚   β”‚   β”œβ”€β”€ config.py        # Supabase + Gemini initialization
β”‚   β”‚   β”œβ”€β”€ schemas.py       # Pydantic models for validation
β”‚   β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.py      # Authentication endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ loans.py     # Loan application endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ upload.py    # File upload (CSV, images, audio)
β”‚   β”‚   β”‚   β”œβ”€β”€ admin.py     # Admin panel endpoints
β”‚   β”‚   β”‚   └── agent.py     # AI chat agent
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ risk_engine.py # EMI + Risk score calculation
β”‚   β”‚   β”‚   β”œβ”€β”€ parser.py    # CSV/Image/Audio parsing + identity verification
β”‚   β”‚   β”‚   β”œβ”€β”€ llm.py       # Gemini AI text generation
β”‚   β”‚   β”‚   β”œβ”€β”€ notification.py # Email notifications (SMTP/Mock)
β”‚   β”‚   β”‚   └── audit.py     # Audit logging
β”‚   β”‚   └── utils/
β”‚   β”‚       └── security.py  # JWT verification, auth dependencies
β”‚   β”œβ”€β”€ tests/               # Test files
β”‚   β”œβ”€β”€ requirements.txt     # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile           # Production Docker setup
β”‚   β”œβ”€β”€ .dockerignore        # Docker build exclusions
β”‚   └── .env                 # Environment secrets
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/                 # React source code
β”‚   β”œβ”€β”€ public/              # Public assets
β”‚   β”œβ”€β”€ package.json         # Node dependencies
β”‚   └── ...                  # Other frontend files
β”œβ”€β”€ .gitignore
└── README.md                # This file

🌐 API Endpoints Reference

πŸ” Authentication (/auth)

Method Endpoint Auth Required Description
POST /auth/signup ❌ Register new user
POST /auth/login ❌ Login β†’ returns JWT tokens
POST /auth/login/form ❌ OAuth2 login for Swagger
POST /auth/logout βœ… Sign out current user
POST /auth/refresh ❌ Refresh access token
GET /auth/me βœ… Get current user profile

πŸ’° Loans (/loans)

Method Endpoint Auth Required Description
POST /loans/apply βœ… Submit loan application with AI assessment
GET /loans/my-loans βœ… Get user's loan history
GET /loans/ ❌ (Admin) Get all loans (admin view)
GET /loans/{loan_id} ❌ (Admin) Get specific loan

Loan Application Flow:

  1. User submits amount, tenure, income, expenses, purpose.
  2. Risk Engine calculates EMI and risk score.
  3. Gemini AI generates approval/rejection message.
  4. Loan saved to Supabase loans table.
  5. Action logged to audit_logs.

πŸ“€ Uploads (/upload)

Method Endpoint Auth Required Description
POST /upload/receipt Optional Upload receipt image β†’ AI extracts data
POST /upload/bank-statement βœ… Upload CSV β†’ parses with verification
POST /upload/receipt/save βœ… Save verified receipt to database
POST /upload/audio/transcribe βœ… Transcribe voice notes to text using Gemini

Features:

  • Receipt Parsing: Gemini Vision extracts merchant, amount, date, category.
  • Bank Statement Parsing: Pandas-based auto-categorization (Food, Transport, etc.).
  • Identity Verification: Fuzzy name matching (60% threshold).
  • Audio Transcription: Gemini for voice input on loan queries.

πŸ‘¨β€πŸ’Ό Admin (/admin)

Method Endpoint Auth Required Description
GET /admin/stats Admin Dashboard stats (loans, volume)
GET /admin/loans Admin Get all loans for review
PATCH /admin/loans/{loan_id}/status Admin Update loan status + email notification

Admin Features:

  • Role-based access (profiles.role = 'admin').
  • Email notifications on status changes.
  • Audit logging for actions.

πŸ€– AI Agent (/agent)

Method Endpoint Auth Required Description
POST /agent/chat βœ… Chat with AI Bank Manager

What it does:

  • Fetches user's loan data.
  • Generates contextual responses using Gemini.

🏠 System Endpoints

Method Endpoint Description
GET / API status
GET /health Health check (API + DB)

βš™οΈ Core Services

  1. Risk Engine (risk_engine.py):

    • EMI Calculation: EMI = P Γ— r Γ— (1+r)^n / ((1+r)^n - 1).
    • Risk Scoring Rules:
      • DTI > 40%: +30 points.
      • DTI > 60%: +50 points (replaces 30).
      • Expenses > 70% of income: +20 points.
      • DTI > 50% AND Expenses > 80%: Γ—1.5 multiplier.
    • Result: Score > 50 = REJECTED, else APPROVED.
  2. Parser Service (parser.py):

    • Bank Statement: Pandas parsing, auto-categorization.
    • Receipts: Gemini Vision extraction.
    • Audio: Gemini transcription.
    • Identity: Fuzzy matching (60% threshold).
  3. LLM Service (llm.py):

    • Functions: Loan summaries, rejection/approval messages, chat responses, spending analysis.
    • Singleton for unified imports.
  4. Notification Service (notification.py):

    • Gmail SMTP (mock mode for dev).
    • Status update emails.
  5. Audit Service (audit.py):

    • Logs to audit_logs table.
    • Non-blocking design.

πŸ”’ Security Implementation

Feature Implementation
Authentication Supabase Auth + JWT + OTP
Rate Limiting SlowAPI (60/min)
Security Headers X-Content-Type-Options, X-Frame-Options, HSTS
CORS Configured (allow all origins)
Role-Based Access Admin dependency checks
Identity Verification Fuzzy name matching for uploads

πŸ—„οΈ Database Schema (Supabase)

Table Purpose
loans Loan applications (status, score, EMI)
profiles User profiles (name, phone, role)
transactions Parsed financial transactions
bank_statements Uploaded statement records
audit_logs Action audit trail

🐳 Docker Setup

Dockerfile (for backend):

FROM python:3.11-slim
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

.dockerignore:

__pycache__
*.pyc
venv/
.env
.git
.pytest_cache
tests/

Build & Run (for backend):

# Build image
docker build -t riskoff-backend .
# Run container
docker run -d -p 8000:8000 --env-file .env --name riskoff-api riskoff-backend

πŸš€ Running Locally

Backend Setup

  1. Navigate to backend: cd backend
  2. Create virtual environment: python -m venv venv
    • Activate: source venv/bin/activate (Linux/Mac) or venv\Scripts\activate (Windows)
  3. Install dependencies: pip install -r requirements.txt
  4. Set up .env with:
    SUPABASE_URL=your_url
    SUPABASE_KEY=your_key
    GEMINI_API_KEY=your_key
    SMTP_EMAIL=your_email
    SMTP_PASSWORD=your_password
    
  5. Run server: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

  1. Navigate to frontend: cd frontend
  2. Install dependencies: npm install
  3. Run: npm start

Access:

πŸ” Demo Accounts

Role Email Password
Admin admin@riskoff.com admin123
User user@test.com user123

βœ… Implementation Summary

All components (FastAPI backend, React frontend, Supabase, Auth, Risk Engine, AI, Parsing, Admin, Agent, Notifications, Audit, Docker, Security) are complete and tested.

ARCHITECTURE DIAGRAM

image

VIMEO LINK

https://vimeo.com/1152642038?fl=ip&fe=ec https://vimeo.com/1152642490?fl=ip&fe=ec

πŸ“„ License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •