Skip to content

projectqreturn/Qreturn-Live

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Qreturn

AI-Powered Lost & Found Platform with QR Technology

Next.js React MongoDB Firebase PWA


🎯 About

Qreturn is a comprehensive Progressive Web App (PWA) that revolutionizes the lost and found experience by combining:

  • πŸ€– AI-powered image matching for automatic lost/found item detection
  • πŸ“± QR code technology for quick item registration and tracking
  • πŸ“ Real-time location tracking with proximity notifications (10km radius)
  • πŸ’¬ Firebase-powered chat for seamless communication between users
  • πŸ”” Push notifications for instant match alerts and updates
  • 🌐 Offline-first architecture for uninterrupted service

Perfect for communities, universities, airports, and public spaces to help reunite people with their belongings.

UI Design

View our complete design system on Figma:
🎨 Qreturn UI Design


✨ Features

πŸ” User Management

  • Secure Authentication: Powered by Clerk with email/social login
  • Profile Management: User verification with NIC/ID upload
  • Location Tracking: Automatic GPS tracking (updates every 50+ meters)
  • Account Dashboard: View all posts, items, and activity history

πŸ“ Post Management

  • Lost Item Posts: Create detailed lost item reports with photos
  • Found Item Posts: Report found items with image upload
  • AI Image Matching: Automatic matching via external ML API
  • QR Code Generation: Generate unique QR codes for personal items
  • Protected QR Scanning: Scan and report found items instantly
  • Category System: Organize by Electronics, Documents, Accessories, etc.
  • District-based Search: Filter items by geographical location

πŸ” Search & Discovery

  • Visual Search: Upload image to find similar lost/found items
  • Smart Filtering: Search by category, date, location, and keywords
  • Map View: Interactive map showing lost/found items with GPS markers
  • Proximity Alerts: Get notified when items are reported nearby (10km radius)

πŸ’¬ Communication

  • Real-time Chat: Firebase-powered messaging between users
  • In-app Notifications: Instant alerts for matches, messages, and updates
  • Push Notifications: Stay updated even when app is closed
  • Email Notifications: Fallback for critical updates

πŸ“± PWA Features

  • Installable: Add to home screen on mobile/desktop
  • Offline Support: Browse cached content without internet
  • Service Workers: Smart caching for instant loading
  • Push Notifications: Native-like notification experience
  • Responsive Design: Seamless experience across all devices

πŸ›‘οΈ Safety & Moderation

  • Post Reporting: Flag inappropriate or suspicious content
  • Admin Dashboard: Moderate posts and manage user reports
  • Account Verification: Optional ID verification for trusted users
  • Contact Forms: Support and inquiry system

πŸ› οΈ Tech Stack

Frontend

Backend

DevOps & Tools

  • Package Manager: npm
  • Build Tool: Turbopack (Next.js 15)
  • Version Control: Git & GitHub
  • Deployment: Vercel-ready
  • Analytics: Vercel Analytics
  • Webhooks: Svix for Clerk integration

πŸš€ Getting Started

Prerequisites

Ensure you have the following installed:

  • Node.js: v18 or higher
  • npm: v9 or higher
  • Git: Latest version
  • MongoDB: Atlas account or local instance
  • Firebase: Project with Firestore and FCM enabled
  • Clerk: Account for authentication

Installation

  1. Clone the repository:

    git clone https://github.com/projectqreturn/Qreturn-Live.git
    cd Qreturn-Live
  2. Install dependencies:

    npm install
  3. Set up environment variables (see Environment Setup):

    # Create .env.local file in root directory
    cp .env.example .env.local
    # Edit .env.local with your credentials
  4. Configure Firebase for PWA:

    npm run configure-firebase
  5. Generate VAPID keys for push notifications:

    npm run generate-vapid
  6. Run the development server:

    npm run dev
  7. Open your browser: Navigate to http://localhost:3000

Production Build

For PWA testing and production deployment:

# Build the application
npm run build

# Start production server
npm start

Note: PWA features (install prompt, service workers, push notifications) require a production build.


πŸ” Environment Setup

Create a .env.local file in the root directory with the following variables:

# MongoDB Database
MONGODB_URL=mongodb+srv://username:[email protected]/

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxxxxxxxxxxxx
CLERK_SECRET_KEY=sk_test_xxxxxxxxxxxxx
CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxx

# Firebase (Firestore & Cloud Messaging)
NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyxxxxxxxxxxxxxxxxxxxxxxxxx
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=123456789012
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789012:web:xxxxxxxxxxxxx
NEXT_PUBLIC_FIREBASE_VAPID_KEY=BKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Cloudinary (Image Hosting)
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=123456789012345
CLOUDINARY_API_SECRET=xxxxxxxxxxxxxxxxxxxxx

# External Image API (AI Matching)
NEXT_PUBLIC_IMAGE_API_URL=http://18.136.211.184:8000

# Google Maps (Optional)
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=AIzaSyxxxxxxxxxxxxxxxxxxxxxxxxx

# Application URL (for webhooks & redirects)
NEXT_PUBLIC_APP_URL=http://localhost:3000

# VAPID Keys (for push notifications)
NEXT_PUBLIC_VAPID_PUBLIC_KEY=BPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
VAPID_PRIVATE_KEY=xxxxxxxxxxxxxxxxxxxxx
VAPID_EMAIL=mailto:[email protected]

Getting API Keys


πŸ“ Project Structure

qreturn/
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ icons/                    # PWA app icons (PNG & SVG)
β”‚   β”œβ”€β”€ QR/                       # QR code assets
β”‚   β”œβ”€β”€ slider/                   # Landing page images
β”‚   β”œβ”€β”€ manifest.json             # PWA manifest
β”‚   β”œβ”€β”€ sw.js                     # Main service worker (auto-generated)
β”‚   └── firebase-messaging-sw.js  # FCM service worker
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ (login)/              # Authentication pages
β”‚   β”‚   β”‚   β”œβ”€β”€ sign-in/
β”‚   β”‚   β”‚   └── sign-up/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ (mainapp)/            # Protected app routes
β”‚   β”‚   β”‚   β”œβ”€β”€ (posts)/          # Lost/found post pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ lost/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ found/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ edit-lostpost/
β”‚   β”‚   β”‚   β”‚   └── edit-foundpost/
β”‚   β”‚   β”‚   β”œβ”€β”€ (user)/           # User-specific pages
β”‚   β”‚   β”‚   β”œβ”€β”€ createpost/       # Create new posts
β”‚   β”‚   β”‚   β”œβ”€β”€ image-search/     # Visual search
β”‚   β”‚   β”‚   β”œβ”€β”€ map/              # Map view
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/          # User profile
β”‚   β”‚   β”‚   β”œβ”€β”€ protectedqr/      # QR scanner
β”‚   β”‚   β”‚   β”œβ”€β”€ reports/          # User reports
β”‚   β”‚   β”‚   └── layout.js         # Protected layout
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ (sub-content)/        # Public pages
β”‚   β”‚   β”‚   β”œβ”€β”€ about/
β”‚   β”‚   β”‚   β”œβ”€β”€ contact/
β”‚   β”‚   β”‚   β”œβ”€β”€ privacy/
β”‚   β”‚   β”‚   └── terms-and-conditions/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ api/                  # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ contact/          # Contact form
β”‚   β”‚   β”‚   β”œβ”€β”€ images/           # Image operations
β”‚   β”‚   β”‚   β”œβ”€β”€ myitems/          # User items CRUD
β”‚   β”‚   β”‚   β”œβ”€β”€ post/             # Post management
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ lost/
β”‚   β”‚   β”‚   β”‚   └── found/
β”‚   β”‚   β”‚   β”œβ”€β”€ push/             # Push notifications
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ subscribe/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ unsubscribe/
β”‚   β”‚   β”‚   β”‚   └── send/
β”‚   β”‚   β”‚   β”œβ”€β”€ report/           # Report system
β”‚   β”‚   β”‚   β”œβ”€β”€ user/             # User management
β”‚   β”‚   β”‚   β”‚   └── location/
β”‚   β”‚   β”‚   └── webhooks/         # External webhooks
β”‚   β”‚   β”‚       └── clerk/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ actions/          # Server actions
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ user.action.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ lostPost.action.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ foundPost.action.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ myitems.action.js
β”‚   β”‚   β”‚   β”‚   └── contact.action.js
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   β”œβ”€β”€ modals/           # Mongoose schemas
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ user.modal.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ lostPost.modal.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ foundPost.modal.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ myitems.modal.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ chat.modal.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ contact.modal.js
β”‚   β”‚   β”‚   β”‚   └── reportPost.modal.js
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   β”œβ”€β”€ notification/     # Notification system
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ notification.js
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ examples.js
β”‚   β”‚   β”‚   β”‚   └── useNotifications.js
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   β”œβ”€β”€ utils/            # Utility functions
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ imageUpload.js
β”‚   β”‚   β”‚   β”‚   └── imageDelete.js
β”‚   β”‚   β”‚   β”‚
β”‚   β”‚   β”‚   β”œβ”€β”€ db.js             # MongoDB connection
β”‚   β”‚   β”‚   └── utils.js          # Helper functions
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ layout.js             # Root layout
β”‚   β”‚   β”œβ”€β”€ page.jsx              # Landing page
β”‚   β”‚   └── globals.css           # Global styles
β”‚   β”‚
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ appnav/               # App navigation
β”‚   β”‚   β”œβ”€β”€ chat/                 # Chat components
β”‚   β”‚   β”œβ”€β”€ createpost/           # Post creation
β”‚   β”‚   β”œβ”€β”€ footer/               # Footer
β”‚   β”‚   β”œβ”€β”€ landingpage/          # Landing page sections
β”‚   β”‚   β”œβ”€β”€ map/                  # Map components
β”‚   β”‚   β”œβ”€β”€ notifications/        # Notification UI
β”‚   β”‚   β”œβ”€β”€ postcard/             # Post display cards
β”‚   β”‚   β”œβ”€β”€ profile/              # Profile components
β”‚   β”‚   β”œβ”€β”€ pwa/                  # PWA-specific
β”‚   β”‚   β”‚   β”œβ”€β”€ InstallPWA.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PWARegistration.jsx
β”‚   β”‚   β”‚   └── PushNotificationButton.jsx
β”‚   β”‚   β”œβ”€β”€ LocationTracker.jsx   # Auto location tracking
β”‚   β”‚   └── LocationDebugger.jsx  # GPS debug tool
β”‚   β”‚
β”‚   β”œβ”€β”€ firebase/
β”‚   β”‚   └── firebase.config.ts    # Firebase configuration
β”‚   β”‚
β”‚   └── middleware.js             # Clerk route protection
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ configure-firebase-sw.js  # Firebase SW setup
β”‚   └── fix-existing-chats.js     # DB migration script
β”‚
β”œβ”€β”€ .github/
β”‚   └── copilot-instructions.md   # AI coding guidelines
β”‚
β”œβ”€β”€ next.config.mjs               # Next.js + PWA config
β”œβ”€β”€ tailwind.config.mjs           # Tailwind configuration
β”œβ”€β”€ package.json                  # Dependencies
β”œβ”€β”€ firebase.json                 # Firebase config
β”œβ”€β”€ firestore.rules               # Firestore security rules
└── firestore.indexes.json        # Firestore indexes

πŸ”‘ Key Functionalities

1. Authentication Flow (Clerk)

  • User signs up/signs in via Clerk
  • Webhook creates/syncs user in MongoDB
  • Profile stored in MongoDB with location data
  • Protected routes enforced by src/middleware.js
// Access authenticated user
import { useUser } from '@clerk/nextjs';

const { user } = useUser();
const userId = user.id; // Clerk user ID

2. Post Creation with AI Matching

  1. User uploads images to Cloudinary
  2. First image sent to external ML API (uploadMainImageToExternalApi)
  3. API returns UUID-based searchId for matching
  4. Post saved to MongoDB with search_Id field
  5. Background AI matching occurs (external service)

3. Real-time Location Tracking

  • LocationTracker component runs automatically in protected routes
  • Updates MongoDB every 50+ meters movement
  • GPS stored as string: "latitude,longitude"
  • Used for proximity notifications and map features
// Query nearby users
import { getNearbyUsers } from '@/app/lib/actions/user.action';

const nearbyUsers = await getNearbyUsers(centerGps, radiusKm, excludeUserId);

4. Push Notification System

Firebase Cloud Messaging for web push:

  • Tokens stored in Firestore (users/{clerkId}/tokens)
  • Notifications stored in Firestore (notifications collection)
  • Background handling via firebase-messaging-sw.js
// Send notification
import { createNotification, NOTIFICATION_TYPES } from '@/app/lib/notification/notification';

await createNotification({
  userId: 'clerk_user_id',
  type: NOTIFICATION_TYPES.MATCH_FOUND,
  title: 'Match Found!',
  message: 'Someone found your lost wallet',
  link: '/myitems',
  sendPush: true
});

5. Dual Database Architecture

MongoDB (via Mongoose):

  • Users, posts, items, reports, contacts
  • Structured data with relationships
  • Auto-incrementing IDs via mongoose-sequence

Firestore (Firebase):

  • Notifications (real-time updates)
  • Chat messages (real-time messaging)
  • FCM tokens (push subscription management)

6. QR Code System

  • Generate unique QR codes for personal items
  • Scan QR codes to report found items
  • Protected scanning (authentication required)
  • Automatic owner notification via push/email

πŸ“‘ API Documentation

Authentication

All API routes use Clerk authentication. Protected routes require valid JWT token.

Endpoints

Posts

# Create lost post
POST /api/post/lost
Body: { title, date, phone, Category, District, gps, description, email, photo[], clerkUserId }

# Get all lost posts
GET /api/post/lost

# Update lost post
PUT /api/post/lost?id={postId}

# Delete lost post
DELETE /api/post/lost?id={postId}

# Same endpoints for found posts
POST/GET/PUT/DELETE /api/post/found

User Management

# Get user profile
GET /api/user?clerkId={userId}

# Update user location
POST /api/user/location
Body: { clerkId, gps }

# Get nearby users
GET /api/user/location?gps={lat,lng}&radius={km}

Notifications

# Subscribe to push
POST /api/push/subscribe
Body: { subscription, userId }

# Unsubscribe from push
POST /api/push/unsubscribe
Body: { endpoint }

# Send push notification
POST /api/push/send
Body: { userId, title, body, url, data }

Reports

# Report a post
POST /api/report
Body: { postId, postType, reason, description, reporterEmail }

# Get all reports (admin)
GET /api/report

# Update report status
PUT /api/report?id={reportId}
Body: { status }

πŸ“± PWA & Offline Support

Installation

Users can install Qreturn as a standalone app:

  • Mobile: "Add to Home Screen" prompt
  • Desktop: Install button in address bar
  • Custom Prompt: Appears 3 seconds after first visit

Service Workers

Main Service Worker (sw.js):

  • Caches static assets (images, CSS, JS)
  • Network-first strategy for API calls
  • Cache-first for images and static resources
  • Offline fallback page

Firebase Messaging SW (firebase-messaging-sw.js):

  • Handles background push notifications
  • Displays native notifications
  • Routes notification clicks to app

Offline Capabilities

  • Browse cached posts and items
  • View previously loaded content
  • Queue actions for sync when online
  • Automatic retry for failed requests

Caching Strategy

// API calls: Network-first (15s timeout)
// Images: Cache-first (60 days)
// Static assets: Cache-first (1 year)

πŸš€ Deployment

Vercel (Recommended)

  1. Connect GitHub repository to Vercel

  2. Configure environment variables in Vercel dashboard

  3. Deploy:

    # Vercel automatically detects Next.js
    # Just push to main branch
    git push origin main
  4. Custom Domain (optional):

    • Add domain in Vercel dashboard
    • Update DNS records
    • SSL automatically provisioned

Environment Variables in Production

Ensure all variables from .env.local are added to Vercel:

  • Project Settings β†’ Environment Variables
  • Add all variables (categorize as Production/Preview/Development)

Post-Deployment Checklist

  • βœ… Verify PWA manifest loads correctly
  • βœ… Test service worker registration
  • βœ… Confirm push notifications work
  • βœ… Check MongoDB connection pooling
  • βœ… Validate Clerk webhooks (use Vercel URL)
  • βœ… Test image upload to Cloudinary
  • βœ… Verify external AI API accessibility
  • βœ… Test Firebase FCM delivery
  • βœ… Check Google Maps API restrictions

πŸ§ͺ Testing

Development Testing

# Start development server
npm run dev

# Test in browser
open http://localhost:3000

PWA Testing

# Build for production
npm run build

# Start production server
npm start

# Test PWA features
open http://localhost:3000

Testing PWA Install:

  1. Open DevTools β†’ Application β†’ Service Workers
  2. Check "Offline" to test offline mode
  3. Use Lighthouse audit for PWA score

Push Notification Testing

Visit test pages:

  • /push-test - Basic push notification testing
  • /notification-test - Advanced notification features
  • /notifications-demo - Complete demo

🀝 Contributing

We welcome contributions! Please follow these guidelines:

Development Process

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly
  5. Commit with conventional commits:
    git commit -m "feat: add amazing feature"
  6. Push to your fork:
    git push origin feature/amazing-feature
  7. Open a Pull Request

Commit Convention

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation changes
  • style: Code style changes (formatting)
  • refactor: Code refactoring
  • test: Test additions or changes
  • chore: Build process or tooling changes

Code Style

  • Use Tailwind CSS for styling
  • Follow React best practices
  • Use TypeScript for type safety (where applicable)
  • Write meaningful component names
  • Add comments for complex logic
  • Keep components small and focused

πŸ“š Additional Documentation


πŸ› Troubleshooting

Common Issues

1. Service Worker Not Registering

# Clear browser cache and storage
# Rebuild the app
npm run build
npm start

2. Push Notifications Not Working

  • Verify VAPID keys are correct
  • Check Firebase config in firebase-messaging-sw.js
  • Ensure HTTPS (required for web push)
  • Grant notification permissions in browser

3. MongoDB Connection Issues

  • Check MONGODB_URL in .env.local
  • Verify IP whitelist in MongoDB Atlas
  • Test connection string format

4. Image Upload Failing

  • Verify Cloudinary credentials
  • Check image size limits
  • Ensure external API is accessible

5. Location Tracking Not Working

  • Allow location permissions in browser
  • Check HTTPS (required for geolocation API)
  • Test on physical device (more accurate)

Debug Tools

  • LocationDebugger component - Visualize GPS data
  • Browser DevTools β†’ Application β†’ Service Workers
  • Firebase Console β†’ Cloud Messaging β†’ Reports
  • MongoDB Compass - Database GUI

πŸ“„ License

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


πŸ‘₯ Team

Qreturn is developed and maintained by the Project Qreturn team.


πŸ™ Acknowledgments


πŸ“ž Support

For support, questions, or feature requests:


Made with ❀️ by the Qreturn Team

⭐ Star us on GitHub if you find this project helpful!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages