Skip to content

Services Guide

This guide explains the service layer patterns and architecture in ReversePilot.

Service Layer Overview

Services encapsulate business logic separate from views and models, promoting code reusability and testability.

Service Locations

Loan Services

Location: loan/services/

  • loan_calculation.py: Principal limit and loan calculations
  • expected_rate.py: Expected rate calculations
  • interest_rate.py: Interest rate management
  • loan_documents_service.py: Document generation coordination
  • fee_sync_service.py: Fee synchronization

Integration Services

  • flood_api.py: FloodCert.org integration
  • cleartrust_api.py: ClearTrust integration
  • mismo_service/: MISMO XML generation

Service Patterns

Calculation Services

Example: loan_calculation.py

def get_hecm_loan(loan):
    """
    Calculate HECM loan proceeds.
    """
    # Calculation logic
    return calculation_results

Integration Services

Example: flood_api.py

def get_flood_zone(property_address):
    """
    Get flood zone from FloodCert.org.
    """
    # API call logic
    return flood_zone_data

Data Processing Services

Example: fee_sync_service.py

def sync_fees_for_loan(loan):
    """
    Sync fees for a loan.
    """
    # Fee synchronization logic
    pass

Service Usage

In Views

from loan.services.loan_calculation import get_hecm_loan

class LoanCalculationView(APIView):
    def post(self, request):
        loan = get_loan(request.data.get('loan'))
        result = get_hecm_loan(loan)
        return Response(result)

In Models

from loan.services.fee_sync_service import sync_fees_for_loan

class Loan(models.Model):
    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        sync_fees_for_loan(self)

Best Practices

  1. Single Responsibility: Each service has one clear purpose
  2. Stateless: Services should be stateless when possible
  3. Error Handling: Proper error handling and logging
  4. Documentation: Clear docstrings and comments
  5. Testing: Services should be easily testable

Next Steps


For service questions, refer to the code or contact the development team.