MortgageMind AI – Sprint 5.2 Completed | Document Management Module

Another productive sprint completed on MortgageMind AI, where the focus shifted from Loan Management to building a robust Document Management System using FastAPI, SQLAlchemy, PostgreSQL, Alembic, JWT Authentication, and Docker.

This sprint lays the foundation for upcoming AI-powered OCR and document intelligence features.

✅ What We Achieved

📄 Document Management Module

  • Designed and implemented the Document database model.
  • Established relationships between:
    • User → Loan
    • Loan → Documents
  • Added support for multiple documents per loan.

📤 Secure Document Upload

  • Built multipart file upload APIs using FastAPI.
  • Supported metadata capture including:
    • Document Name
    • Document Type
    • MIME Type
    • File Size
  • Implemented local storage abstraction for uploaded documents.

📂 Document APIs

Implemented authenticated REST endpoints for:

  • Upload Document
  • Get Documents by Loan
  • Get Document by ID
  • Delete Document

All APIs are secured using JWT authentication.

🗄 Repository & Service Architecture

Maintained a clean layered architecture by implementing:

  • Repository Layer
  • Service Layer
  • API Layer

This keeps business logic independent from the HTTP layer and makes future cloud storage integration straightforward.

🧾 Database Migrations

Created and managed schema evolution using Alembic:

  • Document table migration
  • Foreign key relationships
  • Database version tracking

🔐 Security

  • JWT-based authentication enforced on all document endpoints.
  • Users can access protected document APIs only after successful login.

📑 API Documentation

  • Generated OpenAPI/Swagger documentation.
  • Multipart file upload endpoints are documented automatically.
  • Verified API definitions through the generated OpenAPI specification.

🐳 Docker Environment

Verified the complete stack inside Docker:

  • FastAPI
  • PostgreSQL
  • pgAdmin
  • Alembic migrations

⚠ Challenges Faced

Every sprint involves debugging and learning. Some notable challenges included:

🔹 Alembic Migration Recovery

  • Encountered missing revision history after deleting migration files.
  • Rebuilt migration history and synchronized the database version state.
  • Restored a clean migration workflow.

🔹 Docker Database Initialization

  • Faced PostgreSQL version compatibility issues when switching images.
  • Recreated Docker volumes and initialized a clean PostgreSQL environment.

🔹 Foreign Key Dependencies

  • Document migration initially failed because the referenced users table was missing in the database.
  • Corrected migration sequencing and schema initialization.

🔹 FastAPI Router Debugging

  • Diagnosed router registration issues.
  • Verified route registration independently from OpenAPI generation.
  • Confirmed protected endpoints were functioning correctly.

🔹 Swagger/OpenAPI Investigation

  • Document APIs were accessible but initially not visible in Swagger when accessed through localhost.
  • Determined the issue was browser caching and origin-specific behavior (localhost vs 127.0.0.1), not the FastAPI application.
  • Verified that the OpenAPI specification correctly included all Document endpoints.

🔹 Authentication Validation

  • Verified secure JWT integration across the Document module.
  • Confirmed protected endpoints correctly returned 401 Unauthorized when accessed without a valid token.

🛠 Technology Stack

  • Python 3.12
  • FastAPI
  • SQLAlchemy 2.0
  • PostgreSQL
  • Alembic
  • Pydantic v2
  • JWT Authentication
  • Docker & Docker Compose
  • Swagger / OpenAPI
  • pgAdmin

📈 Progress Summary

Sprint 5.1

  • User Authentication
  • JWT Security
  • Loan CRUD APIs

Sprint 5.2 ✅

  • Document Management
  • Secure File Upload
  • Document APIs
  • Repository-Service Architecture
  • Dockerized Development
  • Database Migrations

Next Sprint (5.3)

The next milestone is to add AI capabilities:

  • OCR integration
  • Automatic document classification
  • Mortgage document data extraction
  • AI-assisted loan document analysis

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.