Skip to content

abreuclariana/nextjs-ts-consulting-scheduler

Repository files navigation

Nextjs Ts Consulting Scheduler

A complete interactive scheduling and booking system built with Next.js 16, TypeScript, Supabase, Stripe payment integration, and AI-powered chat support.

πŸš€ Features

  • πŸ“… Interactive Calendar - Dynamic date and time slot selection with real-time availability
  • πŸ’³ Stripe Payment Processing - Real payment integration with Stripe Elements
  • πŸ€– AI Chat Widget - Floating chat assistant powered by OpenAI GPT-4o-mini with conversation history and semantic memory
  • 🌍 Trilingual Support - Full i18n support (English, Portuguese, Spanish)
  • 🧠 Contextual Memory - Embedding-based recall of previous conversations stored in Supabase pgvector
  • πŸ”„ Booking Management - Create, view, and cancel appointments with persistent storage
  • 🎨 Modern UI/UX - Beautiful, responsive design with Tailwind CSS
  • πŸ”’ Database Persistence - PostgreSQL database via Supabase with Row Level Security
  • πŸ“§ Payment Webhooks - Automatic payment confirmation via Stripe webhooks
  • πŸ’¬ Conversation History - Chat messages stored in Supabase for context-aware responses
  • 🌐 Web Scraping Toolkit - Built-in utilities for collecting and analysing external website data
  • ⚑ Edge Functions Ready - Supabase Edge Functions prepared for serverless chat processing
  • πŸ” Semantic Search - Real-time embeddings and pgvector similarity search powering the chat agent

πŸ› οΈ Tech Stack

Frontend

  • Next.js 16.0.1 - React framework with App Router
  • React 19.2.0 - Latest React version
  • TypeScript - Static type checking
  • Tailwind CSS - Utility-first CSS framework
  • Zustand - Lightweight state management
  • Lucide React - Icon library

Backend & Services

  • Supabase - Backend as a Service (PostgreSQL database)
    • Edge Functions - Serverless functions (Deno runtime) for chat processing
    • pgvector - Vector similarity search powering semantic memory
  • Stripe - Payment processing and webhooks
  • OpenAI API - GPT-4o-mini for AI chat responses
  • pgvector - Embedding storage for semantic recall

Data & Automation

  • Cheerio - HTML parsing for web scraping and data extraction
  • Custom Web Scraper - Helper utilities for keyword extraction, metadata parsing, and reading-time analysis

Utilities

  • date-fns - Date manipulation library
  • clsx - Conditional className utility

πŸ“¦ Installation

npm install

πŸ”§ Environment Setup

Create .env.local file in the root:

# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key

# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

# OpenAI (for chat widget)
OPENAI_API_KEY=sk-...

Database Setup

  1. Create a Supabase project at supabase.com
  2. Run migrations in SQL Editor:
    • Execute supabase/schema.sql to create booking tables
    • Execute supabase/rls.sql to set up security policies
    • Execute supabase/chat_schema.sql to create chat tables
    • Execute each file in supabase/migrations (or run supabase db push) to apply incremental schema updates, including semantic memory support (chat_memories)

Chat Setup

  1. Get your OpenAI API key from platform.openai.com
  2. Add OPENAI_API_KEY to your .env.local file
  3. The chat widget will automatically appear on the landing page

For detailed setup: See SUPABASE_SETUP.md and STRIPE_SETUP.md

πŸƒ Running the Application

npm run dev

Open http://localhost:3000 in your browser.

πŸ“ Project Structure

src/
β”œβ”€β”€ app/                    # Next.js App Router (Routes & Pages)
β”‚   β”œβ”€β”€ api/                # API Routes (Backend)
β”‚   β”‚   β”œβ”€β”€ slots/         # GET: Available time slots
β”‚   β”‚   β”œβ”€β”€ appointments/   # CRUD: Booking operations
β”‚   β”‚   β”œβ”€β”€ payment-intent/ # POST: Create Stripe Payment Intent
β”‚   β”‚   β”œβ”€β”€ chat/          # POST: Chat API proxy
β”‚   β”‚   └── webhooks/stripe/# POST: Stripe webhook handler
β”‚   β”œβ”€β”€ schedule/[serviceId]/ # Scheduling page
β”‚   β”œβ”€β”€ appointments/       # Booking list page
β”‚   β”œβ”€β”€ confirmation/[id]/ # Confirmation page
β”‚   └── page.tsx            # Landing page (with chat widget)
β”œβ”€β”€ components/             # Reusable UI Components
β”‚   β”œβ”€β”€ Calendar/          # Calendar components
β”‚   β”œβ”€β”€ Form/              # Booking & Payment forms
β”‚   β”œβ”€β”€ ChatWidget.tsx     # AI chat widget component
β”‚   └── LanguageSelector.tsx
β”œβ”€β”€ lib/                    # Core Logic & Services
β”‚   β”œβ”€β”€ supabase/          # Supabase integration
β”‚   β”‚   β”œβ”€β”€ client.ts      # Browser client
β”‚   β”‚   β”œβ”€β”€ server.ts      # Server client
β”‚   β”‚   └── database.ts    # Database operations
β”‚   β”œβ”€β”€ stripe/            # Stripe integration
β”‚   β”‚   β”œβ”€β”€ client.ts      # Frontend Stripe.js
β”‚   β”‚   └── server.ts      # Backend Stripe SDK
β”‚   β”œβ”€β”€ api-service.ts     # HTTP client
β”‚   β”œβ”€β”€ services.ts        # Service definitions
β”‚   └── time-utils.ts      # Time slot utilities
β”œβ”€β”€ context/               # React Context Providers
β”‚   β”œβ”€β”€ AppointmentContext.tsx
β”‚   └── LanguageContext.tsx # i18n provider
β”œβ”€β”€ locales/               # Translation Files (en/pt/es)
└── types/                 # TypeScript definitions
supabase/
β”œβ”€β”€ functions/             # Supabase Edge Functions (Deno)
β”‚   └── chat/              # Chat Edge Function (alternative to API route)
β”‚       β”œβ”€β”€ index.ts       # Edge Function handler
β”‚       └── deno.json      # Deno configuration
β”œβ”€β”€ schema.sql             # Main database schema
β”œβ”€β”€ rls.sql                # Row Level Security policies
└── chat_schema.sql        # Chat tables schema

πŸ”„ Application Flow

  1. Landing Page β†’ View services, select service, or chat with AI assistant
  2. Schedule Page β†’ Select date and time slot (dynamic availability)
  3. Booking Form β†’ Enter customer details β†’ Stripe payment
  4. Payment Processing β†’ Stripe processes β†’ Webhook confirms payment
  5. Confirmation Page β†’ Success with booking ID and details
  6. Appointments Page β†’ View and manage bookings

Chat Flow

  1. User clicks chat widget icon (bottom-right corner)
  2. Selects a quick question or types custom message
  3. Message sent to OpenAI via Next.js API route
  4. Response saved to Supabase for conversation history
  5. Context-aware responses using short-term history plus pgvector-backed semantic memories
  6. Embeddings stored in chat_memories for future recall

πŸ”’ Business Rules

  • Available hours: 9h-11h (morning) and 14h-16h (afternoon)
  • No appointments after 5 PM
  • Maximum 3 consultations per day
  • Real-time availability checking from Supabase
  • Past bookings cannot be cancelled

πŸ§ͺ Testing

Stripe Test Cards

  • Success: 4242 4242 4242 4242
  • Declined: 4000 0000 0000 9995
  • 3D Secure: 4000 0025 0000 3155

Use any future expiry date and any 3-digit CVC.

πŸ“š Documentation

πŸš€ Production Checklist

  • Switch Stripe keys from test to live
  • Configure production webhook in Stripe Dashboard
  • Verify Supabase RLS policies
  • Test payment flow end-to-end
  • Configure environment variables in hosting platform
  • Set up OpenAI API key with usage limits
  • Test chat widget functionality
  • Verify chat tables exist in Supabase
  • Apply latest migrations (supabase/migrations) to provision chat_memories (semantic memory)

πŸ“ Additional Notes

  • Chat widget works in offline mode if Supabase tables are not configured
  • Semantic recall gracefully falls back to conversation history if embeddings or vector table are unavailable
  • Dynamic time slots support 30/60/90 minute durations
  • Calendar is fully responsive with horizontal scroll on tablets
  • All UI components support trilingual display
  • Edge Functions: Supabase Edge Functions are prepared but currently using Next.js API routes for easier deployment
  • Web Scraping Utilities: src/lib/web-scraper.ts provides helpers for collecting and analysing external content
  • Semantic Memory: src/lib/ai/memory.ts manages embeddings, semantic search, and Supabase persistence

Built with Next.js 16, TypeScript, Supabase, Stripe, and OpenAI

About

Full-Stack SaaS Scheduler: Next.js 16 (App Router), TypeScript, Supabase (RLS/pgvector), Stripe Payments, and AI Chat Widget with Semantic Memory.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors