Lenda Finance

Full StackLive on Vercel

A 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 logic
  • repository.py: Database queries
  • models.py: SQLAlchemy ORM models
  • schemas.py: Pydantic request/response schemas
  • rules.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

LayerTechnology
API FrameworkFastAPI
ORMSQLAlchemy + Alembic migrations
ValidationPydantic (request/response + settings)
DatabasePostgreSQL on AWS RDS
Auth (backend)Passlib + bcrypt (password hashing)
Frontend FrameworkNext.js 16: App Router
LanguageTypeScript
StylingTailwind CSS v4
State ManagementTanStack Query (server state)
Auth (frontend)NextAuth.js v4: Credentials + JWT
ChartsRecharts
HTTP ClientAxios
DeploymentVercel (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.

MethodEndpointDescription
POST/auth/loginAuthenticate user (email + password)
POST/usersRegister a new user
GET/usersList all users
GET/users/{user_id}Get user by ID
POST/assetsDeposit a new asset
GET/assetsList all assets
POST/borrowRequest a loan against available credit
GET/loansList all loans
POST/repay/{loan_id}Repay a loan (partial or full)
POST/repay/batchBatch 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 key
  • name: Full name
  • email: Unique identifier
  • password_hash: bcrypt hash

assets

  • id: Primary key
  • user_id: FK → users
  • type: property | crypto | car
  • value: Deposited value
  • created_at: Timestamp

loans

  • id: Primary key
  • user_id: FK → users
  • amount: Loan principal
  • amount_repaid: Running repayment
  • interest_rate: Default 5%
  • status: pending | approved | repaid
  • created_at: Timestamp

Business Rules

RuleDetail
Allowed asset typesproperty, crypto, car
Depreciation: property1% per period
Depreciation: crypto5% per period
Depreciation: car10% per period
Default interest rate5%
Available credit formulaTotal deposited assets − total outstanding loans
Borrow limitUsers 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