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.
Clone the repository ```bash git clone https://github.com/yourusername/trendhive.git cd trendhive ```
Install dependencies ```bash npm install ```
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
```
Initialize the database ```bash npm run db:push npm run db:seed ```
Create admin user (optional - for testing)
```bash
npm run db:studio
```
Then manually add a user to the AdminUser table with hashed password.
Start development server ```bash npm run dev ```
Open http://localhost:3000 in your browser.
Create a .env.local file with the following variables:
```env
DATABASE_URL=”file:./dev.db” # SQLite for local, postgresql://… for production
OPENAI_API_KEY=sk-your-key-here
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
NEXTAUTH_SECRET=generate-a-random-string JWT_SECRET=generate-another-random-string
CRON_SECRET=your-cron-secret
VERCEL_TOKEN=your-vercel-token
NEXT_PUBLIC_APP_URL=http://localhost:3000 NODE_ENV=development ```
Push to GitHub ```bash git add . git commit -m “Initial commit” git push origin main ```
.env.examplevercel.jsonCRON_SECRET environment variableFor static hosting on GitHub Pages:
Build static export ```bash npm run build npm run export ```
Push to gh-pages branch ```bash git subtree push –prefix out origin gh-pages ```
Enable GitHub Pages
gh-pages branch as sourceNote: GitHub Pages doesn’t support server-side rendering or API routes. Use this only for static content.
/admin/loginGET /api/products - Get all products (supports filtering)
category, sort, limit/api/products?category=Electronics&sort=trendScore&limit=20GET /api/products/[id] - Get product details with price historyPOST /api/admin/auth/login - Admin login
{ email, password }{ token, email }GET /api/admin/affiliate-links - Get all affiliate linksPOST /api/admin/affiliate-links - Create affiliate linkPUT /api/admin/affiliate-links - Update affiliate linkDELETE /api/admin/affiliate-links - Delete affiliate link
POST /api/admin/refresh-products - Trigger product aggregationGET /api/cron/refresh-products - Automated daily refresh (Vercel Cron)id: Unique identifiertitle: Product namedescription: Product descriptionprice: Current priceoriginalPrice: Original/list priceimage: Product image URLrating: Average rating (0-5)reviewCount: Number of reviewscategory: Product categorysource: Source platform (amazon, flipkart, etc.)sourceUrl: Original product URLtrendScore: Calculated trend score (0-10)aiSummary: AI-generated summarypros: JSON array of proscons: JSON array of conssocialCaption: Social media captionaffiliateLink: Affiliate URLcreatedAt: Creation timestampupdatedAt: Last update timestamplastFetched: Last aggregation timestampid: Unique identifierproductId: Reference to Productprice: Price at this point in timedate: Timestampid: Unique identifiername: Platform namebaseUrl: Base affiliate URLcode: Affiliate ID/tagactive: Whether link is activecreatedAt: Creation timestampupdatedAt: Last update timestampid: Unique identifieremail: Admin emailpassword: Hashed passwordcreatedAt: Creation timestampupdatedAt: Last update timestampEdit 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] ```
Edit lib/product-aggregator.ts calculateTrendScore() function to adjust weights.
Edit the OpenAI prompt in lib/product-aggregator.ts generateProductSummary() function.
```bash
npm run test
npm run test:watch
npm run test – –coverage ```
OPENAI_API_KEY is set correctlyJWT_SECRET and NEXTAUTH_SECRET are setnpm run db:push to sync schemaDATABASE_URL is correctgit checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)MIT License - see LICENSE file for details
For issues and questions:
Built with ❤️ using Next.js, Prisma, and OpenAI