A campus-exclusive barter platform where students can trade items using AI-powered matching, fair trade scoring, and multi-hop trade detection.
- College Email Authentication - Only
.edudomains allowed - AI Item Analysis - Auto-categorization, condition scoring, and value estimation using Gemini 1.5 Flash
- Smart Matching - Fair Trade Score algorithm for 1-to-1 matches
- Multi-Hop Trading - BFS/DFS-based cycle detection for complex trades (A โ B โ C โ A)
- Heatmap Analytics - Supply/demand visualization across categories
- Trade Management - Accept/decline trades with status tracking
- Real-time Updates - Firestore listeners for live data
- Frontend: Next.js 14 (App Router), React, TailwindCSS
- Backend: Firebase (Auth, Firestore, Storage, Cloud Functions)
- AI: OpenRouter โ Gemini 1.5 Flash
- Charts: Recharts
- Icons: Lucide React
- Hosting: Vercel (frontend) + Firebase (backend)
Swapy_web/
โโโ src/
โ โโโ app/ # Next.js App Router pages
โ โ โโโ login/ # Login page
โ โ โโโ signup/ # Signup page
โ โ โโโ dashboard/ # Main dashboard
โ โ โโโ upload/ # Upload item page
โ โ โโโ matches/ # View matches (single & multi-hop)
โ โ โโโ my-items/ # Manage user items
โ โ โโโ trades/ # Trade management
โ โ โโโ heatmap/ # Analytics page
โ โ โโโ community/ # Community features
โ โ โโโ api/ # Next.js API routes
โ โโโ components/ # Reusable React components
โ โโโ lib/ # Utilities, types, Firebase config
โโโ functions/ # Firebase Cloud Functions
โ โโโ src/
โ โโโ index.ts # Cloud Functions (analyzeItem, etc.)
โโโ firebase.json # Firebase configuration
โโโ firestore.rules # Firestore security rules
โโโ firestore.indexes.json # Firestore indexes
โโโ storage.rules # Storage security rules
- Node.js 18+ and npm
- Firebase account
- OpenRouter API key (for Gemini 1.5 Flash)
- Git
git clone <your-repo-url>
cd Swapy_web# Install frontend dependencies
npm install
# Install Firebase Functions dependencies
cd functions
npm install
cd ..- Go to Firebase Console
- Create a new project
- Enable Authentication (Email/Password)
- Enable Firestore Database
- Enable Storage
- Enable Cloud Functions
Get Firebase Config:
- Go to Project Settings โ General
- Scroll to "Your apps" โ Add web app
- Copy the Firebase config object
- Go to OpenRouter
- Sign up and get an API key
- Ensure you have access to
google/gemini-flash-1.5model
Create .env.local in the root directory:
# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_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
# OpenRouter API
OPENROUTER_API_KEY=your_openrouter_api_key
# Allowed Email Domains
NEXT_PUBLIC_ALLOWED_DOMAINS=.edu,youruniversity.eduFor Firebase Functions:
Create functions/.env:
OPENROUTER_API_KEY=your_openrouter_api_key# Install Firebase CLI globally
npm install -g firebase-tools
# Login to Firebase
firebase login
# Initialize Firebase (if not already done)
firebase init
# Select:
# - Firestore
# - Functions
# - Storage
# - Hosting (optional)firebase deploy --only firestore:rules
firebase deploy --only firestore:indexes
firebase deploy --only storagecd functions
npm run build
cd ..
firebase deploy --only functionsnpm run dev- Install Vercel CLI:
npm i -g vercel- Deploy:
vercel- Add environment variables in Vercel dashboard
firebase deploy- Users can only read/write their own data
- Items can be created by authenticated users only
- Trades are only visible to involved parties
- Stats are read-only for users
- Users can only upload to their own folder
- All authenticated users can read uploaded images
{
userId: string
name: string
email: string
campusDomain: string
createdAt: Timestamp
}{
itemId: string
userId: string
name: string
category: string
description: string
desiredCategories: string[]
conditionScore: number (0-100)
estimatedValue: number
imageUrl: string
status: 'available' | 'pending' | 'traded'
createdAt: Timestamp
}{
tradeId: string
itemsInvolved: string[]
usersInvolved: string[]
fairnessScore: number
tradeType: 'single' | 'multi'
status: 'pending' | 'completed' | 'cancelled'
createdAt: Timestamp
}{
category: string
demandCount: number
supplyCount: number
}valueSimilarity = 100 - (|valueA - valueB| / max(valueA, valueB) * 100)
conditionCompatibility = 100 - |condA - condB|
scarcityCompatibility = (min(scarcityA, scarcityB) / max(scarcityA, scarcityB)) * 100
demandAlignment = 100 if mutual interest, 50 if one-way, 0 otherwise
fairTradeScore = 0.4 * valueSimilarity +
0.2 * conditionCompatibility +
0.2 * scarcityCompatibility +
0.2 * demandAlignment
- Uses BFS/DFS to find cycles in directed graph
- Edge A โ B exists if A wants something B has
- Detects cycles of length 2-4
- Calculates chain fairness as average of pair scores
- User uploads photo โ Firebase Storage
- Next.js calls
/api/analyze-item - API calls OpenRouter โ Gemini
- AI returns category, condition, keywords
- Backend calculates estimated value from price table
- Item saved to Firestore
- Stats updated
- User selects item to match
- System fetches all available items
- Calculates Fair Trade Score for each pair
- Returns top 20 matches
- User can propose trade
- Build directed graph from all items
- Run BFS/DFS to find cycles
- Calculate chain fairness score
- Return top 10 cycles
- User can propose multi-hop trade
- User proposes trade (single or multi-hop)
- Trade record created with status "pending"
- Other users accept/decline
- If all accept โ status "completed", items marked "traded"
- If any decline โ status "cancelled"
- Check that Cloud Functions are enabled in Firebase Console
- Verify OPENROUTER_API_KEY is set in Firebase Functions config
- Check function logs:
firebase functions:log
- Verify Firebase config in
.env.local - Check that Email/Password auth is enabled in Firebase Console
- Verify allowed domains in constants
- Check Storage rules are deployed
- Verify Firebase Storage is enabled
- Check browser console for errors
- Real-time chat between traders
- Push notifications for trade updates
- User reputation system
- Advanced filters for matches
- Mobile app (React Native)
- Integration with campus payment systems
- Trade history analytics
- Wishlist features
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - feel free to use this project for your campus!
For issues or questions:
- Open a GitHub issue
- Contact: [your-email]
Built with โค๏ธ for campus communities