Skip to content

shardulnarvekar/TrustFirst

Repository files navigation

🀝 TrustFirst - Trust-Based P2P Lending Platform

TrustFirst Next.js TypeScript MongoDB

Digitizing informal money lending between friends and family with AI-powered features

Features β€’ Tech Stack β€’ Getting Started β€’ Documentation


πŸ“– Table of Contents


🌟 Overview

TrustFirst is a modern peer-to-peer lending platform that brings structure and accountability to informal money lending between friends, family, and colleagues. Built with cutting-edge AI technologies, TrustFirst transforms casual lending into a professional, trackable, and trust-based experience.

The Problem

  • Awkward money conversations between friends/family
  • Forgotten payments and broken promises
  • Lack of documentation for informal loans
  • No structured repayment plans
  • Difficulty tracking multiple small loans

The Solution

TrustFirst provides:

  • βœ… Digital agreements with trust scores
  • βœ… AI-generated personalized repayment plans
  • βœ… Automated reminders via email and AI voice calls
  • βœ… Group lending for community support
  • βœ… Payment proof tracking with screenshots
  • βœ… Witness verification for added credibility
  • βœ… Real-time location tracking for security

🎯 Key Features

1. AI-Powered Installment Planning πŸ€–

  • Google Gemini 2.5 Pro integration
  • Generates 3 personalized repayment plans:
    • Aggressive: Fast repayment, higher installments
    • Balanced: Moderate payments over reasonable time
    • Flexible: Smaller payments spread over longer period
  • Smart date validation ensures all payments before due date
  • Considers borrower context and financial capacity

2. Conversational AI Calling πŸ“ž

  • VAPI AI integration for natural voice calls
  • Automated payment reminders via phone
  • Professional, empathetic conversation flow
  • One-click call initiation by lenders
  • Real-time call status tracking

3. Group Lending (Many-to-One) πŸ‘₯

  • Create groups of friends, family, or colleagues
  • Request money from entire group
  • Multiple people contribute partial amounts
  • Each contribution creates individual 1-on-1 agreement
  • Request auto-closes when full amount received
  • Admin controls for group creators:
    • Add/remove members
    • Delete groups
    • Manage permissions

4. Dynamic Trust Score System πŸ“Š

  • Real-time trust score (0-100) for each agreement
  • Score decreases if payments are late
  • Strict Mode option for faster penalties
  • Visual indicators with color coding:
    • 🟒 Green (80-100): Excellent
    • 🟑 Yellow (60-79): Good
    • 🟠 Orange (40-59): Fair
    • πŸ”΄ Red (0-39): Poor

5. Witness Verification βœ…

  • Add third-party witness to agreements
  • Email-based approval workflow
  • Witness can approve/reject agreements
  • Adds legal credibility to informal lending
  • Notification system for all parties

6. Real-Time Location Tracking πŸ“

  • Radar.io integration
  • Track borrower's live location (with consent)
  • Location history with timestamps
  • Address geocoding (city, state, country)
  • Privacy-focused implementation

7. Payment Proof Management πŸ“Έ

  • Upload multiple payment screenshots
  • Grid-based UI for organized tracking
  • Individual proof for each installment
  • View/remove uploaded proofs
  • Progress tracking (X/Y proofs uploaded)
  • File validation (image only, max 5MB)

8. Smart Email Notifications πŸ“§

  • Automated email workflows:
    • Agreement creation confirmations
    • Witness approval requests
    • Payment due date reminders
    • Settlement notifications
  • Professional HTML email templates
  • Clickable buttons with ngrok URLs
  • Real-time delivery status

9. Secure Authentication πŸ”

  • Firebase Authentication
  • Email/password login
  • User profile management
  • Role-based access control (lender/borrower/witness)
  • Session management

10. Comprehensive Dashboard πŸ“±

  • Clean, modern dark-themed UI
  • Real-time updates and notifications
  • Mobile-responsive design
  • Intuitive navigation
  • Visual progress indicators
  • Color-coded status badges

πŸ› οΈ Tech Stack

Frontend

  • Next.js 16.0 - React framework with App Router
  • TypeScript - Type-safe development
  • Tailwind CSS - Utility-first styling
  • Shadcn/ui - Beautiful component library
  • Lucide Icons - Modern icon set

Backend & Database

  • Next.js API Routes - Serverless API endpoints
  • MongoDB Atlas - Cloud NoSQL database
  • Mongoose - MongoDB ODM

AI & Automation

  • Google Gemini 2.5 Pro - AI installment planning
  • VAPI AI - Conversational voice calling
  • Make.com - Webhook automation workflows

External Services

  • Firebase - Authentication & user management
  • Radar.io - Location tracking & geocoding
  • Nodemailer - Email delivery
  • Ngrok - Local development tunneling

Development Tools

  • ESLint - Code linting
  • Prettier - Code formatting
  • Git - Version control

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Client (Browser)                      β”‚
β”‚                     Next.js 16 + React                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Next.js API Routes                        β”‚
β”‚              (Serverless Functions)                          β”‚
β””β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚           β”‚          β”‚          β”‚          β”‚
  β–Ό           β–Ό          β–Ό          β–Ό          β–Ό
β”Œβ”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ DB β”‚   β”‚Firebaseβ”‚  β”‚Geminiβ”‚  β”‚VAPI  β”‚  β”‚Radar.ioβ”‚
β”‚    β”‚   β”‚  Auth  β”‚  β”‚  AI  β”‚  β”‚  AI  β”‚  β”‚Locationβ”‚
β””β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
MongoDB                                    

Data Flow

  1. User Authentication: Firebase handles login/signup
  2. Agreement Creation: Stored in MongoDB with Mongoose
  3. AI Planning: Gemini generates installment plans
  4. Notifications: Nodemailer sends emails
  5. Voice Calls: VAPI AI makes conversational calls
  6. Location: Radar.io tracks borrower location
  7. File Storage: Local filesystem for payment proofs

πŸš€ Getting Started

Prerequisites

  • Node.js 18.x or higher
  • npm or yarn or pnpm
  • MongoDB Atlas account
  • Firebase project
  • Google Cloud account (for Gemini API)
  • Ngrok account (for local development)

Installation

  1. Clone the repository
git clone https://github.com/yourusername/trustfirst.git
cd trustfirst
  1. Install dependencies
npm install
# or
yarn install
# or
pnpm install
  1. Set up environment variables
cp .env.example .env.local

Edit .env.local with your credentials (see Environment Variables)

  1. Start development server
npm run dev
  1. Start ngrok tunnel (in a new terminal)
npx ngrok http 3000
  1. Update ngrok URL
  • Copy the ngrok HTTPS URL
  • Update NEXT_PUBLIC_APP_URL in .env.local
  • Restart the dev server
  1. Open the app
http://localhost:3000

πŸ” Environment Variables

Create a .env.local file in the root directory:

# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id

# MongoDB
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/dbname

# Email Configuration (Gmail)
EMAIL_USER=your_email@gmail.com
EMAIL_PASSWORD=your_app_password
EMAIL_SERVER_HOST=smtp.gmail.com
EMAIL_SERVER_PORT=587
EMAIL_FROM=your_email@gmail.com

# Application URL (Ngrok)
NEXT_PUBLIC_APP_URL=https://your-ngrok-url.ngrok-free.dev

# AI Configuration
GEMINI_API_KEY=your_gemini_api_key

# Make.com Webhook (for VAPI AI calls)
MAKE_CALL_WEBHOOK_URL=https://hook.us2.make.com/your_webhook_id

# Radar.io (Location Tracking)
NEXT_PUBLIC_RADAR_PUBLISHABLE_KEY=your_radar_key

# Firebase Admin (for server-side)
FIREBASE_CLIENT_EMAIL=your_service_account@project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"

Getting API Keys

  1. Firebase: https://console.firebase.google.com/
  2. MongoDB Atlas: https://www.mongodb.com/cloud/atlas
  3. Google Gemini: https://makersuite.google.com/app/apikey
  4. Radar.io: https://radar.com/dashboard
  5. Make.com: https://www.make.com/
  6. Gmail App Password: https://myaccount.google.com/apppasswords

πŸ“ Project Structure

trustfirst/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ api/                      # API Routes
β”‚   β”‚   β”œβ”€β”€ agreements/           # Agreement CRUD
β”‚   β”‚   β”‚   └── [id]/
β”‚   β”‚   β”‚       β”œβ”€β”€ route.ts
β”‚   β”‚   β”‚       β”œβ”€β”€ approve-witness/
β”‚   β”‚   β”‚       β”œβ”€β”€ send-reminder/
β”‚   β”‚   β”‚       β”œβ”€β”€ ask-ai-call/
β”‚   β”‚   β”‚       β”œβ”€β”€ save-plan/
β”‚   β”‚   β”‚       β”œβ”€β”€ upload-installment-proof/
β”‚   β”‚   β”‚       └── remove-installment-proof/
β”‚   β”‚   β”œβ”€β”€ auth/                 # Authentication
β”‚   β”‚   β”œβ”€β”€ groups/               # Group management
β”‚   β”‚   β”œβ”€β”€ money-requests/       # Group lending
β”‚   β”‚   β”œβ”€β”€ notifications/        # Notifications
β”‚   β”‚   β”œβ”€β”€ user/                 # User management
β”‚   β”‚   └── live-location/        # Location tracking
β”‚   β”œβ”€β”€ actions/                  # Server Actions
β”‚   β”‚   └── generate-installment-plan.ts
β”‚   β”œβ”€β”€ auth/                     # Auth pages
β”‚   β”‚   β”œβ”€β”€ signin/
β”‚   β”‚   └── signup/
β”‚   β”œβ”€β”€ dashboard/                # Main app pages
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Dashboard home
β”‚   β”‚   β”œβ”€β”€ layout.tsx            # Dashboard layout
β”‚   β”‚   β”œβ”€β”€ agreement/[id]/       # Agreement details
β”‚   β”‚   β”‚   └── upload-proofs/    # Payment proof upload
β”‚   β”‚   β”œβ”€β”€ groups/               # Group pages
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ create/
β”‚   β”‚   β”‚   └── [id]/
β”‚   β”‚   β”œβ”€β”€ notifications/
β”‚   β”‚   └── profile/
β”‚   β”œβ”€β”€ utils/                    # Utility functions
β”‚   β”‚   └── radar.ts              # Radar.io integration
β”‚   β”œβ”€β”€ globals.css               # Global styles
β”‚   β”œβ”€β”€ layout.tsx                # Root layout
β”‚   └── page.tsx                  # Landing page
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   └── RecentFriendsModal.tsx
β”‚   β”œβ”€β”€ ui/                       # Shadcn/ui components
β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”œβ”€β”€ card.tsx
β”‚   β”‚   β”œβ”€β”€ dialog.tsx
β”‚   β”‚   └── ... (50+ components)
β”‚   β”œβ”€β”€ installment-plan-generator.tsx
β”‚   └── theme-provider.tsx
β”œβ”€β”€ lib/                          # Libraries & utilities
β”‚   β”œβ”€β”€ mongodb.ts                # MongoDB connection
β”‚   β”œβ”€β”€ email.ts                  # Email service
β”‚   └── utils.ts                  # Helper functions
β”œβ”€β”€ models/                       # Mongoose models
β”‚   β”œβ”€β”€ Agreement.ts
β”‚   β”œβ”€β”€ Group.ts
β”‚   β”œβ”€β”€ MoneyRequest.ts
β”‚   β”œβ”€β”€ Notification.ts
β”‚   β”œβ”€β”€ User.ts
β”‚   └── LiveLocation.ts
β”œβ”€β”€ hooks/                        # Custom React hooks
β”‚   β”œβ”€β”€ use-mobile.ts
β”‚   └── use-toast.ts
β”œβ”€β”€ public/                       # Static assets
β”‚   └── uploads/                  # User uploads
β”‚       └── installments/
β”œβ”€β”€ .env.local                    # Environment variables
β”œβ”€β”€ .gitignore
β”œβ”€β”€ next.config.mjs               # Next.js config
β”œβ”€β”€ tailwind.config.ts            # Tailwind config
β”œβ”€β”€ tsconfig.json                 # TypeScript config
β”œβ”€β”€ package.json
└── README.md

πŸ“š API Documentation

Authentication

POST /api/auth/signup

Create a new user account.

Request Body:

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "securepassword"
}

POST /api/auth/signin

Sign in to existing account.

Request Body:

{
  "email": "john@example.com",
  "password": "securepassword"
}

Agreements

GET /api/agreements?userId={userId}

Get all agreements for a user.

POST /api/agreements

Create a new agreement.

Request Body:

{
  "lenderId": "user123",
  "lenderName": "John Doe",
  "lenderEmail": "john@example.com",
  "borrowerName": "Jane Smith",
  "borrowerEmail": "jane@example.com",
  "amount": 10000,
  "purpose": "Medical emergency",
  "dueDate": "2026-03-15",
  "witnessEmail": "witness@example.com"
}

GET /api/agreements/[id]

Get agreement details.

PATCH /api/agreements/[id]

Update agreement (settle, update status, etc.).

POST /api/agreements/[id]/send-reminder

Send payment reminder email.

POST /api/agreements/[id]/ask-ai-call

Initiate AI voice call to borrower.

POST /api/agreements/[id]/approve-witness

Witness approves the agreement.

POST /api/agreements/[id]/save-plan

Save selected installment plan.

Request Body:

{
  "planIndex": 1,
  "planName": "Balanced Approach",
  "installments": [
    {
      "date": "2026-02-15",
      "amount": 3333,
      "note": "First payment"
    }
  ]
}

POST /api/agreements/[id]/upload-installment-proof

Upload payment proof screenshot.

Form Data:

  • file: Image file
  • installmentIndex: Index of installment (0, 1, 2...)

Groups

GET /api/groups?userId={userId}

Get all groups for a user.

POST /api/groups

Create a new group.

Request Body:

{
  "name": "College Friends",
  "description": "My college buddies",
  "createdBy": "user123",
  "createdByName": "John Doe",
  "createdByEmail": "john@example.com",
  "memberEmails": ["friend1@example.com", "friend2@example.com"]
}

GET /api/groups/[id]

Get group details.

PATCH /api/groups/[id]

Update group (add/remove members).

Request Body:

{
  "addMemberEmails": ["newmember@example.com"],
  "removeMemberEmail": "oldmember@example.com"
}

DELETE /api/groups/[id]

Delete a group.

Money Requests

GET /api/money-requests?groupId={groupId}

Get all money requests for a group.

POST /api/money-requests

Create a money request in a group.

Request Body:

{
  "groupId": "group123",
  "requesterId": "user123",
  "requesterName": "John Doe",
  "requesterEmail": "john@example.com",
  "amount": 5000,
  "purpose": "Emergency",
  "dueDate": "2026-03-15"
}

POST /api/money-requests/[id]/contribute

Contribute to a money request.

Request Body:

{
  "lenderId": "user456",
  "lenderName": "Jane Smith",
  "lenderEmail": "jane@example.com",
  "amount": 1000
}

Notifications

GET /api/notifications?userId={userId}

Get all notifications for a user.

Location

POST /api/live-location

Save borrower's live location.

Request Body:

{
  "agreementId": "agreement123",
  "userId": "user123",
  "latitude": 18.5204,
  "longitude": 73.8567,
  "locationContext": {
    "description": "Pune, Maharashtra, India",
    "city": "Pune",
    "state": "Maharashtra",
    "country": "India"
  }
}

🎨 Features Deep Dive

AI Installment Planning

The AI installment planner uses Google Gemini 2.5 Pro to generate personalized repayment schedules:

  1. Input Analysis: Analyzes amount, due date, and borrower context
  2. Plan Generation: Creates 3 distinct plans with different strategies
  3. Date Validation: Ensures all installments are before due date
  4. Smart Scheduling: Distributes payments evenly (monthly/bi-weekly)
  5. User Selection: Borrower selects preferred plan
  6. Proof Tracking: Each installment tracked with screenshot uploads

Example Plans for β‚Ή10,000 due in 3 months:

  • Aggressive: 2 payments of β‚Ή5,000 each (1 month)
  • Balanced: 3 payments of β‚Ή3,333 each (2 months)
  • Flexible: 4 payments of β‚Ή2,500 each (3 months)

Group Lending Workflow

  1. Create Group: User creates group and adds members
  2. Request Money: Member posts money request to group
  3. Contributions: Multiple members contribute partial amounts
  4. Agreement Creation: Each contribution creates 1-on-1 agreement
  5. Request Closure: Auto-closes when full amount received
  6. Individual Tracking: Each agreement tracked separately

Example:

  • Alice requests β‚Ή10,000 from "College Friends" group
  • Bob contributes β‚Ή3,000 β†’ Creates Agreement #1 (Bob β†’ Alice)
  • Charlie contributes β‚Ή4,000 β†’ Creates Agreement #2 (Charlie β†’ Alice)
  • David contributes β‚Ή3,000 β†’ Creates Agreement #3 (David β†’ Alice)
  • Request closes, Alice has 3 separate agreements to repay

Trust Score Algorithm

// Initial score: 80
let trustScore = 80

// If payment is late:
if (daysOverdue > 0) {
  if (strictMode) {
    trustScore -= (daysOverdue * 2) // Faster penalty
  } else {
    trustScore -= daysOverdue // Normal penalty
  }
}

// Minimum score: 0
trustScore = Math.max(0, trustScore)

Email Templates

All emails use professional HTML templates with:

  • Responsive design
  • Branded colors
  • Clickable buttons
  • Dynamic content
  • Ngrok URLs for live access

Email Types:

  1. Agreement Request
  2. Witness Approval Request
  3. Witness Approved Notification
  4. Payment Reminder
  5. Settlement Confirmation

πŸš€ Deployment

Vercel (Recommended)

  1. Push to GitHub
git push origin main
  1. Import to Vercel
  1. Update URLs
  • Replace ngrok URL with Vercel URL
  • Update NEXT_PUBLIC_APP_URL
  • Update Firebase authorized domains

Environment Variables on Vercel

Add all variables from .env.local to Vercel:

  • Settings β†’ Environment Variables
  • Add each variable
  • Redeploy

Custom Domain

  1. Add domain in Vercel settings
  2. Update DNS records
  3. Update NEXT_PUBLIC_APP_URL
  4. Update Firebase authorized domains

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Use ESLint and Prettier
  • Write meaningful commit messages
  • Add comments for complex logic
  • Test thoroughly before submitting PR

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Team

Team CarpeDiem πŸš€

  • Shardul Narvekar - Full Stack Developer & AI Integration
  • Tejas Adhiya - Backend Developer & Database Architecture
  • Jeel Nandha - Frontend Developer & UI/UX Design

πŸ™ Acknowledgments

  • Google Gemini for AI capabilities
  • VAPI AI for conversational calling
  • Radar.io for location services
  • Firebase for authentication
  • MongoDB for database
  • Vercel for hosting
  • Shadcn/ui for beautiful components

πŸ“ž Support

For support, email the team or open an issue on GitHub.


Made with ❀️ by Team CarpeDiem

Shardul Narvekar β€’ Tejas Adhiya β€’ Jeel Nandha

⭐ Star this repo if you find it helpful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors