Back to blog
Blog

Building a Product Hunt Clone with Cosmic and Next.js

Cosmic Intelligence's avatar

Cosmic Intelligence

April 04, 2025

cover image

Introduction

Product Hunt has become the go-to platform for discovering new products and services in tech. In this tutorial, we'll build a simplified Product Hunt clone using Next.js 15 (App Router) with TypeScript for the frontend and Cosmic as our headless CMS. You'll learn how to implement core features like product listings, upvoting, user comments, and product collections.

What we'll be building:

product-hunt-clone.png

Project Setup

Let's begin by creating a new Next.js project:


Choose the following options:

  • TypeScript: Yes
  • ESLint: Yes
  • Tailwind CSS: Yes
  • App Router: Yes
  • Import alias: Yes (use @/ as the import alias)

Next, let's install the Cosmic SDK:


Setting Up Cosmic

First, create a new bucket in your Cosmic dashboard.

Next, we'll create a script to set up our content model and seed some initial data:


Run the seed script to set up your Cosmic bucket with both object types and demo content:


Environment Configuration

Create a file with your Cosmic credentials:


Creating Our API Service

Let's create a service to interact with the Cosmic API:


Building the UI Components

Now let's create the necessary UI components:

Header Component


ProductCard Component


Building the Pages

Homepage


Product Detail Page


Upvote Button Component


Comment Form Component


Collections Page


API Routes for Interactivity

Upvote API


Comments API


Building the Category Page


Collection Detail Page


Conclusion

In this tutorial, we've built a functional Product Hunt clone using Next.js and Cosmic. We've implemented core features like:

  1. Product listings with upvoting functionality
  2. Product detail pages with comments
  3. Categories and collections for product organization
  4. API routes for interactive features

The application demonstrates how Cosmic's headless CMS can be used to power complex web applications with rich content models and relationships between different content types.

Next Steps

To continue improving this application, you could:

  1. Add user authentication with NextAuth.js
  2. Implement product submission functionality
  3. Add search capabilities
  4. Create user profiles
  5. Add analytics to track product popularity
  6. Implement email notifications for new products or comments

The flexibility of Cosmic's content model allows you to easily extend this application with additional features as needed.

You can find more developer resources at the Cosmic documentation and explore ready-to-use templates in the Cosmic templates gallery.