This system provides a complete end-to-end loan application workflow with KYC verification, legal compliance checks, loan eligibility assessment, and dashboard analytics.
The application processes loan applications through multiple verification stages:
- KYC Verification - Validates identity, email, phone, and documents
- Legal Compliance Check - Screens for political connections, senior employee relatives, and sanctions
- Loan Eligibility Assessment - Evaluates credit score, debt-to-income ratio, and income sufficiency
- Final Decision - Approves or rejects based on all verification stages
- Notification - Sends alerts and emails to applicants
Each row represents one client's loan application with the following key columns:
- Basic Information: name, email, phone, region, country
- Financial Data: income, debt, credit_score, loan_amount, loan_purpose, dti_ratio
- KYC Status: kyc_status, kyc_verified_at, kyc_remarks
- Compliance Status: compliance_status, compliance_verified_at, compliance_remarks, political_connection, senior_relative
- Eligibility Status: eligibility_status, eligibility_verified_at, eligibility_remarks
- Final Status: final_status, final_decision_at, final_remarks
- Notifications: alert_sent, email_sent
Status values: PENDING, APPROVED, REJECTED
Health check endpoint
curl http://localhost:5003/Register a new user
curl -X POST http://localhost:5003/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "secure123"
}'User login
curl -X POST http://localhost:5003/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "secure123"
}'Get stock market data
curl http://localhost:5003/dataSimple loan eligibility check (original functionality)
curl -X POST http://localhost:5003/loan \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Smith",
"email": "jane@example.com",
"income": 75000,
"debt": 25000,
"credit_score": 720
}'Submit a new loan application with complete verification workflow
Request Body:
{
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"region": "AMERICAS",
"country": "United States",
"income": 85000,
"debt": 25000,
"credit_score": 720,
"loan_amount": 250000,
"loan_purpose": "Home Purchase",
"documents_uploaded": true,
"documents": ["ID_Proof", "Income_Statement", "Address_Proof"]
}Valid Regions: APAC, EMEA, AMERICAS, MEA, NA, SA, EU, ASIA
Example:
curl -X POST http://localhost:5003/loan-application/submit \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"region": "AMERICAS",
"country": "United States",
"income": 85000,
"debt": 25000,
"credit_score": 720,
"loan_amount": 250000,
"loan_purpose": "Home Purchase"
}'Response:
{
"message": "Loan application submitted and processed successfully",
"application": {
"application_id": "LOAN-20241108-ABC12345",
"name": "John Doe",
"kyc_status": "APPROVED",
"compliance_status": "APPROVED",
"eligibility_status": "APPROVED",
"final_status": "APPROVED",
"dti_ratio": 0.294,
...
}
}Get status of a specific application
Example:
curl http://localhost:5003/loan-application/status/LOAN-20241108-ABC12345List all loan applications with optional filtering
Query Parameters:
status: Filter by final status (PENDING, APPROVED, REJECTED)region: Filter by region (APAC, EMEA, AMERICAS, MEA)limit: Maximum number of results (default: 100)
Examples:
# Get all applications
curl http://localhost:5003/loan-application/list
# Get approved applications only
curl http://localhost:5003/loan-application/list?status=APPROVED
# Get applications from APAC region
curl http://localhost:5003/loan-application/list?region=APAC
# Get first 10 rejected applications
curl http://localhost:5003/loan-application/list?status=REJECTED&limit=10-
GET /loan-application/pending – List every submission awaiting manual approval.
curl http://localhost:5003/loan-application/pending
-
POST /loan-application/{application_id}/approve – Approve a pending request and trigger automated verification.
curl -X POST http://localhost:5003/loan-application/LOAN-20250101-ABCD1234/approve
-
POST /loan-application/{application_id}/reject – Reject a pending request (optional JSON body
{ "reason": "..." }).curl -X POST http://localhost:5003/loan-application/LOAN-20250101-ABCD1234/reject \ -H "Content-Type: application/json" \ -d '{"reason":"Bank statements missing"}'
Reprocess an application through the verification workflow
Example:
curl -X POST http://localhost:5003/loan-application/reprocess/LOAN-20241108-ABC12345Get overall statistics
Response:
{
"total_applications": 150,
"approved": 85,
"rejected": 60,
"pending": 5,
"approval_rate": 56.67
}Example:
curl http://localhost:5003/dashboard/overviewGet application statistics grouped by region
Response:
{
"regions": [
{
"region": "APAC",
"total": 45,
"approved": 25,
"rejected": 18,
"pending": 2
},
{
"region": "EMEA",
"total": 38,
"approved": 22,
"rejected": 15,
"pending": 1
},
...
]
}Example:
curl http://localhost:5003/dashboard/by-regionGet application statistics grouped by country
Response:
{
"countries": [
{
"country": "United States",
"region": "AMERICAS",
"total": 25,
"approved": 15,
"rejected": 10
},
...
]
}Example:
curl http://localhost:5003/dashboard/by-countryGet statistics on each verification stage
Response:
{
"kyc": {
"approved": 120,
"rejected": 30,
"pass_rate": 80.0
},
"compliance": {
"approved": 110,
"rejected": 40,
"pass_rate": 73.33,
"political_connections": 8,
"senior_relatives": 12
},
"eligibility": {
"approved": 90,
"rejected": 60,
"pass_rate": 60.0
}
}Example:
curl http://localhost:5003/dashboard/verification-statsGet financial metrics for approved applications
Response:
{
"average_credit_score": 715.5,
"average_dti_ratio": 0.32,
"average_loan_amount": 185000.0,
"total_loan_amount": 15725000.0,
"average_income": 92500.0
}Example:
curl http://localhost:5003/dashboard/financial-metricsGet application trends over time
Query Parameters:
days: Number of days to retrieve (default: 30)
Response:
{
"timeline": [
{
"date": "2024-11-08",
"total": 8,
"approved": 5,
"rejected": 3
},
...
]
}Example:
curl http://localhost:5003/dashboard/timeline?days=7- Email format validation
- Phone number validation (minimum 10 digits)
- Document upload verification
- Name validation (minimum 3 characters)
- Region and country validation
- Political connections screening (10% random for POC)
- Senior employee relative detection
- Sanctions list screening
- High-risk country check
- High-value transaction flagging (>$500,000)
- DTI Ratio: Must be < 40% (debt/income)
- Credit Score: Must be ≥ 650
- Income Sufficiency: Annual income ≥ 3x loan amount
- Maximum Loan: $1,000,000
- Minimum Income: $30,000
All three stages (KYC, Compliance, Eligibility) must be APPROVED for final approval.
- Start all services:
docker-compose up --build- The application will be available at
http://localhost:5003
To populate the database with sample loan applications:
# Inside the container
python generate_sample_data.py
# Or uncomment the line in start.sh and rebuild# Submit a loan application
curl -X POST http://localhost:5003/loan-application/submit \
-H "Content-Type: application/json" \
-d '{
"name": "Test User",
"email": "test@example.com",
"phone": "+1234567890",
"region": "AMERICAS",
"country": "United States",
"income": 80000,
"debt": 20000,
"credit_score": 720,
"loan_amount": 200000,
"loan_purpose": "Home Purchase"
}'
# Check the application status (replace with actual application_id from response)
curl http://localhost:5003/loan-application/status/LOAN-20241108-XXXXXXXX
# View dashboard analytics
curl http://localhost:5003/dashboard/overview
curl http://localhost:5003/dashboard/by-region
curl http://localhost:5003/dashboard/verification-statsThe dashboard endpoints provide data for visualizing:
- Regional Distribution: Applications by APAC, EMEA, AMERICAS, MEA regions
- Country-wise Breakdown: Detailed country-level statistics
- Approval Funnel: Pass rates at each verification stage
- Financial Metrics: Average credit scores, DTI ratios, loan amounts
- Timeline Trends: Application volume over time
Use these endpoints to build a frontend dashboard with charts showing:
- Pie charts for regional distribution
- Bar charts for country-wise applications
- Funnel charts for verification stages
- Line charts for timeline trends
- KPI cards for key metrics
All endpoints return appropriate HTTP status codes:
200: Success201: Created400: Bad Request (missing/invalid fields)404: Not Found409: Conflict (duplicate entry)500: Internal Server Error
- The system processes applications synchronously in the POC. In production, use asynchronous processing (Celery, Kafka, etc.)
- Email and alert notifications are simulated (logged to console). Integrate with actual email service in production.
- The verification logic uses simplified rules for POC. Implement real KYC, compliance, and credit check integrations in production.
- Database uses PostgreSQL (configure credentials via
.env). For other environments, updatedb.jsaccordingly.
- Asynchronous processing with Kafka/Celery
- Real email integration (SendGrid, AWS SES)
- Document upload and OCR processing
- Real-time dashboard with WebSockets
- Admin panel for manual review
- Audit logs and compliance reporting
- Integration with external credit bureaus
- Multi-factor authentication
- Role-based access control
- API rate limiting and authentication
Audit trail for manual approvals/rejections (most recent first).
curl http://localhost:5003/approval-logsUse ?limit=50 or ?application_id=LOAN-... to filter results.