Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Approach for making a Django Rest Framework (DRF) Workflow

I'm building a business application which will support multiple Loan products.

for eg: Home Loan, Car Loan, Personal Loan, E-commerce Loan.

The major steps involved are :

  1. Onboarding (Generating Lead)
  2. User Info (and Verification)
  3. Loan Info (Credibility)
  4. Disbursement

An example of the business flow is :

  1. Customer comes on-board, registers his mobile number, verifies it with OTP

  2. fills his personal information (validate it)

  3. provides the loan amount

  4. check loan credibility

  5. Allocate funds (after XYZ validations)

  6. Provide Bank Account details

  7. Verify Bank Account (only after you have abc information)

  8. Do eKYC

  9. Disburse

Now, I'm building the same using Django REST Framework for building Web APIs. However, there's a concern.

In another product of ours, the flow can be different. Step 4 and Step 6 can be interchanged, but Step 7 need to be done at the same position. Basically, I should have the flexibility to reshuffle the activities (nodes).

As of right now, the APIs written (although modular) is specific for only one product. How can I use DRF as a workflow approach? or use any library on top of DRF that can govern the flow.

like image 785
PythonEnthusiast Avatar asked Nov 07 '22 02:11

PythonEnthusiast


1 Answers

We had a similar usecase and used a flow library which would capture the entire worflow based on a condition driven flow.

You can look into Viewflow: https://github.com/viewflow/viewflow

Basically it's like setting a flow and utilizing the condition to direct and redirect to different mechanism. Their simple quickstart page tells you how you can achive it: http://docs.viewflow.io/viewflow_quickstart.html

I just tried some sample flow in your case:

class CustomerProcessFlow(Flow):
    process_class = CustomerProcess

    start = (
        flow.Start(
            views.CustomerOnBoardView # Let's say this is your customer onboard view
            fields=["customer_name", "customer_address", "customer_phone"]
        ).Permission(
            auto_create=True
        ).Next(this.validate_customer)
    )

    validate_customer = (
        flow.View(
            views.ValidateCustomerDataView # Validation for customer data,
            fields=["approved"]
        ).Permission(
            auto_create=True
        ).Next(this.loan_amount)
    )

    loan_amount = (
        flow.View(
            views.LoanView # Provide Loan
            fields=["loan_amount"]
        ).Permission(
            auto_create=True
        ).Next(this.check_customer_association)
    )

    check_customer_association = (
        flow.If(lambda customer_association: ! customer.type.normal)
        .Then(this.step_4_6)
        .Else(this.step_6_4)
    )

    step_4_6 = (
        flow.Handler ( this.check_load_credibility_data )
        .Next( this.provide_bank_details_data )
    )

    step_6_4 = (
        flow.Handler( this.provide_bank_details_data )
        .Next(this.check_load_credibility)
    )

    this.check_load_credibility = (
        flow.Handler( this.check_load_credibility_data )
        .Next( this.end )
    )

    this.provide_bank_details_data = (
        flow.Handler( this.provide_bank_details_data )
        .Next(this.end)
    )

    end = flow.End()

    def check_load_credibility_data(self, customer):
        # Load credibility

    def provide_bank_details_data(self, customer):
        # Bank Details

An example can be seen here

like image 112
Nagaraj Tantri Avatar answered Nov 11 '22 14:11

Nagaraj Tantri