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.
- π 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.
- π 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.
- 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.
| 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) |
| Gmail SMTP | |
| Containerization | Docker |
| Other Libraries | Pandas (parsing), Fuzzywuzzy (verification), SlowAPI (rate limiting) |
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
| 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 |
| 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:
- User submits amount, tenure, income, expenses, purpose.
- Risk Engine calculates EMI and risk score.
- Gemini AI generates approval/rejection message.
- Loan saved to Supabase
loanstable. - Action logged to
audit_logs.
| 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.
| 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.
| 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.
| Method | Endpoint | Description |
|---|---|---|
| GET | / | API status |
| GET | /health | Health check (API + DB) |
-
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.
- EMI Calculation:
-
Parser Service (
parser.py):- Bank Statement: Pandas parsing, auto-categorization.
- Receipts: Gemini Vision extraction.
- Audio: Gemini transcription.
- Identity: Fuzzy matching (60% threshold).
-
LLM Service (
llm.py):- Functions: Loan summaries, rejection/approval messages, chat responses, spending analysis.
- Singleton for unified imports.
-
Notification Service (
notification.py):- Gmail SMTP (mock mode for dev).
- Status update emails.
-
Audit Service (
audit.py):- Logs to
audit_logstable. - Non-blocking design.
- Logs to
| 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 |
| 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 |
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
- Navigate to backend:
cd backend - Create virtual environment:
python -m venv venv- Activate:
source venv/bin/activate(Linux/Mac) orvenv\Scripts\activate(Windows)
- Activate:
- Install dependencies:
pip install -r requirements.txt - Set up
.envwith:SUPABASE_URL=your_url SUPABASE_KEY=your_key GEMINI_API_KEY=your_key SMTP_EMAIL=your_email SMTP_PASSWORD=your_password - Run server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- Navigate to frontend:
cd frontend - Install dependencies:
npm install - Run:
npm start
Access:
- Frontend: http://localhost:3000
- API Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Health: http://localhost:8000/health
| Role | Password | |
|---|---|---|
| Admin | admin@riskoff.com | admin123 |
| User | user@test.com | user123 |
All components (FastAPI backend, React frontend, Supabase, Auth, Risk Engine, AI, Parsing, Admin, Agent, Notifications, Audit, Docker, Security) are complete and tested.
ARCHITECTURE DIAGRAM
VIMEO LINK
https://vimeo.com/1152642038?fl=ip&fe=ec https://vimeo.com/1152642490?fl=ip&fe=ec
MIT License