Skip to content

brown2020/xrefaiapp

Repository files navigation

Xref.ai

Next.js React TypeScript Tailwind CSS Firebase License: MIT

An AI-powered content generation platform built with Next.js 16, React 19, and Firebase. Xref.ai helps you create original content for blog posts, essays, marketing copy, product descriptions, and more using advanced AI capabilities.

πŸš€ Features

  • πŸ’¬ AI Chat β€” Real-time conversational AI with streaming responses and conversation memory
  • πŸ“ Text Summarization β€” Summarize any topic or scrape websites for content summarization
  • ✨ Freestyle Writing β€” Generate creative content from custom prompts
  • πŸ“– Text Simplification β€” Simplify complex text to different reading levels (1st Grade to PhD)
  • 🎨 Image Generation β€” Create AI-generated images from text descriptions
  • 🎯 Designer Tool β€” Mix creative elements (colors, artists, styles) to generate unique visual designs
  • πŸ“œ History β€” View and manage all your past generations
  • πŸ’³ Payments β€” Stripe integration for premium features and credits

πŸ“‹ Table of Contents

πŸ›  Tech Stack

Core Framework

Package Version Purpose
Next.js 16.x React framework with App Router and Turbopack
React 19.x UI library with latest features
TypeScript 5.x Type safety and developer experience

AI & Machine Learning

Package Version Purpose
Vercel AI SDK 6.x Streaming AI responses and model integration
@ai-sdk/react 3.x UI hooks for streaming chat
@ai-sdk/openai 3.x OpenAI provider for text generation
@ai-sdk/anthropic 3.x Anthropic provider
@ai-sdk/xai 3.x xAI provider
@ai-sdk/google 3.x Google provider
@ai-sdk/rsc 2.x Server Actions streaming

Backend & Database

Package Version Purpose
Firebase 12.x Authentication, Firestore database, Cloud Storage
Firebase Admin 13.x Server-side Firebase operations
Stripe 20.x Payment processing

UI & Styling

Package Version Purpose
Tailwind CSS 4.x Utility-first CSS framework
Lucide React 0.562.x Beautiful icon library
React Select 5.x Advanced select/dropdown components
React Markdown 10.x Render markdown content
React Hot Toast 2.x Toast notifications

State Management & Utilities

Package Version Purpose
Zustand 5.x Lightweight state management
Axios 1.x HTTP client for API requests
Cheerio 1.x HTML parsing for web scraping
Lodash 4.x Utility functions

Additional Libraries

Package Purpose
react-scroll-to-bottom Auto-scrolling chat container
react-textarea-autosize Auto-expanding textareas
react-simple-typewriter Typewriter effect animations
react-cookie-consent GDPR cookie consent banner
react-firebase-hooks Firebase React hooks
remark-gfm GitHub Flavored Markdown support
sharp Image processing and optimization
cookies-next Cookie management for Next.js

πŸ“¦ Prerequisites

Before you begin, ensure you have:

  • Node.js 18.x or higher
  • npm 9.x or higher (or yarn/pnpm)
  • A Firebase project with:
    • Authentication enabled (Email/Password and/or Google)
    • Firestore Database
    • Cloud Storage
  • An OpenAI API key (optional if you use credits only)
  • A Fireworks AI API key (for image generation)
  • A Stripe account (for payments)
    • Optional: Anthropic, xAI, or Google API keys for alternate models

πŸ”§ Installation

  1. Clone the repository

    git clone https://github.com/brown2020/xrefaiapp.git
    cd xrefaiapp
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp .env.example .env.local

    Fill in your credentials (see Environment Variables)

  4. Run the development server

    npm run dev
  5. Open in browser

    Navigate to http://localhost:3000

πŸ” Environment Variables

Create a .env.local file in the root directory with the following variables:

# Firebase Client Configuration
NEXT_PUBLIC_FIREBASE_APIKEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTHDOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECTID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGEBUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGINGSENDERID=your_sender_id
NEXT_PUBLIC_FIREBASE_APPID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENTID=G-XXXXXXXXXX

# Firebase Admin (Server-side)
FIREBASE_TYPE=service_account
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_PRIVATE_KEY_ID=your_private_key_id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your_project.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=your_client_id
FIREBASE_AUTH_URI=https://accounts.google.com/o/oauth2/auth
FIREBASE_TOKEN_URI=https://oauth2.googleapis.com/token
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oauth2/v1/certs
FIREBASE_CLIENT_CERTS_URL=https://www.googleapis.com/robot/v1/metadata/x509/...

# AI Providers (used when credits are enabled)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=...
XAI_API_KEY=...
GOOGLE_API_KEY=...

# Fireworks AI (Image Generation)
FIREWORKS_API_KEY=your_fireworks_api_key

# Stripe
NEXT_PUBLIC_STRIPE_KEY=pk_...
STRIPE_SECRET_KEY=sk_...
NEXT_PUBLIC_STRIPE_PRODUCT_NAME=Xref.ai Credits
APP_URL=https://your-production-domain.com

# Optional
NEXT_PUBLIC_COOKIE_NAME=xrefAuthToken

# Optional (native IAP WebView)
IAP_WEBVIEW_SECRET=your_shared_hmac_secret

Getting API Keys

Service Where to Get
Firebase Firebase Console β†’ Project Settings
OpenAI OpenAI Platform
Fireworks AI Fireworks Console
Stripe Stripe Dashboard

πŸ“ Project Structure

xrefaiapp/
β”œβ”€β”€ public/                 # Static assets
β”‚   └── .well-known/        # App associations (iOS/Android deep links)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ actions/            # Server Actions
β”‚   β”‚   β”œβ”€β”€ generateAIResponse.ts    # Unified AI text generation
β”‚   β”‚   β”œβ”€β”€ generateImage.ts         # AI image generation
β”‚   β”‚   β”œβ”€β”€ confirmIapPurchase.ts    # Native IAP fulfillment
β”‚   β”‚   β”œβ”€β”€ paymentActions.ts        # Stripe payment handling
β”‚   β”‚   └── suggestTags.ts           # AI tag suggestions
β”‚   β”‚
β”‚   β”œβ”€β”€ app/                # Next.js App Router pages
β”‚   β”‚   β”œβ”€β”€ api/proxy/      # Web scraping proxy endpoint
β”‚   β”‚   β”œβ”€β”€ api/chat/       # AI chat streaming endpoint
β”‚   β”‚   β”œβ”€β”€ chat/           # AI chat interface
β”‚   β”‚   β”œβ”€β”€ tools/          # AI writing tools
β”‚   β”‚   β”œβ”€β”€ history/        # Generation history
β”‚   β”‚   β”œβ”€β”€ account/        # User account management
β”‚   β”‚   └── ...             # Other pages
β”‚   β”‚
β”‚   β”œβ”€β”€ components/         # React components
β”‚   β”‚   β”œβ”€β”€ ui/             # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ icons/          # SVG icon components
β”‚   β”‚   β”œβ”€β”€ DesignerPrompt/ # Designer tool components
β”‚   β”‚   └── ...             # Feature components
β”‚   β”‚
β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useChatMessages.ts     # Chat history management
β”‚   β”‚   β”œβ”€β”€ useHistorySaver.ts     # Save to Firestore
β”‚   β”‚   └── ...
β”‚   β”‚
β”‚   β”œβ”€β”€ firebase/           # Firebase configuration
β”‚   β”‚   β”œβ”€β”€ firebaseClient.ts      # Client-side SDK
β”‚   β”‚   └── firebaseAdmin.ts       # Admin SDK (server)
β”‚   β”‚
β”‚   β”œβ”€β”€ zustand/            # State management stores
β”‚   β”‚   β”œβ”€β”€ useAuthStore.ts        # Authentication state
β”‚   β”‚   β”œβ”€β”€ useProfileStore.ts     # User profile state
β”‚   β”‚   └── usePaymentsStore.ts    # Payment/credits state
β”‚   β”‚
β”‚   β”œβ”€β”€ data/               # Static data (painters, colors, etc.)
β”‚   β”œβ”€β”€ types/              # TypeScript type definitions
β”‚   └── utils/              # Utility functions
β”‚
β”œβ”€β”€ .env.example            # Environment variables template
β”œβ”€β”€ next.config.mjs         # Next.js configuration
β”œβ”€β”€ tailwind.config.ts      # Tailwind CSS configuration
└── tsconfig.json           # TypeScript configuration

🎯 Features Deep Dive

AI Chat (/chat)

A full-featured chat interface with:

  • Streaming responses β€” UI streaming via AI SDK useChat and /api/chat
  • Conversation memory β€” AI remembers context from previous messages
  • Persistent history β€” Conversations saved to Firestore
  • Load more β€” Pagination for older messages

Tools (/tools)

Six AI-powered writing tools:

Tool Description
Summarize Website Enter a URL to scrape and summarize web content
Summarize Text Paste text to get a concise summary
Freestyle Writing Generate creative content from any prompt
Simplify Writing Convert complex text to simpler reading levels
Generate Image Create AI images from text descriptions
Designer Tool Combine creative elements for unique visual designs

History (/history)

  • View all past generations (text and images)
  • Search through history
  • Copy or download previous outputs
  • Expandable conversation view

Account Management (/account)

  • View profile information
  • Manage credits and payments
  • Delete account option

πŸ— Architecture

Server Actions & API Routes

Xref.ai uses Server Actions for tools and API routes for chat streaming with AI SDK UI:

// Example: /api/chat route (AI SDK UI)
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({
    model: openai("gpt-5.4"),
    messages,
  });

  return result.toUIMessageStreamResponse();
}

State Management (Zustand)

Lightweight, modular stores:

  • useAuthStore β€” User authentication state
  • useProfileStore β€” User profile and preferences
  • usePaymentsStore β€” Credits and payment status

Firestore Data Model

users/
  └── {uid}/
      β”œβ”€β”€ profile          # User profile document
      β”œβ”€β”€ summaries/       # Text generation history
      β”‚   └── {docId}
      └── chats/           # Chat conversation history
          └── {docId}

πŸ“‘ API Reference

Web Scraping Proxy

GET /api/proxy?url={encoded_url}

Fetches and returns HTML content from the specified URL for summarization.

Parameters:

  • url (required): URL-encoded website address

Response: Raw HTML content

API Routes

Endpoint Purpose Input
POST /api/chat Streaming chat responses messages, history, model
POST /api/billing/checkout Start Stripe checkout session packId, redirectPath
POST /api/billing/confirm Confirm Stripe checkout session sessionId
GET /api/proxy Web scraping proxy url

Server Actions

Action Purpose Input
generateResponse Generate text from prompt systemPrompt, userPrompt
generateResponseWithMemory Generate with conversation context systemPrompt, chatHistory[]
generateImage Create AI image prompt
suggestTags Get tag suggestions freestyle, tags[]
createPaymentIntent Start Stripe payment amount
validatePaymentIntent Verify payment paymentIntentId

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository

  2. Create a feature branch

    git checkout -b feature/amazing-feature
  3. Make your changes

    • Follow the existing code style
    • Add TypeScript types for new code
    • Test your changes locally
  4. Commit your changes

    git commit -m "Add amazing feature"
  5. Push to your fork

    git push origin feature/amazing-feature
  6. Open a Pull Request

Development Guidelines

  • Use TypeScript for all new code
  • Follow functional components with hooks
  • Use Tailwind CSS for styling
  • Use Server Actions for tool generation and API routes for chat streaming
  • Use Zustand for global state management
  • Keep components modular and reusable

Available Scripts

npm run dev      # Start development server (Turbopack)
npm run build    # Build for production
npm run start    # Start production server
npm run lint     # Run ESLint

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

πŸ“ž Support


Built with ❀️ by brown2020

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors