FastAPI-based M-Pesa credit assessment API with MongoDB and Google Cloud Run deployment.
# M-Pesa Credit Assessment API
A secure REST API for credit assessment based on M-Pesa transaction statements from Kenya. This FastAPI service analyzes transaction patterns to calculate credit scores and risk categories for users.
## 🚀 Live Deployment
**API URL:** `
mpesa-api-xxxxx-uc.a.run.app` (Replace with your actual Cloud Run URL)
**Health Check:** `GET
mpesa-api-xxxxx-uc.a.run.app`
## 📋 Table of Contents
- Features
- Architecture
- Project Structure
- Quick Start
- API Documentation
- Credit Scoring Algorithm
- Environment Variables
- Docker Deployment
- Google Cloud Run Deployment
- Testing
- Design Decisions
- Troubleshooting
## ✨ Features
- **Secure Authentication**: HTTP Basic Auth with bcrypt password hashing
- **Credit Scoring**: Intelligent algorithm analyzing 5 key financial factors
- **MongoDB Integration**: Efficient queries with proper indexing
- **Docker Support**: Containerized for easy deployment
- **Cloud Ready**: Deployed on Google Cloud Run
- **Comprehensive Testing**: Unit tests with pytest
- **Auto Documentation**: OpenAPI/Swagger docs
- **CORS Support**: Ready for frontend integration
## 🏗️ Architecture
```
┌─────────────────┐ ┌─────────────────-┐ ┌─────────────────┐
│ Client App │───▶│ FastAPI API │───▶│ MongoDB Atlas │
│ │ │ │ │ │
│ - Web Frontend │ │ - Authentication │ │ - User Data │
│ - Mobile App │ │ - Credit Scoring │ │ - Transactions │
│ - Postman │ │ - Data Validation│ │ - Indexes │
└─────────────────┘ └─────────────────-┘ └─────────────────┘
```
### Core Components
- **FastAPI Application**: Main API server with async support
- **MongoDB Database**: Stores user profiles and transaction data
- **Credit Scorer**: Rule-based algorithm for risk assessment
- **Authentication**: Secure user verification system
- **Docker Container**: Portable deployment unit
## 📁 Project Structure
``` …