How sanjay-adtani/ai-chatbot works
Project type and purpose
• This is a full-stack web application (Next.js 15 App Router) that allows administrators to create and configure AI chatbots and lets end users interact with them in real time.
• It uses a GraphQL backend (StepZen + IBM API Connect) over NeonDB (PostgreSQL) and calls out to OpenAI for AI responses.
File structure
• app/ folder: Next.js App Router pages split into two segments—(admin) pages for bot management (create, edit, list) and (guests) pages for end-user chat interactions.
• app/api/: two serverless routes:
– /api/graphql/route.ts – proxies GraphQL requests to the StepZen endpoint.
– /api/send-message/route.ts – handles chat messages by calling OpenAI’s API and optionally persists them.
• components/ + components/ui/: React UI building blocks (ApolloProvider, Sidebar, Messages, Button, etc.).
• graphql/: client-side Apollo setup plus GraphQL queries & mutations.
• lib/: server-side helper modules (serverClient.ts to talk to GraphQL/DB, startNewChat.ts, utils.ts).
• stepzen/: StepZen configuration and GraphQL schema definitions over PostgreSQL.
• .env.example: environment variables for Clerk (auth), GraphQL endpoint/token, and OpenAI API key.
README for additional insights
• Tech stack highlights Next.js, TypeScript, Apollo Client, OpenAI API, IBM API Connect, NeonDB.
• Key features clarify that the app persists conversation history and uses a GraphQL-driven architecture with server actions.
Main components
a. Frontend (Next.js App)
— Admin UI (Create/Edit/List Chatbots)
— Guest UI (Chat interface)
— Apollo Client (GraphQL queries/mutations)
— React UI Components (Sidebar, Messages, etc.)
b. Next.js Server (API Layer)
— /api/graphql route (GraphQL proxy)
— /api/send-message route (OpenAI integration)
— Server Actions / lib utilities (e.g., startNewChat)
c. GraphQL Backend
— StepZen GraphQL Server (managed via IBM API Connect)
— GraphQL schema layers (stepzen/*.graphql)
d. Database
— NeonDB (PostgreSQL) for chatbots metadata & conversation history
e. External Services
— OpenAI API for generating responses
— Clerk (Auth)
Architectural patterns & design principles
• Full-stack React (Next.js App Router) with server and client components
• GraphQL façade (StepZen + IBM API Connect) decouples schema from database
• Apollo Client for client-side caching & state management
• Serverless API routes in Next.js as “glue” between UI and external services
• Clear separation of concerns: UI vs. business logic vs. data layer vs. external AI
Technologies & frameworks to annotate
• Next.js 15 (App Router, Server Actions)
• TypeScript
• Apollo Client (frontend)
• StepZen + IBM API Connect (GraphQL server)
• NeonDB (PostgreSQL)
• OpenAI API
• Clerk (auth)