Skip to content

Rayhan0Islam0Shagor/product-price-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DealDrop - Price Tracking & Alert System

DealDrop is a modern web application that allows users to track product prices from any e-commerce website and receive instant email alerts when prices drop. Built with Next.js, Supabase, and Firecrawl, it provides a seamless experience for monitoring deals and saving money.

🎯 Features

  • Universal Product Tracking: Track products from any e-commerce site (Amazon, Walmart, etc.)
  • Automatic Price Monitoring: Daily cron job checks prices and updates product information
  • Price History Visualization: Interactive charts showing price trends over time
  • Email Alerts: Get notified instantly when prices drop below your tracked price
  • User Authentication: Secure Google OAuth authentication via Supabase
  • Modern UI: Beautiful, responsive interface built with Tailwind CSS and shadcn/ui components
  • Real-time Updates: Server-side rendering with automatic revalidation

πŸ› οΈ Tech Stack

Frontend

  • Next.js 16 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type-safe development
  • Tailwind CSS 4 - Utility-first CSS framework
  • shadcn/ui - High-quality component library
  • Recharts - Chart library for price visualization
  • Sonner - Toast notifications
  • Lucide React - Icon library

Backend & Services

  • Supabase - Backend-as-a-Service (Authentication, Database)
  • Firecrawl - Web scraping service for product data extraction
  • Resend - Email delivery service for price drop alerts
  • Vercel - Deployment platform (recommended)

Development Tools

  • Biome - Fast linter and formatter
  • TypeScript - Static type checking

πŸ“ Project Structure

dealdrop/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ actions/           # Server actions
β”‚   β”‚   β”‚   β”œβ”€β”€ boundary.ts    # Access control utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ get-me.ts      # Get current user
β”‚   β”‚   β”‚   β”œβ”€β”€ logout.ts      # User logout
β”‚   β”‚   β”‚   └── products.ts    # Product CRUD operations
β”‚   β”‚   β”œβ”€β”€ api/               # API routes
β”‚   β”‚   β”‚   └── cron/
β”‚   β”‚   β”‚       └── check-price/
β”‚   β”‚   β”‚           └── route.ts  # Cron job for price checking
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   └── callback/
β”‚   β”‚   β”‚       └── route.ts   # OAuth callback handler
β”‚   β”‚   β”œβ”€β”€ layout.tsx         # Root layout
β”‚   β”‚   β”œβ”€β”€ page.tsx           # Home page
β”‚   β”‚   └── globals.css        # Global styles
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ ui/                # shadcn/ui components
β”‚   β”‚   β”œβ”€β”€ AddProductForm.tsx # Product addition form
β”‚   β”‚   β”œβ”€β”€ AuthButton.tsx    # Authentication button
β”‚   β”‚   β”œβ”€β”€ AuthModal.tsx     # Login modal
β”‚   β”‚   β”œβ”€β”€ PriceChart.tsx    # Price history chart
β”‚   β”‚   └── ProductCard.tsx   # Product display card
β”‚   β”œβ”€β”€ lib/                   # Utility libraries
β”‚   β”‚   β”œβ”€β”€ email.ts          # Email sending utilities
β”‚   β”‚   └── firecrawl.ts      # Web scraping utilities
β”‚   β”œβ”€β”€ types/                 # TypeScript type definitions
β”‚   β”‚   └── product.ts        # Product-related types
β”‚   β”œβ”€β”€ utils/                 # Helper utilities
β”‚   β”‚   β”œβ”€β”€ supabase/         # Supabase client utilities
β”‚   β”‚   └── utils.ts          # General utilities
β”‚   └── proxy.ts              # Middleware for session management
β”œβ”€β”€ public/                    # Static assets
β”œβ”€β”€ .gitignore
β”œβ”€β”€ biome.json                 # Biome configuration
β”œβ”€β”€ components.json            # shadcn/ui configuration
β”œβ”€β”€ next.config.ts            # Next.js configuration
β”œβ”€β”€ package.json              # Dependencies
β”œβ”€β”€ postcss.config.mjs        # PostCSS configuration
└── tsconfig.json             # TypeScript configuration

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm/yarn/pnpm
  • Supabase account and project
  • Firecrawl API key
  • Resend API key (for email alerts)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd dealdrop
  2. Install dependencies

    npm install
    # or
    yarn install
    # or
    pnpm install
  3. Set up environment variables

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

    # Supabase Configuration
    NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_supabase_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
    
    # Firecrawl API
    FIRECRAWL_API_KEY=your_firecrawl_api_key
    
    # Resend Email Service
    RESEND_API_KEY=your_resend_api_key
    RESEND_FROM_EMAIL=noreply@yourdomain.com
    
    # Cron Job Security
    CRON_SECRET=your_random_secret_string
    
    # Application URL (for email links)
    NEXT_PUBLIC_APP_URL=http://localhost:3000
  4. Set up Supabase Database

    Create the following tables in your Supabase project:

    Products Table:

    CREATE TABLE products (
      id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
      user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
      url TEXT NOT NULL,
      name TEXT NOT NULL,
      current_price DECIMAL(10, 2) NOT NULL,
      currency TEXT NOT NULL DEFAULT 'USD',
      image_url TEXT,
      created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
      updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
      UNIQUE(user_id, url)
    );
    
    CREATE INDEX idx_products_user_id ON products(user_id);

    Price History Table:

    CREATE TABLE price_history (
      id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
      product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
      price DECIMAL(10, 2) NOT NULL,
      currency TEXT NOT NULL,
      checked_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
    );
    
    CREATE INDEX idx_price_history_product_id ON price_history(product_id);
    CREATE INDEX idx_price_history_checked_at ON price_history(checked_at);

    Enable Row Level Security (RLS):

    -- Enable RLS on products table
    ALTER TABLE products ENABLE ROW LEVEL SECURITY;
    
    -- Users can only see their own products
    CREATE POLICY "Users can view own products"
      ON products FOR SELECT
      USING (auth.uid() = user_id);
    
    -- Users can insert their own products
    CREATE POLICY "Users can insert own products"
      ON products FOR INSERT
      WITH CHECK (auth.uid() = user_id);
    
    -- Users can update their own products
    CREATE POLICY "Users can update own products"
      ON products FOR UPDATE
      USING (auth.uid() = user_id);
    
    -- Users can delete their own products
    CREATE POLICY "Users can delete own products"
      ON products FOR DELETE
      USING (auth.uid() = user_id);
    
    -- Enable RLS on price_history table
    ALTER TABLE price_history ENABLE ROW LEVEL SECURITY;
    
    -- Users can view price history for their products
    CREATE POLICY "Users can view own price history"
      ON price_history FOR SELECT
      USING (
        EXISTS (
          SELECT 1 FROM products
          WHERE products.id = price_history.product_id
          AND products.user_id = auth.uid()
        )
      );
  5. Configure Supabase OAuth

    • Go to your Supabase project dashboard
    • Navigate to Authentication > Providers
    • Enable Google OAuth
    • Add your OAuth credentials
    • Add http://localhost:3000/auth/callback to redirect URLs (for development)
    • Add your production URL to redirect URLs (for production)
  6. Run the development server

    npm run dev
    # or
    yarn dev
    # or
    pnpm dev
  7. Open your browser

    Navigate to http://localhost:3000

πŸ”§ Environment Variables

Variable Description Required
NEXT_PUBLIC_SUPABASE_URL Your Supabase project URL Yes
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY Supabase anon/public key Yes
SUPABASE_SERVICE_ROLE_KEY Supabase service role key (for cron jobs) Yes
FIRECRAWL_API_KEY Firecrawl API key for web scraping Yes
RESEND_API_KEY Resend API key for sending emails Yes
RESEND_FROM_EMAIL Email address to send alerts from Yes
CRON_SECRET Secret token for securing cron endpoint Yes
NEXT_PUBLIC_APP_URL Your application URL (for email links) Yes

πŸ“Š Database Schema

Products Table

Stores tracked products for each user.

Column Type Description
id UUID Primary key
user_id UUID Foreign key to auth.users
url TEXT Product URL
name TEXT Product name
current_price DECIMAL Current price
currency TEXT Currency code (USD, BDT, INR, etc.)
image_url TEXT Product image URL
created_at TIMESTAMP Creation timestamp
updated_at TIMESTAMP Last update timestamp

Price History Table

Stores historical price data for chart visualization.

Column Type Description
id UUID Primary key
product_id UUID Foreign key to products
price DECIMAL Price at check time
currency TEXT Currency code
checked_at TIMESTAMP When price was checked

πŸ”‘ Key Functionality

Adding Products

  • Users can paste any product URL from supported e-commerce sites
  • Firecrawl extracts product name, price, currency, and image
  • Product is added to user's tracking list
  • Initial price is recorded in price history

Price Monitoring

  • Cron job runs daily (configure via Vercel Cron or external service)
  • Checks all products in the database
  • Updates current prices
  • Records price changes in history
  • Sends email alerts when prices drop

Price Alerts

  • Email alerts are sent automatically when a price drops
  • Alert includes:
    • Product name and image
    • Previous and current price
    • Price drop percentage
    • Amount saved
    • Direct link to product

Price Charts

  • Interactive line charts showing price trends
  • Accessible via drawer component on product cards
  • Displays historical price data over time

πŸ”Œ API Routes

/api/cron/check-price (POST)

Automated price checking endpoint for cron jobs.

Authentication: Bearer token via Authorization header

curl -X POST https://your-domain.com/api/cron/check-price \
  -H "Authorization: Bearer YOUR_CRON_SECRET"

Response:

{
  "success": true,
  "message": "Price check completed. X products updated, Y price changes, Z alerts sent",
  "results": {
    "total": 10,
    "updated": 9,
    "failed": 1,
    "priceChanges": 3,
    "alertsSent": 2
  }
}

/auth/callback (GET)

OAuth callback handler for Supabase authentication.

🚒 Deployment

Deploy to Vercel

  1. Push your code to GitHub

  2. Import project to Vercel

    • Go to vercel.com
    • Click "New Project"
    • Import your GitHub repository
  3. Configure environment variables

    • Add all environment variables from .env.local
    • Set NEXT_PUBLIC_APP_URL to your Vercel deployment URL
  4. Set up Cron Job

    Create vercel.json in the root directory:

    {
      "crons": [
        {
          "path": "/api/cron/check-price",
          "schedule": "0 9 * * *"
        }
      ]
    }

    Or use Vercel Cron Jobs dashboard to configure:

    • Schedule: Daily at 9 AM UTC (or your preferred time)
    • Endpoint: /api/cron/check-price
    • Authorization: Bearer token with your CRON_SECRET
  5. Deploy

    • Vercel will automatically deploy on every push to main branch

Alternative: External Cron Service

If not using Vercel Cron, you can use external services like:

Configure them to POST to /api/cron/check-price with the Authorization header.

πŸ§ͺ Development

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run start - Start production server
  • npm run lint - Run Biome linter
  • npm run format - Format code with Biome

Code Style

This project uses Biome for linting and formatting. Configuration is in biome.json.

πŸ”’ Security Considerations

  • Row Level Security (RLS) is enabled on all database tables
  • Users can only access their own products and price history
  • Cron endpoint is protected with bearer token authentication
  • Service role key is only used server-side for cron jobs
  • OAuth authentication via Supabase

🀝 Contributing

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

πŸ“ License

This project is private and proprietary.

πŸ™ Acknowledgments

πŸ“§ Support

For issues, questions, or contributions, please open an issue on the repository.


Built with ❀️ using Next.js and Supabase