Lenda Finance
Full StackLive on VercelA full-stack lending platform where users deposit real-world collateral (property, crypto, vehicles), borrow credit against it, and track their financial position in real time. Built with a FastAPI backend on PostgreSQL/AWS RDS and a Next.js 16 dashboard with TanStack Query and NextAuth.js.
Core Features
Real-World Collateral
Users deposit property, crypto, or vehicles as collateral. Each asset type carries its own depreciation rate: property 1%, crypto 5%, car 10%.
Credit Against Collateral
Available credit equals total deposited assets minus outstanding loans. Users can only borrow up to their available credit. Default interest rate: 5%.
Financial Position Tracking
Real-time dashboard tracks each user's position : collateral value, outstanding debt, available credit, and repayment history across all loans.
Loan Lifecycle Management
Full loan lifecycle: pending → approved → repaid. Supports partial and full repayments, plus batch repayment across multiple loans in a single request.
Layered Architecture
Clean separation of concerns: Controller (endpoints) → Service (business logic) → Repository (DB queries). Pydantic schemas enforce request/response validation throughout.
Secure Authentication
NextAuth.js v4 with Credentials provider and JWT sessions. Passwords hashed with Passlib + bcrypt. Auth-protected dashboard route group via Next.js middleware.
Architecture
The system is split into two independently deployable services: a FastAPI REST API handling all business logic and persistence, and a Next.js 16 dashboard that consumes the API via an Axios service layer and TanStack Query for server state management.
Backend: FastAPI
main.py: Controller layer (all endpoints)service.py: Business logicrepository.py: Database queriesmodels.py: SQLAlchemy ORM modelsschemas.py: Pydantic request/response schemasrules.py: Business rules (asset types, statuses)- Alembic for database migrations
- Pytest test suite
Frontend: Next.js 16
- Auth-protected
(dashboard)route group - Pages: Overview, Users, Assets, Loans, Settings
- TanStack Query hooks for server state
- Axios service layer for all API calls
- Recharts for data visualizations
- Tailwind CSS v4 + Solar icons (Iconify)
- Sonner toast notifications
- NextAuth middleware proxy for route protection
Tech Stack
| Layer | Technology |
|---|---|
| API Framework | FastAPI |
| ORM | SQLAlchemy + Alembic migrations |
| Validation | Pydantic (request/response + settings) |
| Database | PostgreSQL on AWS RDS |
| Auth (backend) | Passlib + bcrypt (password hashing) |
| Frontend Framework | Next.js 16: App Router |
| Language | TypeScript |
| Styling | Tailwind CSS v4 |
| State Management | TanStack Query (server state) |
| Auth (frontend) | NextAuth.js v4: Credentials + JWT |
| Charts | Recharts |
| HTTP Client | Axios |
| Deployment | Vercel (frontend) |
API Reference
All endpoints are defined in the FastAPI backend. Authentication uses a POST to /auth/login which returns a token used for protected routes.
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/login | Authenticate user (email + password) |
| POST | /users | Register a new user |
| GET | /users | List all users |
| GET | /users/{user_id} | Get user by ID |
| POST | /assets | Deposit a new asset |
| GET | /assets | List all assets |
| POST | /borrow | Request a loan against available credit |
| GET | /loans | List all loans |
| POST | /repay/{loan_id} | Repay a loan (partial or full) |
| POST | /repay/batch | Batch repay multiple loans |
| GET | /positions/{user_id} | Get user's full financial position |
Data Model
Three core tables managed by SQLAlchemy ORM with Alembic migrations. All relationships are enforced at the database level with foreign key constraints.
users
id: Primary keyname: Full nameemail: Unique identifierpassword_hash: bcrypt hash
assets
id: Primary keyuser_id: FK → userstype: property | crypto | carvalue: Deposited valuecreated_at: Timestamp
loans
id: Primary keyuser_id: FK → usersamount: Loan principalamount_repaid: Running repaymentinterest_rate: Default 5%status: pending | approved | repaidcreated_at: Timestamp
Business Rules
| Rule | Detail |
|---|---|
| Allowed asset types | property, crypto, car |
| Depreciation: property | 1% per period |
| Depreciation: crypto | 5% per period |
| Depreciation: car | 10% per period |
| Default interest rate | 5% |
| Available credit formula | Total deposited assets − total outstanding loans |
| Borrow limit | Users cannot borrow beyond their available credit |
Deployment
Frontend
- Deployed on Vercel (auto-deploy on push)
- Live at lenda-finance.vercel.app
- Next.js 16 App Router + Turbopack
- Environment: NEXT_PUBLIC_API_URL, NEXTAUTH_URL, NEXTAUTH_SECRET
Backend & Database
- FastAPI served via Uvicorn
- PostgreSQL on AWS RDS
- Alembic migrations for schema management
- Environment: DATABASE_URL, SECRET_KEY, FRONTEND_URL