Skip to content

nabarvn/chadgpt

Repository files navigation

Icon

ChadGPT

Your low-key AI agent for the new era!
View Project »

Report BugRequest Feature

Overview

Screenshot

ChadGPT is a full-stack GPT implementation built with Next.js 13, featuring a custom AI persona that delivers direct, confident responses. It streams answers in real-time from OpenAI's API, automatically syncs your chat history across devices with Firebase, and includes Google OAuth authentication. The interface supports full markdown rendering with syntax-highlighted code blocks, while Upstash Redis rate limiting prevents API abuse.

Architecture

The diagram below illustrates the high-level architecture of the ChadGPT application.

graph TD
    User[User] --> Frontend[Next.js Frontend<br/>App Router];
    Frontend -- "Authentication" --> Auth[NextAuth.js<br/>Google OAuth];
    Frontend -- "API Requests" --> API[Next.js API Routes];
    API -- "Rate Limiting" --> Redis[Upstash Redis];
    API -- "AI Chat" --> OpenAI[OpenAI API<br/>Streaming];
    API -- "Store/Retrieve Messages" --> Firestore[Cloud Firestore];
    Frontend -- "Real-time Updates" --> Firestore;

    style Frontend fill:#F5F5F5,color:#000,stroke:#333,stroke-width:2px;
    style Auth fill:#4285F4,color:#fff,stroke:#333,stroke-width:2px;
    style API fill:#000,color:#fff,stroke:#333,stroke-width:2px;
    style Redis fill:#00E9A3,color:#000,stroke:#333,stroke-width:2px;
    style OpenAI fill:#74AA9C,color:#000,stroke:#333,stroke-width:2px;
    style Firestore fill:#FFA611,color:#000,stroke:#333,stroke-width:2px;
Loading

Running Locally

Follow these steps to set up and run ChadGPT on your local machine.

Prerequisites

This application requires:

1. Cloning the Repository

Clone the repository to your local machine:

git clone https://github.com/nabarvn/chadgpt.git
cd chadgpt

2. Installing Dependencies

Install all required dependencies:

npm install

3. Firebase Setup

Create a Firebase project and configure the following:

  1. Enable Firestore Database preferably in test mode to avoid writing security rules
  2. Register a web app and note the config values (apiKey, authDomain, projectId, etc.)
  3. Generate Admin SDK credentials from Service Accounts (download the JSON)

See the Firebase Console and Firestore documentation.

4. Google OAuth Setup

Create OAuth 2.0 credentials in Google Cloud Console:

  • Set authorized redirect URI: http://localhost:3000/api/auth/callback/google
  • Copy the Client ID and Client Secret

Refer to the OAuth 2.0 documentation if needed.

5. OpenAI API Key

Generate an API key from the OpenAI Platform.

6. Upstash Redis Setup

Create a Redis database in Upstash Console and copy the REST URL and token.

7. Environment Variables

Create a local environment file by copying the example:

cp .env.example .env

Important

Open the newly created .env file and populate it with your API keys and configuration values.

For development, set NEXTAUTH_URL to your localhost URL.

To generate a secure NEXTAUTH_SECRET:

openssl rand -base64 32

8. Running the Application

Start the development server:

npm run dev

The application will be available at http://localhost:3000

Tech Stack

Core Framework

Styling & UI

Authentication

Database & Real-time

AI & Streaming

Rate Limiting & Caching

Content Rendering

State Management & Data Fetching

Utilities

Key Features

  • Real-time AI Response Streaming - Watch AI responses appear as they're generated
  • Persistent Chat History - All conversations automatically saved and synced across devices
  • Full Markdown Rendering - Rich text formatting with code syntax highlighting
  • Rate Limiting Protection - Built-in API protection with Redis-backed rate limiting
  • Responsive Design - Seamless experience on desktop, tablet, and mobile devices
  • Dark/Light Theme - Toggle between themes to suit your preference
  • Code Block Copy - One-click copy functionality for code snippets

Don't forget to leave a STAR 🌟

About

The best ChatGPT Clone (legacy version) built with Typescript, Next.js 13, Tailwind, and Firebase.

Topics

Resources

Stars

Watchers

Forks