An AI-powered loan application platform built with Next.js, Google Cloud SQL, Google Cloud Storage, and a Multi-Agent AI system. This application enables users to apply for loans through an intuitive multi-step form, with automatic document upload and intelligent AI-driven loan decisions.
-
Multi-Step Loan Application Form
- Personal Information Collection
- Education Background
- Employment Details
- Loan Requirements
- Document Upload (Bank & Salary Statements)
-
AI Multi-Agent Processing System β NEW
- Bank Statement Analysis Agent
- Salary Statement Verification Agent
- External Verification Agent
- Loan Officer Decision Agent
- Intelligent risk scoring and loan recommendations
- Detailed reasoning and explanations
-
Cloud-Native Backend
- Google Cloud SQL (PostgreSQL) for data persistence
- Google Cloud Storage for document management
- Transaction-based data integrity
- Real-time file uploads
- Integration with AI Agent API
-
Modern Tech Stack
- Next.js 16 with App Router
- React 19 with Server Components
- TypeScript for type safety
- Tailwind CSS for styling
- FastAPI for AI Agent API
- Python 3.11+ with Google ADK
-
Security Features
- Input validation
- File type & size restrictions
- Parameterized database queries
- Secure credential management
Before you begin, ensure you have:
- Node.js 20+ installed
- Python 3.11+ installed
- Google Cloud Platform account
- Cloud SQL instance with PostgreSQL
- Cloud Storage bucket
- Service account with appropriate permissions
- Cloud SQL Proxy executable
Start all services with a single command:
# Make sure you have .env file configured
./start-all.shThis will start:
- β Cloud SQL Proxy (Port 5432)
- β AI Agent API Server (Port 8000)
- β Next.js Application (Port 3000)
Access the application at: http://localhost:3000
To stop all services:
./stop-all.sh
# or press Ctrl+C in the terminalIf you prefer to start services individually:
git clone <your-repo-url>
cd LoanAI
npm install
# Install Python dependencies for AI Agent
cd AI_agent
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
deactivate
cd ..cp .env.example .env
# Edit .env with your configurationRequired environment variables:
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAMEGCS_BUCKET_NAME,GCS_PROJECT_IDAI_AGENT_API_URL(default: http://localhost:8000)GOOGLE_APPLICATION_CREDENTIALS
Place your service account JSON key at:
config/gcp-credentials.json
cd config
./setup-proxy.sh
cd .../start-all.shOr start them individually:
Terminal 1 - Cloud SQL Proxy:
cd config
./cloud_sql_proxy --port 5432 PROJECT_ID:REGION:INSTANCETerminal 2 - AI Agent API:
cd AI_agent
./start_server.shTerminal 3 - Next.js:
npm run devOpen http://localhost:3000 to see the application.
AI Agent API documentation: http://localhost:8000/docs
Customer β Next.js Frontend β Next.js Backend API β Cloud SQL Database
β
AI Agent API (Port 8000)
β
Multi-Agent System
(Bank, Salary, Verification Agents)
β
Loan Officer Decision
β
Decision Result
For detailed architecture, see: INTEGRATION.md
LoanAI/
βββ src/
β βββ app/
β β βββ api/
β β β βββ loan-application/ # Main application API + AI integration
β β β βββ upload-document/ # File upload API
β β βββ about/ # About page
β β βββ contact/ # Contact page
β β βββ ...
β βββ components/
β β βββ feature/ # Core feature components
β β β βββ LoanForm.tsx
β β β βββ steps/ # Form step components
β β β βββ ...
β β βββ layout/ # Layout components
β β βββ ui/ # Reusable UI components
β βββ lib/
β β βββ db.ts # Database client
β β βββ storage.ts # Cloud Storage client
β βββ types/
β βββ form.ts # TypeScript interfaces
βββ AI_agent/ # β AI Multi-Agent System
β βββ api_server.py # FastAPI server
β βββ services/ # Data transformation services
β βββ loanai_agent/ # Agent system code
β β βββ agents/ # Individual agents
β β βββ models/ # Data models
β β βββ protocols/ # Communication protocols
β β βββ main.py # Application orchestrator
β βββ config/ # Agent configuration
β βββ requirements.txt # Python dependencies
β βββ start_server.sh # Start AI Agent API
βββ config/
β βββ gcp-credentials.json # GCP service account
β βββ cloud_sql_proxy # Proxy executable
β βββ setup-proxy.sh # Proxy setup script
βββ Docs/ # Documentation
β βββ Backend/ # Backend documentation
β βββ Agent/ # AI Agent documentation
βββ logs/ # Service logs
βββ scripts/
β βββ test-backend.js # Backend health check
β βββ database-queries.sql # Utility SQL queries
βββ config/
β βββ gcp-credentials.json # GCP service account key
βββ start-all.sh # β Master startup script
βββ stop-all.sh # Stop all services
βββ .env # Environment variables
βββ QUICK_START.md # β Quick reference guide
βββ INTEGRATION.md # β Integration documentation
βββ README.md # This file
Submit a complete loan application with customer data. Data is saved to Cloud SQL and automatically sent to AI Agent system for processing.
Request Body:
{
"firstName": "John",
"lastName": "Doe",
"personalId": "123456789",
"gender": "male",
"birthYear": "1990",
"phone": "+1234567890",
"address": "123 Main St",
"educationLevel": "bachelor",
"university": "University Name",
"employmentStatus": "employed",
"companyName": "Company Inc",
"monthlySalary": "5000",
"experienceYears": "5",
"loanPurpose": "personal",
"loanAmount": "10000",
"loanDuration": "24",
"bankStatementUrl": "gs://bucket/path",
"salaryStatementUrl": "gs://bucket/path"
}Response:
{
"success": true,
"customerId": "uuid",
"message": "Loan application submitted successfully and sent for AI processing"
}Upload documents to Cloud Storage.
Request: multipart/form-data
file: File objectdocumentType: Document type identifier
Process loan application through multi-agent system (async).
Get AI decision result for a customer.
Check processing status (pending/completed/failed).
Health check endpoint.
Interactive API documentation (Swagger UI).
customers- Main customer records with AI decision resultscustomer_personal_info- Personal informationcustomer_education- Education detailscustomer_employment- Employment informationloan_applications- Loan requestscustomer_documents- Document references
See Docs/Backend/ for detailed schema.
# Start all services
./start-all.sh # Start everything (recommended)
./stop-all.sh # Stop all services
# Individual services
npm run dev # Start Next.js only
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run test:backend # Test backend connectivity
npm run db:connect # Connect to database
# AI Agent
cd AI_agent && ./start_server.sh # Start AI Agent API# Test backend health
npm run test:backend
# Test AI Agent health
curl http://localhost:8000/health
# Connect to database
npm run db:connect
# View application logs
tail -f .next/server/app-paths.json- QUICKSTART.md - Quick setup guide
- BACKEND_README.md - Comprehensive backend documentation
- ARCHITECTURE.md - System architecture diagrams
- DEPLOYMENT_CHECKLIST.md - Production deployment guide
- IMPLEMENTATION_SUMMARY.md - Implementation details
- Environment variables for sensitive data
- Parameterized database queries (SQL injection prevention)
- File type and size validation
- Secure credential storage
- Transaction-based data integrity
.gitignorefor sensitive files
- Update environment variables for production
- Enable Cloud SQL SSL/TLS
- Configure HTTPS
- Set up monitoring and logging
- Configure backup strategy
- Test rollback procedures
See DEPLOYMENT_CHECKLIST.md for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
- Next.js team for the amazing framework
- Google Cloud Platform for infrastructure
- React team for the UI library
For issues and questions:
- Check the documentation
- Review the troubleshooting guide
- Open an issue on GitHub
Built with β€οΈ using Next.js, Google Cloud SQL, and Google Cloud Storage