Skip to content

Mehedi26696/DenaAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 DenaAI - Intelligent Loan Underwriting System

DenaAI Banner FastAPI Flutter XGBoost License

AI-Powered Loan Decision System with OCR, LLM Extraction, and Explainable ML

Features β€’ Architecture β€’ Installation β€’ API Docs β€’ Demo


πŸ“‹ Table of Contents


🌟 Overview

DenaAI is an intelligent loan underwriting system that combines cutting-edge AI technologies to automate and enhance the loan approval process. Built for financial institutions, it provides:

  • πŸ“„ Automated Document Processing via OCR
  • πŸ€– AI-Powered Data Extraction using Groq LLM
  • 🎯 ML-Based Risk Assessment with XGBoost
  • πŸ” Explainable AI for transparent decision-making
  • πŸ“Š Bias Detection & Monitoring for fair lending
  • πŸ‘₯ Dual Interface for customers and bank officers

Why DenaAI?

Traditional loan processing is slow, subjective, and prone to bias. DenaAI solves these problems by:

βœ… Reducing processing time from days to minutes
βœ… Providing transparent, explainable decisions
βœ… Detecting and preventing algorithmic bias
βœ… Supporting both automated and manual review workflows
βœ… Helping rejected applicants improve their applications


✨ Features

🎯 Core Features

For Loan Applicants

  • πŸ“± Mobile-First Application - Apply for loans from anywhere
  • πŸ“Έ Smart Document Upload - OCR automatically extracts data from income documents
  • ⚑ Instant Decisions - Get approval/rejection in seconds
  • πŸ’‘ AI-Powered Guidance - Understand why you were rejected and how to improve
  • πŸ“Š Application Tracking - Monitor your loan status in real-time
  • πŸ“œ Loan History - View all past applications and outcomes

For Bank Officers

  • πŸ” Manual Review Queue - Handle edge cases requiring human judgment
  • πŸ“Š Comprehensive Dashboard - Monitor all applications
  • πŸ‘₯ User Management - Manage customer accounts
  • πŸ“ˆ Analytics & Reports - Track approval rates and trends
  • βœ… Approval Workflow - Approve, reject, or request additional information

For Administrators

  • πŸ–₯️ Web Monitoring Dashboard - Real-time system monitoring
  • 🎯 Bias Detection - Identify and mitigate algorithmic bias
  • πŸ“‹ Audit Logs - Complete audit trail of all decisions
  • πŸ“Š Advanced Analytics - Deep insights with interactive graphs
  • βš™οΈ System Configuration - Manage thresholds and rules

πŸ” Security & Compliance

  • πŸ”’ Secure authentication for users and admins
  • πŸ“ Complete audit trail for regulatory compliance
  • πŸ›‘οΈ Data privacy protection
  • βš–οΈ Fair lending compliance monitoring

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       USER INTERACTION                       β”‚
β”‚  πŸ“± Flutter Mobile App     πŸ–₯️ Flutter Web Dashboard         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚                              β”‚
                 β–Ό                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FASTAPI BACKEND                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   Auth API   β”‚  β”‚  Loan API    β”‚  β”‚  Admin API   β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                  β”‚                  β”‚
          β–Ό                  β–Ό                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PROCESSING LAYER                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   OCR   β”‚β†’ β”‚ Groq LLM β”‚β†’ β”‚  Rules  β”‚β†’ β”‚ XGBoost  β”‚     β”‚
β”‚  β”‚ Service β”‚  β”‚Extractionβ”‚  β”‚  Engine β”‚  β”‚   ML     β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                                         β”‚
          β–Ό                                         β–Ό
    Decision Result                        Explanation + Score

Workflow

graph TD
    A[User Uploads Document] --> B{User Type?}
    B -->|New User| C[OCR Extraction]
    B -->|Existing User| D[Fetch History]
    C --> E[Groq LLM Parse Fields]
    D --> E
    E --> F[Rule-Based Checks]
    F --> G[XGBoost Prediction]
    G --> H{Decision}
    H -->|Approved| I[Show Explanation]
    H -->|Rejected| J[AI Help & Suggestions]
    H -->|Uncertain| K[Manual Review Queue]
    K --> L[Bank Officer Review]
    I --> M[Store Audit Log]
    J --> M
    L --> M
Loading

πŸ› οΈ Technology Stack

Backend

  • Framework: FastAPI 0.124.4
  • ML Engine: XGBoost 3.1.2, Scikit-learn 1.6.1
  • LLM: Groq (Llama 3.1-8B-Instant)
  • OCR: OCR.space API
  • Language: Python 3.10+

Frontend

  • Framework: Flutter 3.0+
  • State Management: Provider/Riverpod
  • Platforms: iOS, Android, Web

Machine Learning

  • Algorithm: XGBoost Gradient Boosting
  • Features: 11 financial indicators
  • Training Dataset: loan_approval_dataset.csv
  • Model Format: Joblib pipeline

DevOps & Tools

  • API Documentation: Swagger UI (FastAPI auto-generated)
  • Environment Management: Python dotenv
  • Version Control: Git

πŸ“¦ Installation

Prerequisites

  • Python 3.10+
  • Flutter SDK 3.0+
  • Git

Backend Setup

# Clone the repository
git clone https://github.com/Mehedi26696/Fintech.git
cd DenaAI/backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
copy .env.example .env  # Windows
cp .env.example .env    # Linux/Mac

# Edit .env and add your API keys
# GROQ_API_KEY=your_groq_api_key
# OCR_SPACE_API_KEY=your_ocr_api_key

# Run the server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd ../frontend

# Install dependencies
flutter pub get

# Run on desired platform
flutter run -d chrome        # Web
flutter run -d windows       # Windows
flutter run                  # Mobile (connect device/emulator)

πŸš€ Usage

Starting the Backend

cd backend
uvicorn src.main:app --reload --port 8000

Access the API documentation at: http://localhost:8000/docs

Running the Frontend

cd frontend
flutter run

API Health Check

curl http://localhost:8000/health

Response:

{
  "status": "healthy",
  "service": "Loan Underwriting & Prediction System",
  "version": "2.0.0"
}

πŸ“š API Documentation

Base URL

http://localhost:8000

Key Endpoints

1. Document-Based Underwriting

POST /underwrite
Content-Type: multipart/form-data

Parameters:
- file: Document image/PDF (required)
- loan_amount: float (optional)
- loan_term: int (optional)
- cibil_score: int (optional)
- income_annum: float (optional)
- ... (other overrides)

Response:
{
  "extracted": {...},
  "rule_checks": {...},
  "approval_probability": 0.78,
  "decision": "Approved",
  "explanation": "...",
  "missing_fields": []
}

2. Feature-Based Prediction

POST /model/predict

Body:
{
  "features": {
    "no_of_dependents": 2,
    "income_annum": 600000,
    "loan_amount": 500000,
    "loan_term": 12,
    "cibil_score": 750,
    ...
  },
  "threshold": 0.5
}

Response:
{
  "approval_probability": 0.82,
  "decision": "Approved",
  "threshold": 0.5
}

3. Batch Prediction

POST /model/predict_batch

Body:
{
  "records": [
    {"features": {...}},
    {"features": {...}}
  ],
  "threshold": 0.5
}

4. Model Schema

GET /model/schema

Response: Complete feature schema with descriptions

Authentication Endpoints (To be implemented)

POST /auth/login
POST /auth/signup
POST /auth/forgot-password

πŸ“± Frontend Architecture

frontend/lib/
β”œβ”€β”€ core/                      # Core configurations
β”‚   β”œβ”€β”€ config/               # App & API config
β”‚   β”œβ”€β”€ theme/                # App theme & colors
β”‚   β”œβ”€β”€ routes/               # Navigation
β”‚   β”œβ”€β”€ constants/            # Constants
β”‚   └── utils/                # Utilities
β”‚
β”œβ”€β”€ features/                  # Feature modules
β”‚   β”œβ”€β”€ splash/               # Splash screen
β”‚   β”œβ”€β”€ onboarding/           # Onboarding flow
β”‚   β”œβ”€β”€ auth/                 # Authentication
β”‚   β”‚   β”œβ”€β”€ screens/          # Login, signup, etc.
β”‚   β”‚   β”œβ”€β”€ widgets/          # Auth widgets
β”‚   β”‚   β”œβ”€β”€ services/         # Auth service
β”‚   β”‚   └── models/           # User models
β”‚   β”‚
β”‚   β”œβ”€β”€ user/                 # User dashboard
β”‚   β”‚   β”œβ”€β”€ screens/          # Home, profile, settings
β”‚   β”‚   └── widgets/          # Dashboard widgets
β”‚   β”‚
β”‚   β”œβ”€β”€ loan/                 # Loan management
β”‚   β”‚   β”œβ”€β”€ screens/          # Application, upload, status
β”‚   β”‚   β”‚   β”œβ”€β”€ loan_form_screen.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ document_upload_screen.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ loan_explanation_screen.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ ai_help_screen.dart
β”‚   β”‚   β”‚   └── loan_history_screen.dart
β”‚   β”‚   β”œβ”€β”€ widgets/          # Loan widgets
β”‚   β”‚   β”œβ”€β”€ services/         # Loan API services
β”‚   β”‚   └── models/           # Loan models
β”‚   β”‚
β”‚   β”œβ”€β”€ admin/                # Admin (mobile/tablet)
β”‚   β”‚   β”œβ”€β”€ screens/          # Management screens
β”‚   β”‚   β”‚   β”œβ”€β”€ manual_review_screen.dart
β”‚   β”‚   β”‚   └── review_detail_screen.dart
β”‚   β”‚   β”œβ”€β”€ widgets/          # Admin widgets
β”‚   β”‚   β”œβ”€β”€ services/         # Admin services
β”‚   β”‚   └── models/           # Admin models
β”‚   β”‚
β”‚   └── admin_web/            # Web-only monitoring
β”‚       β”œβ”€β”€ screens/          # Web dashboards
β”‚       β”‚   β”œβ”€β”€ admin_dashboard.dart
β”‚       β”‚   β”œβ”€β”€ bias_monitor.dart
β”‚       β”‚   β”œβ”€β”€ audit_log.dart
β”‚       β”‚   └── graphs.dart
β”‚       β”œβ”€β”€ widgets/          # Web widgets
β”‚       β”œβ”€β”€ services/         # Monitoring services
β”‚       └── models/           # Monitoring models
β”‚
└── shared/                    # Shared components
    β”œβ”€β”€ widgets/              # Reusable widgets
    β”œβ”€β”€ services/             # HTTP, storage, etc.
    β”œβ”€β”€ models/               # Common models
    β”œβ”€β”€ exceptions/           # Error handling
    └── extensions/           # Dart extensions

πŸ€– Machine Learning Pipeline

Model Training

cd backend
jupyter notebook "Training Code.ipynb"

Features Used (11 total)

  1. no_of_dependents - Number of dependents
  2. income_annum - Annual income
  3. loan_amount - Requested loan amount
  4. loan_term - Loan term in months
  5. cibil_score - Credit score (300-900)
  6. residential_assets_value - Residential property value
  7. commercial_assets_value - Commercial property value
  8. luxury_assets_value - Luxury assets value
  9. bank_asset_value - Bank deposits/savings
  10. education - Education level (encoded)
  11. self_employed - Employment type (binary)

Model Performance

  • Algorithm: XGBoost with hyperparameter tuning
  • Training Accuracy: ~95%
  • Validation Accuracy: ~92%
  • F1 Score: ~0.91
  • Model File: loan_xgb_pipeline.joblib

Rule Engine

Business rules applied before ML prediction:

  • βœ… Income reasonability check
  • βœ… CIBIL score minimum threshold
  • βœ… Loan-to-income ratio validation
  • βœ… Missing field detection
  • βœ… OCR confidence validation

🎨 Key Features Breakdown

1. Explainable AI

Every decision comes with:

  • Probability score
  • Rule check results
  • Feature importance
  • Clear explanation text

2. Bias Detection

Web dashboard monitors:

  • Approval rate by demographics
  • Score distribution fairness
  • Statistical parity checks
  • Disparate impact analysis

3. AI-Powered Help

Rejected applicants receive:

  • Reasons for rejection
  • Actionable improvement suggestions
  • What-if scenario analysis
  • Personalized guidance via Groq LLM

4. Multi-Level Decision Flow

Automatic Approval β†’ User gets instant result
Automatic Rejection β†’ AI help + explanation
Uncertain Cases β†’ Manual review by officer

πŸ”’ Environment Variables

Create a .env file in the backend/ directory:

# API Configuration
API_TITLE=Loan Underwriting & Prediction System
API_VERSION=2.0.0
DEBUG=False

# ML Model
MODEL_PATH=loan_xgb_pipeline.joblib
DEFAULT_APPROVAL_THRESHOLD=0.5

# OCR Service
OCR_SPACE_API_KEY=your_ocr_api_key_here
OCR_SPACE_BASE_URL=https://api.ocr.space/parse/image

# Groq API
GROQ_API_KEY=your_groq_api_key_here
GROQ_BASE_URL=https://api.groq.com/openai/v1/chat/completions
GROQ_MODEL=llama-3.1-8b-instant

# Optional: Gemini API (backup)
GEMINI_API_KEY=your_gemini_api_key_here

Getting API Keys


🀝 Contributing

We welcome contributions! Please follow these steps:

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

Development Guidelines

  • Follow PEP 8 for Python code
  • Follow Flutter/Dart style guide
  • Write tests for new features
  • Update documentation

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Team

DenaAI Development Team

H.M. Mehedi Hasan
H.M. Mehedi Hasan

Backend & ML Development
Chowdhury Shafahid Rahman
Chowdhury Shafahid Rahman

API Integration
Sumaiya Rahman Soma
Sumaiya Rahman Soma

UX/UI & Bias Detection
MD. Abu Bakar Siddique
MD. Abu Bakar Siddique

Frontend Development

πŸ™ Acknowledgments

  • FastAPI for the excellent web framework
  • XGBoost team for the ML library
  • Groq for LLM API access
  • OCR.space for document processing
  • Flutter team for the cross-platform framework

πŸ“ž Support

For support, email support@denai.com or open an issue on GitHub.

Built with ❀️ by the DenaAI Team

GitHub Stars GitHub Forks

About

DenaAI is an intelligent loan underwriting system that combines cutting-edge AI technologies to automate and enhance the loan approval process.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors