Introduction
SpendWisely George provides a RESTful API built with FastAPI that manages financial transactions, portfolio tracking, and mutual fund holdings. The API integrates with Fold Money for transaction data and MFApi for mutual fund NAV information.Base URL
PORT environment variable (default: 8000).
API Architecture
The backend consists of four main functional areas:Authentication
- OTP-based login flow using Fold Money API
- Token management and session persistence
- Status checking for logged-in state
Transactions
- Fetches transaction history from Fold Money
- Stores data locally in SQLite database
- Manual sync endpoint for data refresh
Portfolio
- Real-time portfolio valuation
- NAV calculation using MFApi integration
- Aggregated total value across all holdings
Holdings
- CRUD operations for mutual fund holdings
- Local JSON file storage
- Scheme code and units tracking
Response Format
All API responses use JSON format. Successful responses return the requested data directly:Error Handling
Errors follow FastAPI’s HTTPException pattern with appropriate status codes:Error Response Structure
Common Status Codes
Request completed successfully
Invalid request parameters or authentication failure
Server-side error during processing (e.g., sync failure)
Example Error Response
Authentication Flow
The API uses a two-step OTP authentication process:- Request OTP: Send phone number to
/api/fold/login - Verify OTP: Submit OTP code to
/api/fold/verify - Token Storage: Tokens are stored in
unfold_config.yamlfor subsequent requests
Data Storage
The API uses multiple storage mechanisms:- unfold_config.yaml: Authentication tokens and user UUID
- unfold/db.sqlite: Transaction history from Fold Money
- holdings.json: User’s mutual fund holdings
CORS Configuration
The API is configured with permissive CORS settings for development:Rate Limiting
The API does not implement rate limiting, but be aware of external API limits:- Fold Money API: Subject to their rate limits
- MFApi: Public API with no documented rate limits
Next Steps
Authentication
Set up Fold Money OTP login
Transactions
Fetch and sync transaction data
Portfolio
Get real-time portfolio valuation
Holdings
Manage mutual fund holdings