GadgetsPrices

TrendHive - Automated Trending Products Aggregator

A production-ready, SEO-optimized web application that automatically aggregates trending products from multiple e-commerce platforms with AI-powered summaries and affiliate link management.

Features

Tech Stack

Quick Start

Prerequisites

Local Development

  1. Clone the repository ```bash git clone https://github.com/yourusername/trendhive.git cd trendhive ```

  2. Install dependencies ```bash npm install ```

  3. Set up environment variables ```bash cp .env.example .env.local ```

    Edit .env.local and add your API keys: ```env DATABASE_URL=”file:./dev.db” OPENAI_API_KEY=sk-… NEXTAUTH_SECRET=your-secret-key JWT_SECRET=your-jwt-secret NEXT_PUBLIC_APP_URL=http://localhost:3000 ```

  4. Initialize the database ```bash npm run db:push npm run db:seed ```

  5. Create admin user (optional - for testing) ```bash npm run db:studio ``` Then manually add a user to the AdminUser table with hashed password.

  6. Start development server ```bash npm run dev ```

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

Environment Variables

Create a .env.local file with the following variables:

```env

Database

DATABASE_URL=”file:./dev.db” # SQLite for local, postgresql://… for production

OpenAI API

OPENAI_API_KEY=sk-your-key-here

Affiliate APIs (optional)

AMAZON_AFFILIATE_TAG=your-tag AMAZON_ACCESS_KEY=your-key AMAZON_SECRET_KEY=your-secret

FLIPKART_AFFILIATE_ID=your-id FLIPKART_API_KEY=your-key

Authentication

NEXTAUTH_SECRET=generate-a-random-string JWT_SECRET=generate-another-random-string

Cron Jobs

CRON_SECRET=your-cron-secret

Vercel Deployment

VERCEL_TOKEN=your-vercel-token

App Configuration

NEXT_PUBLIC_APP_URL=http://localhost:3000 NODE_ENV=development ```

Deployment

  1. Push to GitHub ```bash git add . git commit -m “Initial commit” git push origin main ```

  2. Connect to Vercel
    • Go to vercel.com
    • Click “New Project”
    • Import your GitHub repository
    • Add environment variables from .env.example
    • Click “Deploy”
  3. Set up Cron Jobs
    • In Vercel dashboard, go to Settings → Cron Jobs
    • Add the cron job from vercel.json
    • Set CRON_SECRET environment variable
  4. Connect Custom Domain
    • In Vercel dashboard, go to Settings → Domains
    • Add your custom domain
    • Follow DNS configuration instructions for your registrar

Deploy to GitHub Pages (Static Export)

For static hosting on GitHub Pages:

  1. Build static export ```bash npm run build npm run export ```

  2. Push to gh-pages branch ```bash git subtree push –prefix out origin gh-pages ```

  3. Enable GitHub Pages

    • Go to repository Settings → Pages
    • Select gh-pages branch as source

Note: GitHub Pages doesn’t support server-side rendering or API routes. Use this only for static content.

Admin Dashboard

Access Admin Panel

  1. Navigate to /admin/login
  2. Log in with your admin credentials
  3. Manage affiliate links and trigger product refreshes
  1. Go to Admin Dashboard
  2. Click “Add Link”
  3. Enter:
    • Name: Platform name (e.g., “Amazon”)
    • Base URL: Affiliate base URL
    • Code: Your affiliate ID/tag
  4. Click “Save Link”

Refresh Products

  1. Go to Admin Dashboard
  2. Click “Refresh Products Now”
  3. Wait for aggregation to complete
  4. Products will be updated with latest data

API Endpoints

Public Endpoints

Admin Endpoints (Requires Bearer Token)

Cron Endpoints

Database Schema

Product

PriceHistory

AdminUser

Customization

Add New Product Sources

Edit lib/product-aggregator.ts:

```typescript export async function fetchYourSource(): Promise<ProductData[]> { // Implement API call to your source return products }

// In aggregateProducts(): const yourProducts = await fetchYourSource() const allProducts = […amazonProducts, …flipkartProducts, …yourProducts] ```

Modify Trend Score Calculation

Edit lib/product-aggregator.ts calculateTrendScore() function to adjust weights.

Customize AI Summaries

Edit the OpenAI prompt in lib/product-aggregator.ts generateProductSummary() function.

Testing

```bash

Run all tests

npm run test

Run tests in watch mode

npm run test:watch

Run tests with coverage

npm run test – –coverage ```

Performance Optimization

Cost Estimation

Troubleshooting

Products not updating

Admin login fails

Database errors

Contributing

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

License

MIT License - see LICENSE file for details

Support

For issues and questions:

Roadmap


Built with ❤️ using Next.js, Prisma, and OpenAI