Convert Figma logo to code with AI

adrianhajdin logoproject_next_14_ai_prompt_sharing

Next.js recently became the official React framework as outlined in React docs. In this course, you'll learn the most important Next.js concepts and how they fit into the React ecosystem. Finally, you'll put your skills to the test by building a modern full-stack Next 14 application.

2,778
412
2,778
78

Top Related Projects

9,746

Build AI-powered applications with React, Svelte, Vue, and Solid

Examples and guides for using the OpenAI API

16,363

AI agent stdlib that works with any LLM and TypeScript AI SDK.

93,526

🦜🔗 Build context-aware reasoning applications

Integrate cutting-edge LLM technology quickly and easily into your apps

Quick Overview

This project is a modern web application for sharing AI-generated prompts. It's built using Next.js 14, leveraging its latest features and best practices. The application allows users to create, share, and discover AI prompts, fostering a community of AI enthusiasts and creators.

Pros

  • Utilizes the latest Next.js 14 features, ensuring a modern and efficient development experience
  • Implements a clean and responsive user interface, enhancing user experience across devices
  • Integrates with MongoDB for robust data storage and management
  • Incorporates user authentication for personalized experiences and content management

Cons

  • Limited to AI prompt sharing, which may not appeal to a broader audience
  • Requires familiarity with Next.js and React ecosystem for effective contributions
  • Potential scalability challenges as the user base and content grow
  • Dependency on third-party services (e.g., MongoDB) may introduce complexity in deployment and maintenance

Code Examples

  1. Creating a new prompt:
const createPrompt = async (e) => {
  e.preventDefault();
  setSubmitting(true);

  try {
    const response = await fetch("/api/prompt/new", {
      method: "POST",
      body: JSON.stringify({
        prompt: post.prompt,
        userId: session?.user.id,
        tag: post.tag,
      }),
    });

    if (response.ok) {
      router.push("/");
    }
  } catch (error) {
    console.log(error);
  } finally {
    setSubmitting(false);
  }
};
  1. Fetching prompts:
const fetchPosts = async () => {
  const response = await fetch("/api/prompt");
  const data = await response.json();

  setPosts(data);
};
  1. Implementing user authentication:
import { getProviders, signIn, signOut, useSession } from "next-auth/react";

const Nav = () => {
  const { data: session } = useSession();

  return (
    <nav>
      {session?.user ? (
        <div>
          <Image
            src={session?.user.image}
            width={37}
            height={37}
            className="rounded-full"
            alt="profile"
          />
          <button type="button" onClick={signOut}>
            Sign Out
          </button>
        </div>
      ) : (
        <>
          {providers &&
            Object.values(providers).map((provider) => (
              <button
                type="button"
                key={provider.name}
                onClick={() => signIn(provider.id)}
              >
                Sign In
              </button>
            ))}
        </>
      )}
    </nav>
  );
};

Getting Started

  1. Clone the repository:

    git clone https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing.git
    
  2. Install dependencies:

    cd project_next_14_ai_prompt_sharing
    npm install
    
  3. Set up environment variables: Create a .env file in the root directory and add necessary variables (e.g., MongoDB connection string, NextAuth secret).

  4. Run the development server:

    npm run dev
    
  5. Open http://localhost:3000 in your browser to view the application.

Competitor Comparisons

9,746

Build AI-powered applications with React, Svelte, Vue, and Solid

Pros of ai

  • Comprehensive AI library with support for multiple models and providers
  • Extensive documentation and examples for various use cases
  • Active development and frequent updates

Cons of ai

  • Steeper learning curve due to its broader scope
  • May include unnecessary features for simple projects
  • Requires more setup and configuration

Code Comparison

project_next_14_ai_prompt_sharing:

const PromptCard = ({ post, handleTagClick, handleEdit, handleDelete }) => {
  // Component logic
};

ai:

import { useCompletion } from 'ai/react';

export default function Chat() {
  const { completion, input, handleInputChange, handleSubmit } = useCompletion();
  // Component logic
}

The project_next_14_ai_prompt_sharing repository focuses on a specific use case of prompt sharing, while ai provides a more general-purpose AI development toolkit. The code snippets demonstrate the difference in approach, with project_next_14_ai_prompt_sharing using custom components for prompt management, and ai offering pre-built hooks for AI interactions.

Examples and guides for using the OpenAI API

Pros of openai-cookbook

  • Comprehensive collection of OpenAI API usage examples and best practices
  • Regularly updated with new features and improvements from OpenAI
  • Extensive documentation and explanations for various AI tasks

Cons of openai-cookbook

  • Focused solely on OpenAI's offerings, limiting its scope
  • May be overwhelming for beginners due to its extensive content
  • Lacks a specific application or project structure

Code Comparison

project_next_14_ai_prompt_sharing:

import { connectToDB } from "@utils/database";
import Prompt from "@models/prompt";

export const GET = async (request) => {
    try {
        await connectToDB()
        const prompts = await Prompt.find({}).populate('creator')

openai-cookbook:

import openai

response = openai.Completion.create(
  model="text-davinci-002",
  prompt="Translate the following English text to French: '{}'",
  temperature=0.3,
  max_tokens=60
)

project_next_14_ai_prompt_sharing is a Next.js application for sharing AI prompts, while openai-cookbook is a collection of examples and guides for using OpenAI's API. The former provides a full-stack application structure, while the latter focuses on demonstrating various AI capabilities using OpenAI's services.

16,363

AI agent stdlib that works with any LLM and TypeScript AI SDK.

Pros of agentic

  • Focuses on building AI agents and workflows, offering more advanced AI capabilities
  • Provides a flexible framework for creating custom AI-powered applications
  • Has a larger community with more stars and contributors

Cons of agentic

  • More complex and requires deeper understanding of AI concepts
  • Less beginner-friendly compared to the Next.js project
  • May have a steeper learning curve for developers new to AI

Code Comparison

project_next_14_ai_prompt_sharing:

const PromptCard = ({ post, handleTagClick, handleEdit, handleDelete }) => {
  return (
    <div className='prompt_card'>
      <div className='flex justify-between items-start gap-5'>
        <div className='flex-1 flex justify-start items-center gap-3 cursor-pointer'>
          <Image
            src={post.creator.image}
            alt='user_image'
            width={40}
            height={40}
            className='rounded-full object-contain'
          />
        </div>
      </div>
    </div>
  );
};

agentic:

class Agent:
    def __init__(self, name: str, description: str):
        self.name = name
        self.description = description
        self.memory = Memory()
        self.tools = []

    def add_tool(self, tool: Tool):
        self.tools.append(tool)

    async def run(self, task: str) -> str:
        # Agent execution logic
93,526

🦜🔗 Build context-aware reasoning applications

Pros of langchain

  • More comprehensive and versatile, offering a wide range of AI/LLM integration tools
  • Actively maintained with frequent updates and a large community
  • Extensive documentation and examples for various use cases

Cons of langchain

  • Steeper learning curve due to its extensive feature set
  • May be overkill for simple AI prompt sharing projects
  • Requires more setup and configuration

Code Comparison

project_next_14_ai_prompt_sharing:

const CreatePrompt = ({ type, post, setPost, submitting, handleSubmit }) => {
  return (
    <Form
      type={type}
      post={post}
      setPost={setPost}
      submitting={submitting}
      handleSubmit={handleSubmit}
    />
  );
};

langchain:

from langchain import OpenAI, LLMChain, PromptTemplate

llm = OpenAI(temperature=0.9)
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)
chain = LLMChain(llm=llm, prompt=prompt)

The project_next_14_ai_prompt_sharing code focuses on creating a form component for prompt sharing, while langchain demonstrates setting up an LLM chain for generating company names based on products. langchain offers more flexibility and power for complex AI tasks, but project_next_14_ai_prompt_sharing provides a simpler solution for basic prompt sharing functionality.

Integrate cutting-edge LLM technology quickly and easily into your apps

Pros of semantic-kernel

  • More comprehensive AI integration framework
  • Broader language support (C#, Python, Java)
  • Extensive documentation and examples

Cons of semantic-kernel

  • Steeper learning curve
  • More complex setup and configuration
  • Less focused on specific use case (prompt sharing)

Code Comparison

semantic-kernel:

using Microsoft.SemanticKernel;

var kernel = Kernel.Builder.Build();
var promptTemplate = "{{$input}}";
var function = kernel.CreateSemanticFunction(promptTemplate);
var result = await function.InvokeAsync("Hello, world!");

project_next_14_ai_prompt_sharing:

import { connectToDB } from "@utils/database";
import Prompt from "@models/prompt";

export const POST = async (request) => {
  const { userId, prompt, tag } = await request.json();
  try {
    await connectToDB();
    const newPrompt = new Prompt({ creator: userId, prompt, tag });
    await newPrompt.save();
    return new Response(JSON.stringify(newPrompt), { status: 201 })
  } catch (error) {
    return new Response("Failed to create a new prompt", { status: 500 });
  }
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


Project Banner
Next.js mongodb tailwindcss

Next.js 14 AI Prompt Sharing Application

Build this project step by step with our detailed tutorial on JavaScript Mastery YouTube. Join the JSM family!

📋 Table of Contents

  1. 🤖 Introduction
  2. ⚙️ Tech Stack
  3. 🔋 Features
  4. 🤸 Quick Start
  5. 🕸️ Snippets
  6. 🔗 Links
  7. 🚀 More

🚨 Tutorial

This repository contains the code corresponding to an in-depth tutorial available on our YouTube channel, JavaScript Mastery.

If you prefer visual learning, this is the perfect resource for you. Follow our tutorial to learn how to build projects like these step-by-step in a beginner-friendly manner!

🤖 Introduction

Develop a Next.js application that highlights the key features of Next.js along with a comprehensive CRUD AI Prompt sharing system utilizing a MongoDB database and implementing NextAuth authentication.

If you're getting started and need assistance or face any bugs, join our active Discord community with over 27k+ members. It's a place where people help each other out.

⚙️ Tech Stack

  • Next.js
  • MongoDB
  • NextAuth
  • TailwindCSS

🔋 Features

👉 Modern Design with Glassmorphism Trend Style: A modern and visually appealing design, incorporating the glassmorphism trend style for a sleek and contemporary appearance.

👉 Discover and Share AI Prompts: Allow users to discover AI prompts shared by the community and create their own prompts to share with the world.

👉 Edit and Delete Created Prompts: Users have the ability to edit their created prompts at any time and delete them when needed.

👉 Profile Page: Each user gets a dedicated profile page showcasing all the prompts they've created, providing an overview of their contributions.

👉 View Other People's Profiles: Users can explore the profiles of other creators to view the prompts they've shared, fostering a sense of community.

👉 Copy to Clipboard: Implement a convenient "Copy to Clipboard" functionality for users to easily copy the AI prompts for their use.

👉 Search Prompts by Specific Tag: Allow users to search for prompts based on specific tags, making it easier to find prompts related to specific topics.

👉 Google Authentication using NextAuth: Enable secure Google authentication using NextAuth, ensuring a streamlined and trustworthy login experience.

👉 Responsive Website: Develop a fully responsive website to ensure optimal user experience across various devices, from desktops to smartphones

and many more, including code architecture and reusability

🤸 Quick Start

Follow these steps to set up the project locally on your machine.

Prerequisites

Make sure you have the following installed on your machine:

Cloning the Repository

git clone https://github.com/adrianhajdin/project_next_13_ai_prompt_sharing.git
cd project_next_13_ai_prompt_sharing

Installation

Install the project dependencies using npm:

npm install

Set Up Environment Variables

Create a new file named .env in the root of your project and add the following content:

NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_URL_INTERNAL=http://localhost:3000
NEXTAUTH_SECRET=
GOOGLE_ID=
GOOGLE_CLIENT_SECRET=
MONGODB_URI=

Replace the placeholder values with your actual credentials. You can obtain these credentials by signing up on these corresponding websites from Google Cloud Console, Cryptpool (for random Auth Secret), and MongoDB.

Running the Project

npm run dev

Open http://localhost:3000 in your browser to view the project.

🕸️ Snippets

globals.css
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");

@tailwind base;
@tailwind components;
@tailwind utilities;

/* 
  Note: The styles for this gradient grid background is heavily inspired by the creator of this amazing site (https://dub.sh) – all credits go to them! 
*/

.main {
  width: 100vw;
  min-height: 100vh;
  position: fixed;
  display: flex;
  justify-content: center;
  padding: 120px 24px 160px 24px;
  pointer-events: none;
}

.main:before {
  background: radial-gradient(circle, rgba(2, 0, 36, 0) 0, #fafafa 100%);
  position: absolute;
  content: "";
  z-index: 2;
  width: 100%;
  height: 100%;
  top: 0;
}

.main:after {
  content: "";
  background-image: url("/assets/images/grid.svg");
  z-index: 1;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  opacity: 0.4;
  filter: invert(1);
}

.gradient {
  height: fit-content;
  z-index: 3;
  width: 100%;
  max-width: 640px;
  background-image: radial-gradient(
      at 27% 37%,
      hsla(215, 98%, 61%, 1) 0px,
      transparent 0%
    ),
    radial-gradient(at 97% 21%, hsla(125, 98%, 72%, 1) 0px, transparent 50%),
    radial-gradient(at 52% 99%, hsla(354, 98%, 61%, 1) 0px, transparent 50%),
    radial-gradient(at 10% 29%, hsla(256, 96%, 67%, 1) 0px, transparent 50%),
    radial-gradient(at 97% 96%, hsla(38, 60%, 74%, 1) 0px, transparent 50%),
    radial-gradient(at 33% 50%, hsla(222, 67%, 73%, 1) 0px, transparent 50%),
    radial-gradient(at 79% 53%, hsla(343, 68%, 79%, 1) 0px, transparent 50%);
  position: absolute;
  content: "";
  width: 100%;
  height: 100%;
  filter: blur(100px) saturate(150%);
  top: 80px;
  opacity: 0.15;
}

@media screen and (max-width: 640px) {
  .main {
    padding: 0;
  }
}

/* Tailwind Styles */

.app {
  @apply relative z-10 flex justify-center items-center flex-col max-w-7xl mx-auto sm:px-16 px-6;
}

.black_btn {
  @apply rounded-full border border-black bg-black py-1.5 px-5 text-white transition-all hover:bg-white hover:text-black text-center text-sm font-inter flex items-center justify-center;
}

.outline_btn {
  @apply rounded-full border border-black bg-transparent py-1.5 px-5 text-black transition-all hover:bg-black hover:text-white text-center text-sm font-inter flex items-center justify-center;
}

.head_text {
  @apply mt-5 text-5xl font-extrabold leading-[1.15] text-black sm:text-6xl;
}

.orange_gradient {
  @apply bg-gradient-to-r from-amber-500 via-orange-600 to-yellow-500 bg-clip-text text-transparent;
}

.green_gradient {
  @apply bg-gradient-to-r from-green-400 to-green-500 bg-clip-text text-transparent;
}

.blue_gradient {
  @apply bg-gradient-to-r from-blue-600 to-cyan-600 bg-clip-text text-transparent;
}

.desc {
  @apply mt-5 text-lg text-gray-600 sm:text-xl max-w-2xl;
}

.search_input {
  @apply block w-full rounded-md border border-gray-200 bg-white py-2.5 font-satoshi pl-5 pr-12 text-sm shadow-lg font-medium focus:border-black focus:outline-none focus:ring-0;
}

.copy_btn {
  @apply w-7 h-7 rounded-full bg-white/10 shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.2)] backdrop-blur flex justify-center items-center cursor-pointer;
}

.glassmorphism {
  @apply rounded-xl border border-gray-200 bg-white/20 shadow-[inset_10px_-50px_94px_0_rgb(199,199,199,0.2)] backdrop-blur p-5;
}

.prompt_layout {
  @apply space-y-6 py-8 sm:columns-2 sm:gap-6 xl:columns-3;
}

/* Feed Component */
.feed {
  @apply mt-16 mx-auto w-full max-w-xl flex justify-center items-center flex-col gap-2;
}

/* Form Component */
.form_textarea {
  @apply w-full flex rounded-lg h-[200px] mt-2 p-3 text-sm text-gray-500 outline-0;
}

.form_input {
  @apply w-full flex rounded-lg mt-2 p-3 text-sm text-gray-500 outline-0;
}

/* Nav Component */
.logo_text {
  @apply max-sm:hidden font-satoshi font-semibold text-lg text-black tracking-wide;
}

.dropdown {
  @apply absolute right-0 top-full mt-3 w-full p-5 rounded-lg bg-white min-w-[210px] flex flex-col gap-2 justify-end items-end;
}

.dropdown_link {
  @apply text-sm font-inter text-gray-700 hover:text-gray-500 font-medium;
}

/* PromptCard Component */
.prompt_card {
  @apply flex-1 break-inside-avoid rounded-lg border border-gray-300 bg-white/20 bg-clip-padding p-6 pb-4 backdrop-blur-lg backdrop-filter md:w-[360px] w-full h-fit;
}

.flex-center {
  @apply flex justify-center items-center;
}

.flex-start {
  @apply flex justify-start items-start;
}

.flex-end {
  @apply flex justify-end items-center;
}

.flex-between {
  @apply flex justify-between items-center;
}
jsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@*": ["./*"]
    }
  }
}
route.js
import Prompt from "@models/prompt";
import { connectToDB } from "@utils/database";

export const GET = async (request, { params }) => {
    try {
        await connectToDB()

        const prompt = await Prompt.findById(params.id).populate("creator")
        if (!prompt) return new Response("Prompt Not Found", { status: 404 });

        return new Response(JSON.stringify(prompt), { status: 200 })

    } catch (error) {
        return new Response("Internal Server Error", { status: 500 });
    }
}

export const PATCH = async (request, { params }) => {
    const { prompt, tag } = await request.json();

    try {
        await connectToDB();

        // Find the existing prompt by ID
        const existingPrompt = await Prompt.findById(params.id);

        if (!existingPrompt) {
            return new Response("Prompt not found", { status: 404 });
        }

        // Update the prompt with new data
        existingPrompt.prompt = prompt;
        existingPrompt.tag = tag;

        await existingPrompt.save();

        return new Response("Successfully updated the Prompts", { status: 200 });
    } catch (error) {
        return new Response("Error Updating Prompt", { status: 500 });
    }
};

export const DELETE = async (request, { params }) => {
    try {
        await connectToDB();

        // Find the prompt by ID and remove it
        await Prompt.findByIdAndRemove(params.id);

        return new Response("Prompt deleted successfully", { status: 200 });
    } catch (error) {
        return new Response("Error deleting prompt", { status: 500 });
    }
};
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
    './app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  theme: {
    extend: {
      fontFamily: {
        satoshi: ['Satoshi', 'sans-serif'],
        inter: ['Inter', 'sans-serif'],
      },
      colors: {
        'primary-orange': '#FF5722',
      }
    },
  },
  plugins: [],
}
user.js
username: {
    type: String,
    required: [true, 'Username is required!'],
    match: [/^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/, "Username invalid, it should contain 8-20 alphanumeric letters and be unique!"]
  },

🔗 Links

Assets used in the project can be found here

🚀 More

Advance your skills with Next.js 14 Pro Course

Enjoyed creating this project? Dive deeper into our PRO courses for a richer learning adventure. They're packed with detailed explanations, cool features, and exercises to boost your skills. Give it a go!

Project Banner

Accelerate your professional journey with the Expert Training program

And if you're hungry for more than just a course and want to understand how we learn and tackle tech challenges, hop into our personalized masterclass. We cover best practices, different web skills, and offer mentorship to boost your confidence. Let's learn and grow together!

Project Banner