Skip to content

adarsh-yadav1/FinBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– FinBot β€” AI-Powered Loan Sales Assistant

An Agentic AI system for NBFCs that automates the end-to-end personal loan journey β€” from customer intent to sanction letter generation β€” using Groq LLM, FastAPI, and React.


Live link : https://fin-bot-azure.vercel.app/


πŸ“ Architecture Overview

User (React Chat UI)
        β”‚
        β–Ό
  FastAPI Backend
        β”‚
   Master Agent  ◄── Groq LLaMA 3.3 70B (intent, conversation)
        β”‚
   β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚           Worker Agents       β”‚
   β”œβ”€ Sales Agent                  β”‚  ← Loan term extraction & negotiation
   β”œβ”€ Verification Agent           β”‚  ← KYC via Mock CRM
   β”œβ”€ Underwriting Agent           β”‚  ← Deterministic Rules Engine
   └─ Sanction Agent               β”‚  ← PDF sanction letter generator
        β”‚
   Backend Services
   β”œβ”€ Mock CRM (JSON)              ← KYC / PAN / credit score
   β”œβ”€ Underwriting Rules Engine    ← 6-rule deterministic engine
   └─ Sanction Service             ← Letter generation

πŸ›  Tech Stack

Layer Technology
LLM Groq β€” llama-3.3-70b-versatile
Backend Python 3.11+, FastAPI (ASGI), Uvicorn
Frontend React 18, Vite, Tailwind CSS
Session Storage In-memory (replace with Redis/Postgres for prod)
Decision Logic Hybrid: Groq for NLU + deterministic rules engine
Document Gen Plain text (swap in fpdf2/reportlab for real PDF)

πŸ” Underwriting Rules Engine

The rules engine is fully deterministic and auditable β€” Groq is never used for financial decisions. Rules run in sequence; the first failure causes rejection.

# Rule Threshold
1 Loan bounds β‚Ή10,000 – β‚Ή20,00,000
2 Tenure bounds 6 – 60 months
3 Minimum credit score β‰₯ 700
4 Pre-approved limit check Loan ≀ limit β†’ approve; limit < loan ≀ 2Γ— limit β†’ need salary slip; > 2Γ— limit β†’ reject
5 Loan-to-income ratio ≀ 36Γ— monthly income
6 EMI affordability EMI ≀ 40% of monthly income

EMI is computed using the standard reducing-balance formula:

EMI = P Γ— r Γ— (1+r)^n / ((1+r)^n βˆ’ 1)

where r = annual_rate / 12, n = tenure_months.


🧩 Agent Roles

Master Agent

  • Owns the full conversation state machine
  • Stages: greeting β†’ sales β†’ verification β†’ underwriting β†’ approved/rejected
  • Orchestrates worker agents; makes no financial decisions itself

Sales Agent (Groq-powered)

  • Extracts loan_amount, tenure_months, purpose, monthly_income from free-text
  • Handles "2 lakh" β†’ 200000 conversion, years β†’ months, etc.
  • Returns structured JSON; Master Agent writes to session DB

Verification Agent (Groq + CRM lookup)

  • Collects and format-validates phone (10 digits) and PAN (ABCDE1234F pattern)
  • Looks up customer in Mock CRM; cross-validates PAN
  • Populates credit score, income, pre-approved limit into session

Underwriting Agent (Rules Engine)

  • Reads session data, calls rules/underwriting_rules.py
  • Rules engine returns structured UnderwritingResult
  • Groq only used to humanize the explanation text (no decision power)

Sanction Agent

  • Generates a formatted sanction letter with all loan terms
  • Stores file in /tmp/finbot_sanctions/
  • Returns a download URL

πŸš€ Getting Started

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Groq API Key (free tier available)

Backend Setup

cd backend

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

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env and set: GROQ_API_KEY=your_key_here

# Run the server
uvicorn main:app --reload --port 8000

Backend runs at: http://localhost:8000
API docs: http://localhost:8000/docs


Frontend Setup

cd frontend

# Install dependencies
npm install

# Start dev server
npm run dev

Frontend runs at: http://localhost:5173


πŸ§ͺ Demo Accounts

Use these phone + PAN combinations during KYC verification:

Phone PAN Credit Score Income Result
9876543210 ABCDE1234F 750 β‚Ή60,000 βœ… Likely approved
9123456780 FGHIJ5678K 680 β‚Ή35,000 ❌ Low credit score
9988776655 LMNOP9012Q 610 β‚Ή25,000 ❌ Low credit + invalid slip
8000000001 RSTUV3456W 720 β‚Ή45,000 βœ… Likely approved

πŸ’¬ Sample Conversation Flow

User:  I need a home renovation loan
Bot:   Great! How much would you like to borrow and for how long?

User:  2 lakh for 24 months, my salary is 50000
Bot:   Got it β€” β‚Ή2,00,000 over 24 months. 
       To verify your identity, please share your mobile number.

User:  9876543210
Bot:   And your PAN card number?

User:  ABCDE1234F
Bot:   βœ… KYC verified, Rahul Sharma!
       πŸ“‹ Underwriting: Congratulations! Your loan of β‚Ή2,00,000 has been approved.
       Monthly EMI: β‚Ή9,982 at 18% p.a.
       πŸŽ‰ [Download Sanction Letter]

πŸ“ Project Structure

finbot/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                    # FastAPI app entry point
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ master_agent.py        # State machine + orchestrator
β”‚   β”‚   β”œβ”€β”€ sales_agent.py         # Loan term extraction
β”‚   β”‚   β”œβ”€β”€ verification_agent.py  # KYC validation
β”‚   β”‚   └── underwriting_agent.py  # Rules engine wrapper
β”‚   β”œβ”€β”€ rules/
β”‚   β”‚   └── underwriting_rules.py  # 6-rule deterministic engine
β”‚   └── services/
β”‚       β”œβ”€β”€ groq_service.py        # Groq API client
β”‚       β”œβ”€β”€ crm_service.py         # Mock CRM / KYC database
β”‚       β”œβ”€β”€ session_store.py       # In-memory session state
β”‚       └── sanction_service.py    # Sanction letter generator
β”‚
└── frontend/
    β”œβ”€β”€ index.html
    β”œβ”€β”€ vite.config.js
    β”œβ”€β”€ tailwind.config.js
    └── src/
        β”œβ”€β”€ App.jsx                # Root component + layout
        β”œβ”€β”€ index.css              # Global styles + animations
        β”œβ”€β”€ main.jsx
        β”œβ”€β”€ hooks/
        β”‚   └── useChat.js         # Conversation state management
        β”œβ”€β”€ utils/
        β”‚   └── api.js             # Axios API client
        └── components/
            β”œβ”€β”€ Header.jsx
            β”œβ”€β”€ StageBar.jsx       # Progress indicator
            β”œβ”€β”€ MessageBubble.jsx  # Chat messages
            β”œβ”€β”€ TypingIndicator.jsx
            β”œβ”€β”€ QuickReplies.jsx   # Suggestion chips
            β”œβ”€β”€ ChatInput.jsx      # Text input bar
            β”œβ”€β”€ LoanPanel.jsx      # Sidebar loan summary
            └── WelcomeScreen.jsx  # Initial landing view

πŸ”§ Configuration

All underwriting thresholds are in backend/rules/underwriting_rules.py:

MIN_CREDIT_SCORE          = 700
MAX_LOAN_TO_INCOME_RATIO  = 36
MAX_EMI_TO_INCOME_RATIO   = 0.40
MAX_LOAN_ABSOLUTE         = 2_000_000
MIN_LOAN_ABSOLUTE         = 10_000
MAX_TENURE_MONTHS         = 60
ANNUAL_INTEREST_RATE      = 0.18
OVER_LIMIT_MULTIPLIER     = 2.0

πŸ›£ Future Scope

  • Replace Mock CRM with real KYC / PAN / bureau APIs
  • Swap in fpdf2 for proper PDF sanction letters
  • Redis session store for horizontal scaling
  • WhatsApp / SMS channel via Twilio
  • Fraud & AML detection agents
  • Multilingual support (Hindi, Tamil, etc.)
  • Cross-sell agents (credit cards, insurance, BNPL)
  • Firebase Auth for user identity management

πŸ“„ License

MIT β€” built for the IIIT Guwahati FinTech AI project.

About

It is a Hackathon Project which automates the Loan Process.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors