A comprehensive backend system for UBL's Loan Origination System, designed to handle multiple product types including Auto Loans, Cash Plus, Credit Cards, and more.
The ILOS backend supports:
- ETB (Existing to Bank) customers with automatic data population from CIF
- NTB (New to Bank) customers with manual data entry
- Multiple product types: Auto Loan, Cash Plus, Credit Cards, Ameen Drive, SME, etc.
- Comprehensive validation using Zod schemas
- PostgreSQL database with normalized schema
- Node.js (v16 or higher)
- PostgreSQL database (local or cloud like Neon)
- npm or yarn
-
Clone and Install Dependencies
cd ILOS-backend npm install -
Environment Configuration
cp env.example .env
Edit
.envwith your database configuration:DATABASE_URL=postgresql://username:password@hostname:port/database_name PORT=5000 NODE_ENV=development
-
Initialize Database
npm run init-db
-
Start the Server
# Development mode with auto-reload npm run dev # Production mode npm start
-
Verify Installation Visit
http://localhost:5000/healthto confirm the server is running.
The system uses a normalized PostgreSQL schema with the following main tables:
cif_customers- Customer Information File (ETB customers)applications- Main application recordspersonal_details- Customer personal informationaddress_details- Current/permanent addressesemployment_details- Employment informationreference_contacts- Reference contactsbanking_details- Banking relationships
autoloan_applications- Auto loan specific datacashplus_applications- Cash Plus loan datacredit_card_applications- Credit card applicationsvehicle_details- Vehicle information (for auto loans)insurance_details- Insurance information
POST /getNTB_ETB
Content-Type: application/json
{
"cnic": "12345-1234567-1"
}Response for ETB Customer:
{
"cnic": "12345-1234567-1",
"status": "ETB",
"consumerId": "ETB-123456",
"isExisting": true,
"cifDetails": {
"consumerId": "ETB-123456",
"fullName": "John Doe",
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@email.com",
"phoneNo": "03001234567",
// ... other CIF details
}
}Response for NTB Customer:
{
"cnic": "98765-9876543-2",
"status": "NTB",
"consumerId": "NTB-6543-789123",
"isExisting": false
}GET /cif/{consumerId}POST /api/autoloan/create
Content-Type: application/json
{
"application": {
"consumerId": "ETB-123456",
"cnic": "12345-1234567-1",
"customerStatus": "ETB",
"productType": "autoloan",
"desiredAmount": 2000000,
"tenureMonths": 60,
"purpose": "Vehicle Purchase"
},
"personalDetails": {
"title": "Mr",
"firstName": "John",
"lastName": "Doe",
"cnic": "12345-1234567-1",
"dateOfBirth": "1990-01-01",
"gender": "Male",
"maritalStatus": "Single",
// ... other personal details
},
"currentAddress": {
"addressType": "current",
"street": "123 Main Street",
"city": "Karachi",
"mobile": "03001234567",
// ... other address details
},
"employmentDetails": {
"employmentType": "salaried",
"companyName": "ABC Company",
"designation": "Software Engineer",
"basicSalary": 150000,
"grossSalary": 180000,
// ... other employment details
},
"references": [
{
"referenceType": "professional",
"name": "Reference Name",
"relation": "Colleague",
"phone": "03009876543",
"address": "Reference Address",
"city": "Karachi",
"occupation": "Manager"
}
],
"vehicleDetails": {
"vehicleType": "car",
"make": "Honda",
"model": "Civic",
"yearOfManufacture": 2023,
"vehiclePrice": 3500000,
"downPayment": 1500000,
"financingAmount": 2000000
},
// ... other required sections
}POST /api/cashplus/create
Content-Type: application/jsonPOST /api/creditcard/create
Content-Type: application/jsonGET /api/autoloan/{applicationId}
GET /api/cashplus/{applicationId}
GET /api/creditcard/{applicationId}GET /api/autoloan?page=1&limit=10&status=pending&customerStatus=ETB
GET /api/cashplus?page=1&limit=10
GET /api/creditcard?page=1&limit=10PATCH /api/autoloan/{applicationId}/status
Content-Type: application/json
{
"status": "approved"
}The system uses Zod for comprehensive validation:
- CNIC Format:
12345-1234567-1 - Phone Format:
03001234567or+923001234567 - Email Format: Standard email validation
- Date Format: ISO date strings
- Amount Limits: Product-specific minimum/maximum amounts
- PB enters CNIC
- System checks CIF database
- If found (ETB), auto-populates form fields
- PB reviews and submits application
- Data saved to application tables
- PB enters CNIC
- System creates new consumer ID (NTB-xxx)
- PB manually fills all form fields
- Data saved to both CIF and application tables
ILOS-backend/
βββ db.js # Database connection
βββ server.js # Main server file
βββ customerService.js # Customer-related services
βββ schema.sql # Database schema
βββ init-db.js # Database initialization
βββ routes/ # API route handlers
β βββ autoloan.js
β βββ cashplus.js
β βββ creditcard.js
β βββ ...
βββ schemas/ # Validation schemas
β βββ validationSchemas.js
βββ README.md
- Create Product Schema in
schemas/validationSchemas.js - Add Database Table in
schema.sql - Create Route Handler in
routes/ - Register Route in
server.js
Copy env.example to .env and configure:
DATABASE_URL=postgresql://username:password@hostname:port/database_name
PORT=5000
NODE_ENV=developmentnpm run dev- Start development server with auto-reloadnpm start- Start production servernpm run init-db- Initialize database with schemanpm run setup- Full setup (install + init-db)
The API returns standardized error responses:
{
"error": "Validation failed",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": ["personalDetails", "firstName"],
"message": "Required"
}
]
}- Database indexes on frequently queried columns
- Pagination for list endpoints
- Efficient joins for application details
- Connection pooling for database queries
- Input validation with Zod schemas
- SQL injection prevention with parameterized queries
- CORS enabled for frontend integration
- Environment-based configuration
The system can be tested using tools like Postman or curl. A health check endpoint is available at /health.
For questions or issues:
- Check the API documentation above
- Verify database connection and schema
- Check server logs for detailed error messages
- Ensure all required fields are provided in requests
- Set
NODE_ENV=production - Use secure database credentials
- Enable SSL for database connections
- Set up proper logging
- Configure reverse proxy (nginx)
- Set up monitoring and health checks
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]This backend has been optimized for Vercel serverless deployment with all Express routes converted to serverless functions.
- Install dependencies:
npm install- Create
.envfile with:
DB_HOST=your_database_host
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
DB_PORT=3306
- Run the development server:
npm run dev- Push code to GitHub
- Import project in Vercel
- Set environment variables from
.vercel-env-template
See DEPLOYMENT-GUIDE.md for detailed instructions.
GET /health- Health checkPOST /getNTB_ETB- Customer status lookupGET /cif/:consumerId- CIF details
POST /api/applications- Create applicationGET /api/applications- Get applicationsGET /api/applications/:id- Get application by IDPUT /api/applications/:id- Update applicationDELETE /api/applications/:id- Delete application
/api/personal-details- Personal details management/api/current-address- Current address management/api/permanent-address- Permanent address management/api/employment-details- Employment details management/api/reference-contacts- Reference contacts management/api/vehicle-details- Vehicle details management/api/insurance-details- Insurance details management/api/contact-details- Contact details management/api/verification- Verification management
/api/autoloan- Auto loan applications/api/cashplus- Cash plus applications/api/creditcard- Credit card applications
- Express routes converted to serverless functions
- CORS handling for all endpoints
- Database connection pooling
- Error handling middleware
- Customer data formatting
For full deployment instructions of both frontend and backend, see COMPLETE-DEPLOYMENT-GUIDE.md in the root directory.
This backend provides a robust foundation for the ILOS system with proper data validation, comprehensive API endpoints, and support for multiple product types while handling both ETB and NTB customer flows efficiently.