This is a Django-based Credit Approval System designed to evaluate customer loan eligibility, manage customer data, and process loans. The application is fully dockerized, using PostgreSQL as the database, Redis as the message broker for background tasks with Celery, and Django Rest Framework for building APIs.
- Features
- Setup and Installation
- API Endpoints
- Running Celery Tasks
- Testing
- Usage
- Stopping the Application
- License
- Customer Management: Register new customers and store their details.
- Loan Processing: Create and manage loans with automatic eligibility checks.
- Credit Limit and Debt Tracking: Track approved limits, current debt, and loan repayments.
- Background Task Processing: Celery tasks for data ingestion and other background tasks.
- API Documentation: REST API endpoints using Django Rest Framework.
- Docker: Install Docker and Docker Compose (Docker installation guide).
- Basic knowledge of Python, Django, and REST APIs is recommended.
Configure the following environment variables in docker-compose.yml
:
POSTGRES_DB
: The name of the PostgreSQL database (e.g.,credit_db
).POSTGRES_USER
: The database username.POSTGRES_PASSWORD
: The database password.CELERY_BROKER_URL
: URL for the Celery broker (set toredis://redis:6379/0
by default).CELERY_RESULT_BACKEND
: URL for the Celery result backend (set toredis://redis:6379/0
by default).
-
Clone the repository and navigate to the project directory.
git clone https://github.com/himanshu-sharmav/credit_approval_system.git cd credit-approval-system
-
Run the below command for Python dependencies.
pip install requirements.txt
-
Build and start the Docker containers:
docker-compose up --build
-
Run database migrations:
docker-compose exec web python manage.py migrate
-
Create a superuser for accessing the Django admin (optional):
docker-compose exec web python manage.py createsuperuser
-
Create a .env File Create a .env file in the root of the project directory with the following content:
POSTGRES_DB=credit_db POSTGRES_USER=your_user POSTGRES_PASSWORD=your_password
CELERY_BROKER_URL=redis://redis:6379/0 CELERY_RESULT_BACKEND=redis://redis:6379/0 The application will be available at
http://127.0.0.1:8000
.
- URL:
/register/
- Method:
POST
- Request Body:
{ "first_name": "Alice", "last_name": "Smith", "age": 32, "monthly_income": 60000, "phone_number": "1122334455" }
- Description: Registers a new customer and calculates their approved credit limit.
- URL:
/check-eligibility/
- Method:
POST
- Request Body:
{ "customer_id": 1, "loan_amount": 300000, "interest_rate": 10, "tenure": 24 }
- Description: Checks if a customer is eligible for a loan based on credit score and existing debt.
- URL:
/create-loan/
- Method:
POST
- Request Body:
{ "customer_id": 1, "loan_id": 101, "loan_amount": 200000, "interest_rate": 12, "tenure": 12 }
- Description: Creates a new loan for a customer and calculates the monthly repayment amount.
- URL:
/view-loan/<id>/
- Method:
GET
- Description: Retrieves details of a specific loan by its primary key (
id
).
- URL:
/view-loans/<customer_id>/
- Method:
GET
- Description: Retrieves all loans associated with a specific customer.
This project uses Celery for background task processing with Redis as the broker.
To start a Celery worker:
docker-compose exec web celery -A credit_approval_system worker -l info
To run a scheduled job, use Celery Beat:
docker-compose exec web celery -A credit_approval_system beat -l info
To test the API endpoints, you can use tools like Postman or cURL with the following sample requests:
{
"first_name": "Alice",
"last_name": "Smith",
"age": 32,
"monthly_income": 60000,
"phone_number": "1122334455"
}
{
"customer_id": 1,
"loan_amount": 300000,
"interest_rate": 10,
"tenure": 24
}
To run Django’s built-in test suite:
docker-compose exec web python manage.py test
- Start Application: Run
docker-compose up --build
to start the application. - API Testing: Use Postman or any REST client to test the API endpoints as described.
- Admin Access: Access the Django admin at
http://127.0.0.1:8000/admin
(after creating a superuser).
To stop and remove the Docker containers, use:
docker-compose down
This project is licensed under the MIT License. See the LICENSE file for details.