Skip to content

CashGuard is a Next.js 14 currency validation platform that scans bills via a mobile-friendly UI, validates them with Gemini AI and a custom Vertex classifier, and stores history securely in Firebase.

Notifications You must be signed in to change notification settings

Nightwolf7570/CashAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CashGuard - Currency Validation Tool

A production-ready Next.js web application for currency validation and bill scanning, powered by Google Gemini AI and Firebase. Built with TypeScript, Tailwind CSS, and a professional green/blue financial theme.

πŸš€ Features

  • πŸ“± Mobile-Responsive Design - Works seamlessly on all devices
  • πŸ“· Camera Scanner - Scan bills using your device's camera with mobile-optimized experience
  • βœ… Dual AI Validation - Get instant results using TWO AI models:
    • 🧠 Gemini AI (via AI Studio) - Detailed security feature analysis
    • πŸ€– Bill Classifier (Custom Vertex AI) - Real/Fake classification
  • πŸ” Firebase Authentication - Secure Google Sign-In integration
  • πŸ“Š Scan History - Keep track of all your previous scans in Firestore
  • 🎨 Professional UI - Beautiful green/blue financial theme with smooth transitions
  • πŸ“ˆ Google Analytics 4 - Track page views, validation attempts, and user engagement
  • ⚑ Performance Monitoring - Firebase Performance Monitoring integration
  • πŸ”’ Secure Storage - Images stored in Firebase Storage with security rules
  • πŸ“± Offline Support - Service worker for offline functionality
  • 🎯 Toast Notifications - Real-time feedback with react-hot-toast
  • πŸ–ΌοΈ Image Compression - Automatic image compression before upload
  • ☁️ Cloud Run Ready - Fully containerized for serverless deployment

🎯 Hackathon Category: AI Studio - Idea to Code

This project demonstrates:

  • Google AI Studio Integration - Uses Gemini Vision API for currency validation
  • Cloud Run Deployment - Serverless containerized deployment
  • Applet Architecture - Self-contained API functions
  • Rapid Prototyping - From idea to production using AI Studio

See docs/AI_STUDIO_INTEGRATION.md for details on how we used AI Studio to "vibe code" this application.

πŸ“‹ Prerequisites

  • Node.js 18+ installed
  • npm or yarn package manager
  • Google AI Studio account (for Gemini API key)
  • Firebase project (for hosting, Firestore, Storage, Auth, Analytics, Performance)

πŸ› οΈ Setup Instructions

1. Get Gemini API Key

  1. Go to Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy the API key (you'll need it for environment variables)

2. Create Firebase Project

  1. Go to Firebase Console
  2. Click "Add project" or select an existing project
  3. Follow the setup wizard:
    • Enter project name
    • Enable Google Analytics (optional but recommended)
    • Select or create an Analytics account

3. Enable Firebase Services

Enable Authentication:

  1. In Firebase Console, go to Authentication β†’ Sign-in method
  2. Enable Google sign-in provider
  3. Add your domain to authorized domains if needed

Enable Firestore:

  1. Go to Firestore Database
  2. Click "Create database"
  3. Start in production mode (we'll add security rules)
  4. Choose your preferred location

Enable Storage:

  1. Go to Storage
  2. Click "Get started"
  3. Start in production mode (we'll add security rules)
  4. Use the default bucket location

Enable Analytics:

  1. Analytics is automatically enabled when you create a Firebase project
  2. Make note of your Measurement ID (G-XXXXXXXXXX)

Enable Performance Monitoring:

  1. Go to Performance in Firebase Console
  2. Click "Get started" (if not already enabled)
  3. Follow the setup instructions

4. Get Firebase Configuration

  1. In Firebase Console, go to Project Settings (gear icon)
  2. Scroll down to "Your apps"
  3. Click the Web icon (</>) to add a web app
  4. Register app with a nickname (e.g., "CashGuard Web")
  5. Copy the Firebase configuration object

You'll need these values:

  • apiKey
  • authDomain
  • projectId
  • storageBucket
  • messagingSenderId
  • appId
  • measurementId (from Analytics settings)

5. Install Dependencies

npm install

6. Configure Environment Variables

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

# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key_here
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-XXXXXXXXXX

# Gemini API Key (Server-side only)
GEMINI_API_KEY=your_gemini_api_key_here

7. Deploy Firestore Security Rules

firebase deploy --only firestore:rules

8. Deploy Storage Security Rules

firebase deploy --only storage:rules

9. Run Development Server

npm run dev

Open http://localhost:3000 in your browser.

🚒 Deployment Options

Option 1: Deploy to Google Cloud Run (✨ Recommended - Meets Hackathon Requirements)

Cloud Run provides fully managed serverless container deployment:

Quick Start:

# 1. Setup (one-time)
./scripts/setup-cloudrun.sh

# 2. Deploy
./scripts/deploy-cloudrun.sh

Features:

  • βœ… Scales automatically (0 to N instances)
  • βœ… Pay only for what you use ($0 when idle)
  • βœ… Built-in HTTPS and CDN
  • βœ… Integrates with Google AI Studio
  • βœ… Meets hackathon requirements

Full Guide: See CLOUDRUN_QUICKSTART.md or docs/CLOUD_RUN_DEPLOYMENT.md

⚠️ After Deployment: If you see auth/unauthorized-domain error, see FIX_FIREBASE_AUTH.md for a quick fix.

Option 2: Deploy to Vercel

Vercel provides seamless Next.js deployment with API routes:

  1. Push your code to GitHub
  2. Go to Vercel
  3. Import your repository
  4. Add environment variables in Vercel dashboard
  5. Deploy!

Option 3: Deploy to Firebase Hosting with Functions

For Firebase Hosting with API routes, you need Firebase Functions:

1. Install Firebase CLI

npm install -g firebase-tools

2. Login to Firebase

firebase login

3. Initialize Firebase

firebase init

Select:

  • βœ… Hosting
  • βœ… Functions
  • βœ… Firestore
  • βœ… Storage

4. Build Next.js

npm run build

5. Set Environment Variables

For Firebase Functions, set environment variables:

firebase functions:config:set gemini.api_key="your_api_key_here"

Or use .env file in functions/ directory.

6. Deploy

firebase deploy

Note: For production, consider using Firebase Functions to handle API routes, or deploy Next.js to Vercel and configure Firebase services separately.

Option 3: Standalone Next.js Server

You can also deploy Next.js as a standalone server to any Node.js hosting:

npm run build
npm start

πŸ“ Project Structure

CashAuth/
β”œβ”€β”€ app/                    # Next.js app directory
β”‚   β”œβ”€β”€ admin/             # Admin dashboard pages
β”‚   β”œβ”€β”€ api/               # API routes
β”‚   β”‚   β”œβ”€β”€ admin/         # Admin API endpoints
β”‚   β”‚   └── validate/      # Gemini validation endpoint
β”‚   β”œβ”€β”€ scanner/           # Scanner page
β”‚   β”œβ”€β”€ results/           # Results page
β”‚   β”œβ”€β”€ history/           # History page
β”‚   β”œβ”€β”€ settings/          # Settings page
β”‚   └── layout.tsx         # Root layout
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ Auth.tsx           # Authentication component
β”‚   β”œβ”€β”€ Header.tsx         # Header component
β”‚   β”œβ”€β”€ AnalyticsProvider.tsx # Analytics wrapper
β”‚   β”œβ”€β”€ EducationModal.tsx # Educational content modal
β”‚   └── SafeImage.tsx      # Safe image loading component
β”œβ”€β”€ lib/                   # Utility libraries
β”‚   β”œβ”€β”€ firebase.ts        # Firebase initialization
β”‚   β”œβ”€β”€ firebase-admin.ts  # Firebase Admin SDK
β”‚   β”œβ”€β”€ collections.js     # Firestore collections
β”‚   β”œβ”€β”€ performance.ts     # Performance monitoring
β”‚   β”œβ”€β”€ imageCompression.ts # Image compression
β”‚   β”œβ”€β”€ imageUtils.ts      # Image utilities
β”‚   └── toast.tsx          # Toast notifications
β”œβ”€β”€ docs/                  # Project documentation
β”‚   β”œβ”€β”€ API_KEYS_SETUP.md  # API keys setup guide
β”‚   β”œβ”€β”€ FIREBASE_SETUP.md  # Firebase configuration
β”‚   β”œβ”€β”€ FIREBASE_STORAGE_FIX.md # Storage troubleshooting
β”‚   β”œβ”€β”€ GEMINI.md          # Gemini AI integration details
β”‚   β”œβ”€β”€ SETUP_CHECKLIST.md # Setup checklist
β”‚   └── VERIFY_SCAN_HISTORY.md # Scan history verification
β”œβ”€β”€ scripts/               # Node.js utility scripts
β”‚   β”œβ”€β”€ seed-firestore.js  # Database seeding
β”‚   └── verify-scan-history.js # History verification
β”œβ”€β”€ tools/                 # Python tools for ML/AI
β”‚   β”œβ”€β”€ create_vertex_import_file.py # Vertex AI data prep
β”‚   β”œβ”€β”€ prepare_coco_dataset.py # COCO dataset prep
β”‚   └── README.md          # Tools documentation
β”œβ”€β”€ public/                # Static assets
β”‚   β”œβ”€β”€ demo/              # Demo images
β”‚   β”œβ”€β”€ education/         # Educational SVG assets
β”‚   └── sw.js              # Service worker
β”œβ”€β”€ firebase.json          # Firebase configuration
β”œβ”€β”€ firestore.rules        # Firestore security rules
β”œβ”€β”€ storage.rules          # Storage security rules
β”œβ”€β”€ firestore.indexes.json # Firestore indexes
└── README.md              # This file

πŸ”’ Security Features

  • Firebase Authentication: Required for all operations
  • Firestore Rules: Users can only access their own scans
  • Storage Rules: Users can only upload/access images in their own folder
  • Rate Limiting: API endpoint has rate limiting (10 requests/minute)
  • Image Validation: Validates image format and size before processing

πŸ“Š Analytics & Monitoring

Google Analytics 4 Events Tracked:

  • page_view - Page navigation
  • validation_attempt - Validation attempts (success/failure)
  • validation_success - Successful validations
  • validation_failure - Failed validations with error details
  • user_engagement - User interaction events

Performance Monitoring:

  • Image validation performance
  • API response times
  • Page load metrics

🎯 API Endpoints

POST /api/validate

Validates a currency bill image using Google Gemini AI.

Request:

{
  "imageBase64": "data:image/jpeg;base64,..."
}

Response:

{
  "success": true,
  "result": {
    "denomination": "$20",
    "currency": "USD",
    "validity": "Valid",
    "confidence": 85,
    "features": ["Watermark detected", "Security thread verified"],
    "notes": "Additional observations"
  }
}

Rate Limiting: 10 requests per minute per IP address

πŸ› οΈ Technologies Used

  • Next.js 14 (App Router) - React framework
  • React 18 - UI library
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Firebase - Backend services
    • Authentication (Google Sign-In)
    • Firestore (Database)
    • Storage (Image storage)
    • Analytics (User tracking)
    • Performance Monitoring
  • Google Gemini AI - Currency validation
  • react-hot-toast - Notifications
  • browser-image-compression - Image compression
  • Lucide React - Icons

πŸ“ Notes

  • The app requires authentication to use scanner features
  • Images are automatically compressed before upload to reduce storage costs
  • All scans are stored in Firestore with user-specific access
  • Service worker provides basic offline functionality
  • Performance monitoring tracks validation API calls

πŸ› Troubleshooting

Camera Access Issues

  • Ensure HTTPS (required for camera access)
  • Check browser permissions
  • Try a different browser

Firebase Errors

  • Verify environment variables are set correctly
  • Check Firebase console for service status
  • Ensure security rules are deployed

Gemini API Errors

  • Verify GEMINI_API_KEY is set correctly
  • Check API quota limits in Google AI Studio
  • Ensure image format is valid (JPEG, PNG, WebP)

πŸ“„ License

This project is built for hackathon demonstration purposes.

πŸ™ Acknowledgments

  • Powered by Google Gemini AI
  • Built with Firebase
  • Icons by Lucide

About

CashGuard is a Next.js 14 currency validation platform that scans bills via a mobile-friendly UI, validates them with Gemini AI and a custom Vertex classifier, and stores history securely in Firebase.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published