A fully functional Django + DRF + Celery + Docker based credit approval system that implements loan eligibility checks, customer registration, and loan management.
- Customer Registration with automatic credit limit calculation
- Loan Eligibility Check with dynamic credit scoring
- Loan Creation with approval workflow
- Excel Data Ingestion using Celery background tasks
- RESTful APIs with proper serialization
- PostgreSQL Database with proper decimal handling
- Redis + Celery for background task processing
- Fully Dockerized with one-command deployment
- Unit Tests for critical functionality
- Backend: Django 4.2+, Django Rest Framework
- Database: PostgreSQL
- Task Queue: Celery + Redis
- Data Processing: pandas, openpyxl
- Containerization: Docker + docker-compose
- Web Server: Gunicorn
credit_system/
├── credit_system/ # Django project settings
│ ├── __init__.py
│ ├── celery.py # Celery configuration
│ ├── settings.py # Django settings
│ ├── urls.py # Main URL routing
│ └── wsgi.py # WSGI application
├── loans/ # Main application
│ ├── migrations/ # Database migrations
│ ├── management/
│ │ └── commands/
│ │ └── enqueue_ingest.py # Data ingestion command
│ ├── __init__.py
│ ├── admin.py # Django admin configuration
│ ├── apps.py # App configuration
│ ├── models.py # Database models
│ ├── serializers.py # API serializers
│ ├── views.py # API views
│ ├── urls.py # App URL routing
│ ├── tasks.py # Celery tasks
│ ├── utils.py # Utility functions
│ └── tests.py # Unit tests
├── data/ # Excel data files (mounted)
│ ├── customer_data.xlsx
│ └── loan_data.xlsx
├── Dockerfile # Docker image configuration
├── docker-compose.yml # Multi-container setup
├── requirements.txt # Python dependencies
├── manage.py # Django management script
├── .env # Environment variables
├── .env.example # Environment template
└── README.md # This file
customer_id: Unique identifierfirst_name,last_name: Name fieldsage: Customer agephone_number: Contact informationmonthly_salary: Monthly incomeapproved_limit: Credit limit (calculated as 36x monthly salary, rounded to nearest lakh)current_debt: Outstanding loan amountcreated_at: Registration timestamp
loan_id: Unique loan identifiercustomer: Foreign key to Customerloan_amount: Principal amounttenure: Loan duration in monthsinterest_rate: Annual interest ratemonthly_repayment: EMI amountemis_paid_on_time: Number of EMIs paid punctuallystart_date,end_date: Loan periodcreated_at: Creation timestamp
The system calculates a credit score (0-100) based on:
- EMIs Paid On Time (35 points): Percentage of EMIs paid punctually
- Number of Past Loans (20 points): Credit history depth
- Loan Activity in Current Year (20 points): Recent credit activity
- Loan Volume vs Approved Limit (25 points): Credit utilization ratio
- Score > 50: Approved with requested interest rate
- 30 < Score ≤ 50: Approved with minimum 12% interest rate
- 10 < Score ≤ 30: Approved with minimum 16% interest rate
- Score ≤ 10: Not approved
Register a new customer.
Request:
{
"first_name": "Ravi",
"last_name": "Kumar",
"age": 25,
"monthly_income": 50000,
"phone_number": "9999999999"
}Response:
{
"customer_id": 1,
"name": "Ravi Kumar",
"age": 25,
"monthly_income": 50000.00,
"approved_limit": 1800000.00,
"phone_number": "9999999999"
}Check loan eligibility for a customer.
Request:
{
"customer_id": 1,
"loan_amount": 300000,
"interest_rate": 10,
"tenure": 24
}Response:
{
"customer_id": 1,
"approval": true,
"interest_rate": 10.00,
"corrected_interest_rate": 12.00,
"tenure": 24,
"monthly_installment": 14204.28
}Create a new loan after eligibility check.
Request:
{
"customer_id": 1,
"loan_amount": 300000,
"interest_rate": 10,
"tenure": 24
}Response:
{
"loan_id": 1,
"customer_id": 1,
"loan_approved": true,
"message": "Loan approved with corrected interest rate: 12.00%",
"monthly_installment": 14204.28
}View details of a specific loan.
Response:
{
"loan_id": 1,
"customer": {
"id": 1,
"first_name": "Ravi",
"last_name": "Kumar",
"phone_number": "9999999999",
"age": 25
},
"loan_amount": 300000.00,
"interest_rate": 12.00,
"monthly_installment": 14204.28,
"tenure": 24
}View all loans for a customer.
Response:
[
{
"loan_id": 1,
"loan_amount": 300000.00,
"interest_rate": 12.00,
"monthly_installment": 14204.28,
"repayments_left": 4
}
]- Docker
- docker-compose
- Clone the repository:
git clone https://github.com/your-username/credit_system.git
cd credit_system- Copy environment configuration:
cp .env.example .env-
Place Excel data files: Place your
customer_data.xlsxandloan_data.xlsxfiles in the./data/directory.Note: Sample CSV files are provided in the data directory. Convert them to Excel format or use your own data files with the same column structure.
-
Build and start services:
docker-compose up --build -d- Run database migrations:
docker-compose exec web python manage.py migrate- Ingest Excel data (optional):
docker-compose exec web python manage.py enqueue_ingest- Create superuser (optional):
docker-compose exec web python manage.py createsuperuser- API: http://localhost:8000
- Admin Panel: http://localhost:8000/admin
- PostgreSQL: localhost:5432
- Redis: localhost:6379
docker-compose exec web python manage.py testRegister Customer:
curl -X POST http://localhost:8000/register \
-H "Content-Type: application/json" \
-d '{
"first_name": "Ravi",
"last_name": "Kumar",
"age": 25,
"monthly_income": 50000,
"phone_number": "9999999999"
}'Check Eligibility:
curl -X POST http://localhost:8000/check-eligibility \
-H "Content-Type: application/json" \
-d '{
"customer_id": 1,
"loan_amount": 300000,
"interest_rate": 10,
"tenure": 24
}'Create Loan:
curl -X POST http://localhost:8000/create-loan \
-H "Content-Type: application/json" \
-d '{
"customer_id": 1,
"loan_amount": 300000,
"interest_rate": 10,
"tenure": 24
}'View Loan:
curl http://localhost:8000/view-loan/1View Customer Loans:
curl http://localhost:8000/view-loans/1| customer_id | first_name | last_name | age | phone_number | monthly_salary | approved_limit | current_debt |
|---|---|---|---|---|---|---|---|
| 1 | Ravi | Kumar | 25 | 9999999999 | 50000.00 | 1800000.00 | 0.00 |
| loan_id | customer_id | loan_amount | tenure | interest_rate | monthly_repayment | emis_paid_on_time | start_date | end_date |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 300000.00 | 24 | 10.50 | 14500.00 | 20 | 2023-01-15 | 2024-12-15 |
View application logs:
docker-compose logs webView Celery worker logs:
docker-compose logs workerView database logs:
docker-compose logs db- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your local configuration- Start PostgreSQL and Redis:
docker-compose up db redis -d- Run migrations:
python manage.py migrate- Start development server:
python manage.py runserver- Start Celery worker:
celery -A credit_system worker --loglevel=info- Change default passwords and secret keys
- Use environment-specific configurations
- Set up proper logging and monitoring
- Configure backup strategies for database
- Use a reverse proxy (nginx) for production
- Implement rate limiting and authentication
- Set up SSL certificates
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
For support and questions, please create an issue in the repository.