System Architecture
This document provides a detailed overview of the ReversePilot system architecture, including database schema, service layer, and integration architecture.
Technology Stack
Backend
- Framework: Django 4.2+
- Language: Python 3.x
- API: Django REST Framework
- Authentication: OAuth2 Provider
- Database: PostgreSQL (production) / SQLite (development)
- Cache: Redis
- File Storage: AWS S3
Frontend
- Web application (separate repository)
- RESTful API consumption
- OAuth2 authentication
Application Structure
dc_los_django/
├── company/ # Company and user management
├── loan/ # Loan management and processing
├── documents/ # Document generation
├── apps/
│ ├── credit_report/ # Credit reporting integration
│ └── fha_integration/ # FHA Connection integration
└── dc_los_django/ # Project settings and configuration
Database Schema
Core Models
Company Models
- Company: Company/organization information
- User: System users with hierarchy and permissions
- PermissionGroup: Collections of permissions
- CompanySigner: Authorized document signers
Loan Models
- Loan: Main loan application record
- LoanProduct: Product configuration (HECM, proprietary)
- Borrower: Loan applicant information
- Property: Subject property information
- Fee: Loan fees and charges
- Appraisal: Property appraisal information
- Title: Title information
- CreditReport: Credit report data
Key Relationships
Company
├── Users (1:N)
├── LoanProducts (1:N)
└── Loans (1:N)
├── Borrowers (1:N)
├── Property (1:1)
├── Fees (1:N)
├── CreditReports (1:N)
└── Documents (1:N)
Service Layer
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
- fee_sync_service.py: Fee synchronization
Integration Services
- flood_api.py: FloodCert.org integration
- cleartrust_api.py: ClearTrust integration
- mismo_service/: MISMO XML generation
Document Generation
Hard-Coded Documents
Location: documents/hard_coded_documents/
- HTML Templates: Jinja2 templates for document generation
- Python Data Generators: Functions that populate template data
- Generator: Main document generation orchestrator
Document Flow
- User requests document generation
- System selects appropriate template
- Data generator extracts loan data
- Template is rendered with data
- HTML is converted to PDF
- PDF is stored and returned
Integration Architecture
Credit Reporting (MeridianLink)
- XML-based API integration
- MISMO 3.4 format
- Automatic data parsing
- PDF and XML storage
Flood Certificates (FloodCert.org)
- REST API integration
- Property address-based lookup
- Automatic flood zone determination
FHA Connection
- SOAP/XML integration
- Multiple endpoint support
- Credential management
- Response parsing
MERS
- MIN generation
- Registration API
- Loan tracking
Authentication & Authorization
OAuth2 Authentication
- Token-based authentication
- Refresh token support
- Token expiration
- Scope-based permissions
Permission System
- Permission groups
- Module-based permissions
- Role assignment
- Status transition permissions
Data Flow
Loan Creation Flow
- User creates loan via API
- System validates borrower age
- System selects appropriate loan product
- System creates loan record
- System creates initial fees
- System creates borrower and property records
Document Generation Flow
- User requests document
- System loads template
- System calls data generator
- System renders template with data
- System converts to PDF
- System stores PDF
- System returns PDF to user
Calculation Flow
- User requests calculation
- System retrieves loan data
- System retrieves current rates
- System calculates principal limit
- System calculates set-asides
- System returns calculation results
Caching Strategy
Redis Cache
- Calculation results
- Rate data
- User sessions
- API response caching
File Storage
AWS S3
- Document PDFs
- Credit report files
- Appraisal documents
- Other loan documents
Security
Data Protection
- Encrypted data storage
- Secure file storage
- Encrypted credentials
- Audit logging
Access Control
- OAuth2 authentication
- Permission-based authorization
- Role-based access
- Status transition controls
Deployment Architecture
Production Environment
- Django application server (Gunicorn)
- PostgreSQL database
- Redis cache
- AWS S3 storage
- Load balancer
- SSL/TLS encryption
Development Environment
- Django development server
- SQLite database
- Local file storage
- Development tools
Performance Considerations
Database Optimization
- Indexed fields
- Query optimization
- Connection pooling
- Database replication (production)
Caching
- Calculation result caching
- Rate data caching
- Document template caching
- API response caching
Async Processing
- Background tasks for:
- Credit report processing
- Document generation
- Email notifications
- Report generation
Monitoring & Logging
Logging
- Application logs
- API access logs
- Error logs
- Audit logs
Monitoring
- Application performance
- Database performance
- API response times
- Error rates
Next Steps
- Development Guide - Development setup
- Models Guide - Data models
- Services Guide - Service layer
For architecture questions, contact the development team.